<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-cascader v-model="queryForm.category_id" :options="allCategories" :show-all-levels="false" />

        </el-form-item>
        <el-form-item label="品牌:">
          <el-select v-model="queryForm.brand_id" class="m-2" placeholder="请选择" size="large">
              <el-option
                v-for="item in brandList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="供应商:">
          <el-select v-model="queryForm.supplier_id" class="m-2" placeholder="请选择" size="large">
              <el-option
                v-for="item in supplierList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="套餐商品:">
          <el-select v-model="queryForm.is_package" class="m-2" placeholder="请选择" size="large">
              <el-option
                v-for="item in packageList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </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 {searchAllCategories} from '@/api/product'
import {searchBrand} from '@/api/brand'
import {searchSupplier} from '@/api/supplier'

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:'',
             brand_id:'',
             supplier_id:'',
             is_package:'',
             status:''
          }
        }
    },
  },
  data(){
    return{
        statusOptions:[
          {
            value:'',
            label:"请选择状态"
          },
          {
            value:5,
            label:'使用中'
          },
          {
            value:6,
            label:"已停用"
          },
        ],
        packageList:[
          {
            value:"",
            label:"请选择"
          },
          {
            value:"是",
            label:"是"
          },
          {
            value:"否",
            label:"否"
          }
        ],
        supplierList:[],
        brandList:[],
        allCategories:[],
        dialogVisible:false,
    }
  },
  created() {
    this.initBrand();
    this.initSupplier();
    this.initCategories();
  },
  methods:{

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

    initCategories(){
      let _this=this;
      searchAllCategories().then(res=>{
        if(res.status!=200)return;
        console.log("searchAllCategories",res);
        _this.allCategories=res.data;
      })
    },
    initSupplier(){
      let _this=this;
      searchSupplier({page:1,pageSize:999,status:5}).then(res=>{
        if(res.status!=200)return;
        _this.supplierList=[{"id":0,"name":"请选择"},...res.data.dataList]
      })
    },
    initBrand(){
      let _this=this;
      searchBrand({page:1,pageSize:999,status:5}).then(res=>{
        if(res.status!=200)return;
        _this.brandList=[{id:0,name:"请选择"},...res.data.dataList];
      })
    },
    //搜索
    onSubmit(){
      this.$emit("bindSetQuery",this.$props.queryForm);
    }
  }
}
</script>

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