<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <el-col :span="6">
          <el-form-item label="物料编号" prop="code">
            <el-input
              v-model="queryParams.code"
              placeholder="请输入物料编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物料名称" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入物料名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="版本号" prop="version">
            <el-input
              v-model="queryParams.version"
              placeholder="请输入版本号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="启用标志" prop="status">
            <DictSelect v-model="queryParams.status" placeholder="请选择启用标志" dict-type="WMS_ENABLE_FLAG" />
          </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:material-additional:create']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :loading="exportLoading"
          @click="handleAdd"
        >新增</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="ipqcAwaitCommit" lazy>
        <IpqcNoCommit
          ref="ipqcAwaitCommit"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @approvalList="approvalNosubmitList"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="待审核" name="ipqcAwaitApproval" lazy>
        <IpqcToApproval
          ref="ipqcAwaitApproval"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @approvalList="approvalList"
          @noPassApproval="handleNoPass"
        />
      </el-tab-pane>
      <el-tab-pane label="已审核" name="ipqcAlreadyApproval" lazy>
        <!-- 已审批 -->
        <IpqcApprovaled
          ref="ipqcAlreadyApproval"
          :active-name="activeName"
          :query-paramspro="queryParams"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 新增检验 -->
    <UpdateInspection ref="updateInspection" @addComplete="handleNoPass" />

  </div>
</template>

<script>
import IpqcNoCommit from './components/IpqcInspectStandApproval/IpqcNoCommit.vue'
import IpqcToApproval from './components/IpqcInspectStandApproval/IpqcToApproval.vue'
import IpqcApprovaled from './components/IpqcInspectStandApproval/IpqcApprovaled.vue'
import UpdateInspection from './components/UpdateInspection.vue'

export default {
  name: 'IpqcInspectStandApproval',
  components: {
    IpqcNoCommit,
    IpqcToApproval,
    IpqcApprovaled,
    UpdateInspection
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: 'ipqcAwaitCommit',
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料附加信息列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        code: null,
        name: null,
        wmsMaterialItemMasterId: null,
        version: null,
        status: null,
        createTime: []
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [{ required: true, message: '物料编号不能为空', trigger: 'blur' }],
        wmsMaterialItemMasterId: [{ required: true, message: '检验项类别不能为空', trigger: 'blur' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        code: undefined,
        name: undefined,
        wmsMaterialItemMasterId: undefined,
        version: undefined,
        status: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    approvalList() {
      const alreadyApproval = this.$refs.alreadyApproval
      alreadyApproval && alreadyApproval.handleQuery()
    },
    approvalNosubmitList() {
      const ipqcAwaitApproval = this.$refs.ipqcAwaitApproval
      ipqcAwaitApproval && ipqcAwaitApproval.handleQuery()
    },
    handleNoPass() {
      const ipqcAwaitCommit = this.$refs.ipqcAwaitCommit
      ipqcAwaitCommit && ipqcAwaitCommit.handleQuery()
    },
    // 新增未提交的标准
    handleAdd() {
      this.$refs.updateInspection.btnText = 'add'
      this.$refs.updateInspection.commitDisable = true
      this.$refs.updateInspection.queryObj.version = '草稿'
      this.$refs.updateInspection.visible = true
    },
    materialChange(v) {
      const { materialNo } = v
      this.form.code = materialNo
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>
