<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="98px"
    >
      <QueryFormWrapper>
        <el-col :span="6">
          <el-form-item label="销售出库单" prop="saleOutNo">
            <el-input v-model="queryParams.saleOutNo" placeholder="请输入销售出库单" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="销售订单" prop="id">
            <el-input v-model="queryParams.id" placeholder="请输入销售订单" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户名称" prop="customerName">
            <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <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>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <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">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['wms:incoming-stock:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <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="awaitFqcInspect" lazy>
        <AwaitFqcInspect
          ref="awaitFqcInspect"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @fqcComplete="fqcComplete"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="待审核" name="awaiteFqcAppproval" lazy>
        <AwaiteFqcAppproval
          ref="awaiteFqcAppproval"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @resetComplete="resetComplete"
          @alreadyComplete="alreadyComplete"
          @fqcComplete="ApprovalFqcComplete"
        />
      </el-tab-pane>
      <el-tab-pane label="已检验" name="alreadyFqcInspect" lazy>
        <!-- 已检验 -->
        <AlreadyFqcInspect
          ref="alreadyFqcInspect"
          :active-name="activeName"
          :query-paramspro="queryParams"
        />
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import { exportIncomingStockExcel } from '@/api/wms/incoming/wareHousing'
import AwaitFqcInspect from './components/AwaitFqcInspect.vue'
import AlreadyFqcInspect from './components/AlreadyFqcInspect.vue'
import AwaiteFqcAppproval from './components/AwaiteFqcAppproval.vue'

export default {
  name: 'InspectionExecute',
  components: {
    AwaitFqcInspect,
    AlreadyFqcInspect,
    AwaiteFqcAppproval
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // WMS 入库业务-来料入库列表
      list: [],
      // 显示哪一个表格
      activeName: 'awaitFqcInspect',
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        wmsIncomingReceiptId: null,
        orderType: null,
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        funitId: null,
        remark: null,
        areaTest: null,
        materialLots: null,
        purchaseOrderNo: null,
        createTime: []
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wmsIncomingReceiptId: [{ required: true, message: '来料登记记录ID不能为空', trigger: 'blur' }],
        orderType: [{ required: true, message: '单据类型不能为空', trigger: 'change' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsIncomingReceiptId: undefined,
        orderType: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        funitId: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.$refs[this.activeName].handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      this.$modal.confirm('是否确认导出所有FQC检验执行数据项?').then(() => {
        this.exportLoading = true
        return exportIncomingStockExcel(params)
      }).then(response => {
        this.$download.excel(response, 'FQC检验执行.xls')
        this.exportLoading = false
      }).catch(() => {})
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    resetComplete() {
      const awaitFqcInspects = this.$refs.awaitFqcInspect
      awaitFqcInspects && awaitFqcInspects.handleQuery()
    },
    fqcComplete() {
      const alreadyFqcInspects = this.$refs.alreadyFqcInspect
      alreadyFqcInspects && alreadyFqcInspects.handleQuery()
    },
    ApprovalFqcComplete() {
      const alreadyFqcInspects = this.$refs.alreadyFqcInspects
      alreadyFqcInspects && alreadyFqcInspects.handleQuery()
    },
    alreadyComplete() {},
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>

