<!-- 搜索表单 -->
<template>
  <el-form label-width="90px" class="ele-form-search" @keyup.enter.native="search" @submit.native.prevent>
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="所属工厂" prop="factoryId">
          <el-select filterable placeholder="请选择" v-model="where.factoryId" clearable class="w100">
            <el-option v-for="item in factoryList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-if="activeName != '出入库明细表'" v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="编码:">
          <el-input clearable v-model="where.code" placeholder="请输入" />
        </el-form-item>
      </el-col>

      <el-col v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="物品编码:">
          <el-input clearable v-model="where.categoryCode" placeholder="请输入" />
        </el-form-item>
      </el-col>

      <el-col v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="物品名称:">
          <el-input clearable v-model="where.categoryName" placeholder="请输入" />
        </el-form-item>
      </el-col>

      <!-- <el-col v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="组织机构:">
          <auth-selection
            v-model="where.deptIds"
            style="width: 100%"
          ></auth-selection>
        </el-form-item>
      </el-col> -->
      <el-col v-if="activeName == '出入库明细表'" v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="单号:">
          <el-input v-model="where.bizNo" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-col>
      <el-col v-if="activeName == '出入库明细表'" v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="类型:">
          <el-select style="width: 100%" v-model="where.type" placeholder="请选择">
            <el-option v-for="item in typeOption" :label="item.label" :value="item.value" :key="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-if="activeName == '出入库明细表'" v-bind="styleResponsive ? { lg: 6, md: 10 } : { span: 6 }">
        <el-form-item label="出入库时间:">
          <el-date-picker style="width: 100%" size="small" v-model="where.time" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
      </el-col>
      <el-col style="display: flex; justify-content: flex-end" v-bind="styleResponsive
        ? { lg: activeName == '出入库明细表' ? 24 : 18, md: 24 }
        : { span: activeName == '出入库明细表' ? 24 : 18 }
        ">
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" class="ele-btn-icon" @click="search">
            查询
          </el-button>
          <el-button @click="reset" icon="el-icon-refresh-left" type="primary">重置</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import AuthSelection from '@/components/AuthSelection/index';
import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
export default {
  components: { AuthSelection },
  props: {
    activeName: { type: String, default: '' }
  },
  data() {
    // 默认表单数据
    const defaultWhere = {
      workOrderCode: '',
      warehouseName: '',
      categoryName: '',
      factoryId: ''
    };
    return {
      // 表单数据
      where: { ...defaultWhere },
      factoryList: [],
      typeOption: [
        { label: '入库', value: 1 },
        { label: '出库', value: 2 }
      ],
      defaultWhere: { ...defaultWhere }
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive() {
      return this.$store.state.theme.styleResponsive;
    }
  },
  watch: {
    activeName(val) {
      console.log('val-------', val);
      this.where = { ...this.defaultWhere };
    }
  },
  created() {
    this.getFactoryList();
  },
  methods: {
    //获取工厂列表
    async getFactoryList() {
      const res = await warehouseDefinition.getFactoryarea({
        pageNum: 1,
        size: 9999,
        type: 1
      });
      this.factoryList = res.list;
    },
    /* 搜索 */
    search() {
      this.$emit('search', this.where);
    },
    /*  重置 */
    reset() {
      this.where = { ...this.defaultWhere };
      this.search();
    }
  }
};
</script>
<style lang="scss" scoped>
.ele-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
