<template>
  <div class="data-search">
    <el-form :inline="true" :model="queryForm" class="demo-form-inline">


        <el-form-item label="文档标题:">
          <el-input v-model="queryForm.title" placeholder="请填写文档标题"></el-input>
        </el-form-item>

        <el-form-item label="所属分类:">
          <el-select v-model="queryForm.category_id" clearable class="m-2" placeholder="请选择分类" size="large">
              <el-option
                v-for="item in categoryList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="文档状态:">
          <el-select v-model="queryForm.status" class="m-2" placeholder="请选择文档状态" size="large">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">  <svg-icon icon-class="search"/> 搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addDocument" class="el-icon-circle-plus-outline"> 创建模版</el-button>
        </el-form-item>
      </el-form>


  </div>
</template>

<script>
import {searchDocumentCategory} from "@/api/document";
export default{
  props:{
    queryForm:{
        type:Object,
        default:()=>{
          return {
             page:1,
             pageSize:10,
             title:'',
             category_id:'',
             status:'',
          }
        }
    },
  },
  data(){
    return{
        statusOptions:[
          {
            value:'',
            label:"请选择状态"
          },
          {
            value:5,
            label:'启用'
          },
          {
            value:6,
            label:"停用"
          },
        ],
        dialogVisible:false,
        categoryList:[],
    }
  },
  created() {
    this.initCategoryList();
  },
  methods:{


    initCategoryList(){
      let _this=this;
      searchDocumentCategory({page:1,pageSize:999,status:5}).then(res=>{
        if(res.status!=200)return;
        _this.categoryList=res.data.dataList;
      })
    },
    onCreate(e){
      this.dialogVisible=true;
    },
    //搜索
    onSubmit(){
      this.$emit("bindSetQuery",this.$props.queryForm);
    },
    /* 创建模版 */
    addDocument(){
      let _this = this;
      let a = document.createElement("a");
      a.href = "#/document/create"; // 使用 hash
      a.target = "_blank";
      a.click();
      //this.$router.push('/document/create');
    }
  }
}
</script>

<style lang="scss">
@import "./dataSearch.scss"
</style>
