<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="85px"
    >
      <QueryFormWrapper>
        <el-col :span="8">
          <el-form-item label="物料批次" prop="materialLots">
            <el-input
              v-model="queryParams.materialLots"
              clearable
              placeholder="请输入物料批次"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="采购订单" prop="purchaseOrderNo">
            <el-input
              v-model="queryParams.purchaseOrderNo"
              clearable
              placeholder="请输入采购订单"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="物料编码" prop="materialNo">
            <el-input
              v-model="queryParams.materialNo"
              placeholder="请输入物料编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="供应商名称" prop="supplierName">
            <el-input
              v-model="queryParams.supplierName"
              placeholder="请输入供应商名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col v-show="activeName === 'alreadyIqcInspection'" :span="8"> -->
        <el-col :span="8">
          <el-form-item label="检验人" prop="inspector">
            <el-input
              v-model="queryParams.inspector"
              placeholder="请输入检验人"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col v-show="activeName === 'alreadyIqcInspection'" :span="8"> -->
        <el-col :span="8">
          <el-form-item label="检验时间" prop="createTime">
            <el-date-picker
              v-model="queryParams.createTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col v-show="activeName === 'alreadyIqcInspection'" :span="8"> -->
        <el-col :span="8">
          <el-form-item label="审核人" prop="auditor">
            <el-input
              v-model="queryParams.auditor"
              placeholder="请输入审核人"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col v-show="activeName === 'alreadyIqcInspection'" :span="8"> -->
        <el-col :span="8">
          <el-form-item label="审核时间" prop="auditTime">
            <el-date-picker
              v-model="queryParams.auditTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <EasyAdvancedQuery
              class="mr10"
              label-width="98px"
              @advQuery="advQuery"
            >
              <template #default="{ model }">
                <el-row :gutter="10" type="flex">
                  <el-col :span="12">
                    <el-form-item label="物料名称" prop="materialName">
                      <el-input
                        v-model="model.materialName"
                        placeholder="请输入物料名称"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="入库数量" prop="inQty">
                      <el-input
                        v-model="model.inQty"
                        placeholder="请输入入库数量"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="库存单位" prop="funitId">
                      <el-input
                        v-model="model.funitId"
                        placeholder="请输入库存单位"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="创建日期" prop="createTime">
                      <el-date-picker
                        v-model="model.createTime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="判定结果" prop="noPassType">
                      <DictSelect
                        v-model="model.noPassType"
                        clearable
                        placeholder="请选择判定结果"
                        dict-type="WMS_NO_PASS_TYPE"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
              </template>
            </EasyAdvancedQuery>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </div>
      </QueryFormWrapper>
    </el-form>
    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columnsList"
        @queryTable="handleQuery"
        @saveSetting="getColumnsList"
      />
    </el-row>
    <!-- 列表 -->
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="待检验" name="awaitIqcInspection" lazy>
        <AwaitIqcInspection
          ref="awaitIqcInspection"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @inspectComplete="inspectComplete"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="待审核" name="awaitApproval" lazy>
        <inspectionResultApproval
          ref="awaitApproval"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @resetComplete="resetComplete"
          @alreadyComplete="alreadyComplete"
        />
      </el-tab-pane>
      <el-tab-pane label="已检验" name="alreadyIqcInspection" lazy>
        <!-- 已发 -->
        <AlreadyIqcInspection
          ref="alreadyIqcInspection"
          :active-name="activeName"
          :query-paramspro="queryParams"
        />
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->
  </div>
</template>

<script>
import AwaitIqcInspection from "./components/AwaitIqcInspection.vue";
import AlreadyIqcInspection from "./components/AlreadyIqcInspection.vue";
import inspectionResultApproval from "./components/inspectionResultApproval.vue";
export default {
  name: "InspectionExecute",
  components: {
    AwaitIqcInspection,
    AlreadyIqcInspection,
    inspectionResultApproval,
  },
  provide() {
    return {
      paramsQuery: this.queryParams,
    };
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 显示哪一个表格
      activeName: "awaitIqcInspection",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        funitId: null,
        areaTest: null,
        materialLots: null,
        purchaseOrderNo: null,
        createTime: [],
        materialNo: null,
        materialName: null,
        inspector: null,
        auditor: null,
        auditTime: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 显隐列
      columnsList: [],
    };
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        funitId: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.advParams = {};
      this.$refs[this.activeName].advParams = {};
      this.$refs[this.activeName].handleQuery();
    },
    handleClick(tab, event) {
      this.activeName = tab.name;
      if (this.$refs[this.activeName]) {
        this.$refs[this.activeName].advParams = this.advParams;
        this.$refs[this.activeName].handleQuery();
      }
    },
    inspectComplete() {
      const awaitApproval = this.$refs.awaitApproval;
      awaitApproval && awaitApproval.handleQuery();
    },
    resetComplete() {
      const awaitInspect = this.$refs.awaitIqcInspection;
      awaitInspect && awaitInspect.handleQuery();
    },
    alreadyComplete() {
      const alreadyIqcInspect = this.$refs.alreadyIqcInspection;
      alreadyIqcInspect && alreadyIqcInspect.handleQuery();
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams;
      this.$refs[this.activeName].advParams = this.advParams;
      this.handleQuery();
    },
    getColumns(data) {
      this.columnsList = data;
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList();
      });
    },
  },
};
</script>
