<!-- 搜索表单 -->
<template>
  <el-form
    label-width="80px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <!-- <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { 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: 12 } : { span: 6 }">
        <el-form-item label="申请人:">
          <el-input clearable v-model="where.name" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调拨类型:" label-width="100px">
          <el-input clearable v-model="where.dep" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="状态:">
          <el-input clearable v-model="where.texture" placeholder="请输入" />
        </el-form-item>
		<div class="ele-form-actions">
			<el-button
				type="primary"
				icon="el-icon-search"
				class="ele-btn-icon"
				@click="search"
				size="small"
			>
				查询
			</el-button>
			 <el-button @click="reset"
				 icon="el-icon-refresh-left"
				 size="small"
				 type="primary"
			 >重置</el-button>
		</div>
      </el-col>
    </el-row> -->
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="所属工厂" prop="factoryId">
          <el-select
            filterable
            placeholder="请选择"
            @change="getWarehouseListHandle"
            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-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调出仓库" prop="sourceWarehouse">
          <el-select
            filterable
            placeholder="请选择"
            v-model="where.sourceWarehouse"
            clearable
            class="w100"
          >
            <el-option
              v-for="item in warehouseList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调入仓库" prop="targetWarehouse">
          <el-select
            filterable
            placeholder="请选择"
            v-model="where.targetWarehouse"
            clearable
            class="w100"
          >
            <el-option
              v-for="item in warehouseList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调拨单号:">
          <el-input
            clearable
            v-model="where.allotCode"
            placeholder="请输入物品名称"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调拨名称:">
          <el-input
            clearable
            v-model="where.name"
            placeholder="请输入物品名称"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { 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: 12 } : { 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: 12 } : { span: 6 }">
        <el-form-item label="组织机构:" prop="deptIds">
          <auth-selection
            data-type="Array"
            v-model="where.deptIds"
            style="width: 100%"
          ></auth-selection>
        </el-form-item>
      </el-col> -->
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调拨类型" prop="type">
          <el-select
            filterable
            placeholder="请选择"
            v-model="where.type"
            clearable
            class="w100"
          >
            <el-option
              v-for="item in allocationType"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="调拨状态" prop="status">
          <el-select
            filterable
            placeholder="请选择"
            v-model="where.status"
            clearable
            class="w100"
          >
            <el-option
              v-for="item in stutusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 18, md: 12 } : { span: 18 }">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
            size="small"
          >
            查询
          </el-button>
          <el-button
            @click="reset"
            icon="el-icon-refresh-left"
            size="small"
            type="primary"
            >重置</el-button
          >
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  import { login } from '@/api/login';
  import { getWarehouseList } from '@/api/classifyManage/itemInformation';
  import storageApi from '@/api/warehouseManagement/index.js';
  import { allocationType } from '@/utils/dict/warehouse';
  import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
  export default {
    data() {
      // 默认表单数据
      const defaultWhere = {
        name: '',
        allotCode: '',
        type: '',
        status: '',
        factoryId: '',
        categoryName: '',
        categoryCode: '',
        targetWarehouse: '',
        sourceWarehouse: ''
      };
      return {
        // 表单数据
        where: { ...defaultWhere },
        treeLoading: false,
        allocationType,
        treeData: [],
        factoryList: [],
        warehouseList: [],
        allWarehouseList: [],
        stutusOptions: [
          {
            value: 0,
            label: '未提交'
          },
          {
            value: 1,
            label: '审核中'
          },
          {
            value: 2,
            label: '已完成'
          }
        ]
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    created() {
      this.getArguInfo();
      this.getFactoryList();
    },
    methods: {
      async getTreeData(val) {
        this.where.targetWarehouse = '';
        this.where.sourceWarehouse = '';
        try {
          this.treeLoading = true;
          let res = await storageApi.getWarehouseTrees({
            factoriesId: val
          });
          this.treeLoading = false;
          if (res?.code === '0') {
            this.warehouseList = res.data;
          }
        } catch (error) {
          console.log(error);
        }
        this.treeLoading = false;
      },

      async getArguInfo() {
        const { data } = await getWarehouseList();
        this.allWarehouseList = data;
      },
      //获取工厂列表
      async getFactoryList() {
        const res = await warehouseDefinition.getFactoryarea({
          pageNum: 1,
          size: 9999,
          type: 1
        });
        this.factoryList = res.list;
      },

      getWarehouseListHandle(val) {
        this.where.targetWarehouse = '';
        this.where.sourceWarehouse = '';
        this.warehouseList = this.allWarehouseList.filter(
          (item) => item.factoryId === val
        );
      },
      /* 搜索 */
      search() {
        console.log(this.where);
        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;
  }
  .el-form-item {
    margin-bottom: 5px !important;
  }
</style>
