<!-- 不合格品审理单 -->
<template>
  <div>
    <template v-if="!updateVisible && !disposeVisible && !verifyVisible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
        <el-form-item label="物料名称">
          <el-input
            v-model="dataForm.productName"
            placeholder="请输入物料名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="生产批次号">
          <el-input
            v-model="dataForm.batchNumber"
            placeholder="请输入批次号"
            clearable
          />
        </el-form-item>
        <el-form-item label="任务单编码">
          <el-input
            v-model="dataForm.orderCode"
            placeholder="请输入任务单编码"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="search()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="invoicesCode"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="审理编码"
        >
        </el-table-column>
        <el-table-column
          prop="orderCode"
          header-align="center"
          align="center"
          width="140"
          :show-tooltip-when-overflow="true"
          label="任务单编码"
        >
        </el-table-column>
         <el-table-column
          prop="batchNumber"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="批次号"
        >
        </el-table-column>
        <el-table-column
          prop="productName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="物料名称"
        >
        </el-table-column>
        <el-table-column
          prop="productNumber"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="生产编号"
        >
        </el-table-column>
        <el-table-column
          prop="techName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="工艺名称"
        >
        </el-table-column>
        <el-table-column
          prop="nodeName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="检验工序节点"
        >
        </el-table-column>
        <el-table-column
          prop="disqualificationNodeName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="发生工序节点"
        >
        </el-table-column>
        <el-table-column
          prop="cnt"
          header-align="center"
          align="center"
          :show-tooltip-when-overflow="true"
          label="交检数量"
        >
        </el-table-column>
        <el-table-column
          prop="disqualificationCnt"
          header-align="center"
          align="center"
          width="100"
          :show-tooltip-when-overflow="true"
          label="不合格数量"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          prop="measureStateStr"
          header-align="center"
          align="center"
          :show-tooltip-when-overflow="true"
          label="处理状态"
        >
        </el-table-column>
        <el-table-column
          prop="approver"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="当前审理人"
        >
        </el-table-column>
        <el-table-column
          prop="responsibleName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="责任人"
        >
        </el-table-column>
        <el-table-column
          prop="disposeAnalyse"
          header-align="center"
          align="center"
          width="100"
          :show-tooltip-when-overflow="true"
          label="处理分析"
        >
        </el-table-column>
        <el-table-column
          prop="analyseName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="处理分析人"
        >
        </el-table-column>
        <el-table-column
          prop="disposeMeasure"
          header-align="center"
          align="center"
          width="140"
          :show-tooltip-when-overflow="true"
          label="处置措施"
        >
        </el-table-column>
        <el-table-column
          prop="measureName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="处置措施人"
        >
        </el-table-column>
        <el-table-column
          prop="verifyConclusion"
          header-align="center"
          align="center"
          width="140"
          :show-tooltip-when-overflow="true"
          label="验证结论"
        >
        </el-table-column>
        <el-table-column
          prop="verifyName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="验证人"
        >
        </el-table-column>
        <el-table-column
          prop="creatorName"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="检验员"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          header-align="center"
          align="center"
          width="160"
          label="检验时间"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          prop="approveStateStr"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="审理评审状态"
        >
        </el-table-column>
        <el-table-column
          prop="reworkCnt"
          header-align="center"
          align="center"
          width="100"
          :show-tooltip-when-overflow="true"
          label="返工数量"
        >
        </el-table-column>
        <el-table-column
          prop="repairCnt"
          header-align="center"
          align="center"
          width="100"
          :show-tooltip-when-overflow="true"
          label="返修数量"
        >
        </el-table-column>
        <el-table-column
          prop="damageCnt"
          header-align="center"
          align="center"
          width="140"
          :show-tooltip-when-overflow="true"
          label="不合格/报损数量"
        >
        </el-table-column>
        <el-table-column
          prop="concessionCnt"
          header-align="center"
          align="center"
          width="120"
          :show-tooltip-when-overflow="true"
          label="让步接收数量"
        >
        </el-table-column>
        <el-table-column
          prop="releaseList"
          header-align="center"
          align="center"
          width="100"
          :show-tooltip-when-overflow="true"
          label="顾客放行表"
        >
        <template slot-scope="scope">
            <el-button
              :disabled="
                !scope.row.releaseList || scope.row.releaseList.length === 0
              "
              type="text"
              size="small"
              @click="attachDetails(scope.row.releaseList)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="attachList"
          header-align="center"
          align="center"
          :show-tooltip-when-overflow="true"
          label="附件"
        >
        <template slot-scope="scope">
            <el-button
              :disabled="
                !scope.row.attachList || scope.row.attachList.length === 0
              "
              type="text"
              size="small"
              @click="attachDetails(scope.row.attachList)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button
              v-if="isAuth('disqualification:invoices:update')"
              type="text"
              size="small"
              @click="updateHandle(scope.row)"
              >编辑</el-button
            >
            <el-button
              v-if="isAuth('disqualification:invoices:updateDispose')"
              type="text"
              size="small"
              @click="disposeHandle(scope.row)"
              >处理</el-button
            >
            <el-button
              v-if="isAuth('disqualification:invoices:updateVerify')"
              type="text"
              size="small"
              @click="verifyHandle(scope.row)"
              >验证</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </template>
    <quality-disqualification-update ref="update" v-if="updateVisible" @onChose="onChose" />
    <quality-disqualification-dispose ref="dispose" v-if="disposeVisible" @onChose="onChose" />
    <quality-disqualification-verify ref="verify" v-if="verifyVisible" @onChose="onChose" />
  </div>
</template>

<script>
import {getDisList} from '@/api/quality'
import QualityDisqualificationUpdate from './disqualification-update'
import QualityDisqualificationDispose from './disqualification-dispose'
import QualityDisqualificationVerify from './disqualification-verify'
import {approveStateOption, measureStateOption} from '@/utils/enums'
export default {
  name: 'quality-disqualification',
  components: {QualityDisqualificationUpdate, QualityDisqualificationDispose, QualityDisqualificationVerify},
  data () {
    return {
      updateVisible: false,
      disposeVisible: false,
      verifyVisible: false,
      approveStateOption: approveStateOption,
      measureStateOption: measureStateOption,
      dataForm: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  mounted () {},
  created () {
    this.search()
  },
  methods: {
    onChose () {
      this.updateVisible = false
      this.disposeVisible = false
      this.verifyVisible = false
    },
    search () {
      this.pageIndex = 1
      this.getDataList()
    },
         // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    getDataList () {
      this.dataListLoading = true
      let param = {
        current: this.pageIndex,
        size: this.pageSize,
        batchNumber: this.dataForm.batchNumber,
        productName: this.dataForm.productName
      }
      getDisList(param).then(({ data }) => {
        if (data && data.code === '200') {
          this.dataList = data.data.records
          this.totalPage = Number(data.data.total)
          this.dataList.forEach(item => {
            let option = this.approveStateOption.find(t => t.value === item.approveState)
            if (option != null) {
              item.approveStateStr = option.label
            }
            let measure = this.measureStateOption.find(t => t.value === item.state)
            if (measure != null) {
              item.measureStateStr = measure.label
            }
          })
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    updateHandle (item) {
      this.updateVisible = true
      this.$nextTick(() => {
        this.$refs.update.init(item)
      })
    },
    disposeHandle (item) {
      this.disposeVisible = true
      this.$nextTick(() => {
        this.$refs.dispose.init(item)
      })
    },
    verifyHandle (item) {
      this.verifyVisible = true
      this.$nextTick(() => {
        this.$refs.verify.init(item.invoicesId)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
