<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <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="materialName">
            <el-input v-model="queryParams.materialName" placeholder="请输入产品名称" @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="查看方式" prop="queryType">
            <DictSelect v-model="queryParams.queryType" placeholder="请选择查看方式" dict-type="WMS_IPQC_QUERY_TYPE" />
          </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="ipqcDate">
                      <el-date-picker
                        v-model="model.ipqcDate"
                        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="inspectTime">
                      <el-date-picker
                        v-model="model.inspectTime"
                        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="auditTime">
                      <el-date-picker
                        v-model="model.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>
                </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="awaitIpqcInspection">
        <AwaitIpqcInspection
          ref="awaitIpqcInspection"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @submitComplete="inspectComplete"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="待审核" name="ipqcinspectionResultApproval">
        <IpqcinspectionResultApproval
          ref="ipqcinspectionResultApproval"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @resetComplete="resetComplete"
          @alreadyComplete="alreadyComplete"
        />
      </el-tab-pane>
      <el-tab-pane label="已检验" name="alreadyIqcInspection">
        <!-- 已发 -->
        <AlreadyIpqcInspection
          ref="alreadyIqcInspection"
          :active-name="activeName"
          :query-paramspro="queryParams"
        />
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->

  </div>
</template>

<script>
import AlreadyIpqcInspection from './components/AlreadyIpqcInspection.vue'
import AwaitIpqcInspection from './components/AwaitIpqcInspection.vue'
// import IpqcInspectApproval from './IpqcInspectApproval.vue'
import IpqcinspectionResultApproval from './components/IpqcinspectionResultApproval.vue'

export default {
  name: 'IPQCInspectionExecute',
  components: {
    AlreadyIpqcInspection,
    AwaitIpqcInspection,
    IpqcinspectionResultApproval
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 显示哪一个表格
      activeName: 'awaitIpqcInspection',
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        funitId: null,
        areaTest: null,
        materialLots: null,
        purchaseOrderNo: null,
        createTime: [],
        queryType: 'merge',
        materialName: null,
        materialNo: null
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 显隐列
      columnsList: []
    }
  },
  created() {
    // this.queryParams.queryType = 'merge'
  },
  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.queryParams.materialName = undefined
      this.queryParams.materialNo = undefined
      if (this.activeName === 'ipqcinspectionResultApproval') {
        this.queryParams.queryType = 'single'
      } else {
        this.queryParams.queryType = 'merge'
      }
      this.advParams = {}
      this.$refs[this.activeName].advParams = {}
      this.$refs[this.activeName].handleQuery()
    },
    // tab点击切换
    handleClick(tab, event) {
      this.activeName = tab.name
      if (this.activeName === 'ipqcinspectionResultApproval') {
        this.queryParams.queryType = this.queryParams.queryType === 'merge' ? 'single' : this.queryParams.queryType
        this.$nextTick(() => {
          this.$refs[this.activeName].handleQuery()
        })
      } else {
        this.$nextTick(() => {
          this.$refs[this.activeName].handleQuery()
        })
        // this.queryOptions[1].disabled = false
        // this.queryParams.queryType = 'merge'
      }
    },
    // 送审完成，待审核刷新
    inspectComplete() {
      const ipqcinspectionResultApproval = this.$refs.ipqcinspectionResultApproval
      ipqcinspectionResultApproval && ipqcinspectionResultApproval.handleQuery()
    },
    // 重新检验完，待检验刷新
    resetComplete() {
      const awaitIpqcInspection = this.$refs.awaitIpqcInspection
      awaitIpqcInspection && awaitIpqcInspection.handleQuery()
    },
    // 批核完成，已检验刷新
    alreadyComplete() {
      const alreadyIqcInspection = this.$refs.alreadyIqcInspection
      alreadyIqcInspection && alreadyIqcInspection.handleQuery()
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams
      this.$refs[this.activeName].advParams = this.advParams
      this.handleQuery()
    }
  }
}
</script>

