<template>
  <div class="data-search">
    <el-form :inline="true" :model="queryForm" class="demo-form-inline">
        <el-form-item label="项目名称:">
          <el-input v-model="queryForm.name" placeholder="请填写项目名称"></el-input>
        </el-form-item>
        <el-form-item label="所属分类:">
          <el-select v-model="queryForm.categoryId" 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-button type="success" @click="onCreate" >  <svg-icon icon-class="edit"/> 新项目</el-button>
        </el-form-item>
      </el-form>



    <el-dialog  :visible.sync="dialogVisible" append-to-body v-el-drag-dialog  width="80%" custom-class="prod-verify" title="创建新项目">
         <dataInfo  @onClose="onClose"></dataInfo>
     </el-dialog>

  </div>
</template>

<script>
import dataInfo from './dataInfo.vue';
import {searchCategory} from "@/api/project"
import elDragDialog from '@/directive/el-drag-dialog'
export default{
  components:{
    dataInfo,
  },
  directives: { elDragDialog },
  props:{
    queryForm:{
        type:Object,
        default:()=>{
          return {
            page:1,
            pageSize:10,
            name:'',
            category_id:'',
            status:'',
            isUpdate:false,
          }
        }
    },
  },
  data(){
    return{
        statusOptions:[
          { value:5,label:"启用"},
          { value:6,label:"停用"},
        ],
        dialogVisible:false,
        categoryList:[]
    }
  },
  created() {
      this.initCategory();
  },
  methods:{
    initCategory(){
      let _this=this;
      let par={
        page:1,
        pageSize:999,
        status:5
      }
      searchCategory(par).then(res=>{
         _this.categoryList=res.data.dataList
      })

    },

    onCreate(e){
      this.dialogVisible=true;
    },

    onClose(e){
      this.dialogVisible=false;
      this.queryForm.isUpdate=!this.queryForm.isUpdate
    },
    //搜索
    onSubmit(){
       this.queryForm.isUpdate=!this.queryForm.isUpdate
      this.$emit("bindSetQuery",this.$props.queryForm);
    }
  }
}
</script>

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