<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    :title="title + (type == 'detail' ? '详情' : '报工')"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    width="80%"
    resizable
    :maxable="true"
  >
    <ele-pro-table
      :needPage="false"
      :columns="workColumns"
      :datasource="[form]"
    >
      <template v-slot:toolbar>
        样品总数：{{ form.workSampleCount }}{{ form.measureUnit }}
      </template>
      <template v-slot:craftFiles="{ row }">
        <el-link type="primary" :underline="false" @click="craftFiles(row)"
          >工艺文件</el-link
        >
      </template>

      <template v-slot:isRequired="{ column }">
        <span class="is-required">{{ column.label }}</span>
      </template>
      <template v-slot:qualityType="{ row }">
        {{ getDictValue('质检计划类型', row.qualityType) }}
      </template>
      <template v-slot:qualityMode="{ row }">
        {{ getDictValue('取样类型', row.qualityMode) }}
      </template>
      <template v-slot:hours="{ row }">
        <el-input
          v-model="row.hours"
          placeholder="请输入"
          type="number"
          :disabled="type == 'detail'"
        >
        </el-input>
      </template>
      <template v-slot:accessory="{ row }">
        <fileMain v-model="row.accessory" type="view"></fileMain>
      </template>
      <template v-slot:sampleQuantity="{ row }">
        <el-input
          v-model="row.sampleQuantity"
          placeholder="请输入"
          type="number"
          @input="formSampleQuantityChange"
          :disabled="type == 'detail'"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:sampleNoQualifiedNumber="{ row }">
        <el-input
          v-model="row.sampleNoQualifiedNumber"
          @input="formSampleNoQualifiedNumberChange"
          placeholder="请输入"
          type="number"
          :disabled="type == 'detail'"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
    </ele-pro-table>
    <ele-pro-table
      :needPage="false"
      :columns="tableColumns"
      :datasource="tableData"
    >
      <template v-slot:toolbar>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <span>
            当前检测剩余样品数：{{ form.sampleQuantity
            }}{{ form.measureUnit }}</span
          >
          <el-button
            type="primary"
            v-if="type != 'detail'"
            @click="handleOneKeyQualified"
            style="margin-right: 10px"
          >
            一键合格
          </el-button>
        </div>
      </template>
      <template v-slot:qualityStandardType="{ row }">
        {{ getDictValue('质检标准类型', row.qualityStandardType) }}
      </template>
      <template v-slot:executionMethod="{ row }">
        <el-select
          v-model="row.executionMethod"
          style="width: 100%"
          :disabled="type == 'detail' || !!row.experimentCode"
        >
          <el-option :value="1" label="常规检验"></el-option>
          <el-option :value="2" label="实验"></el-option>
        </el-select>
      </template>
      <template v-slot:useTools="{ row }">
        <toolButtom v-model="row.useTools" :type="type" :sList="row.toolList" />
      </template>
      <template v-slot:qualityResultContent="{ row }">
        <el-input
          v-model="row.qualityResultContent"
          placeholder="请输入内容"
          :disabled="type == 'detail'"
          @input="handleInput(row, row.qualityResultContent)"
        >
          <template slot="append" v-if="row.unitName">
            {{ row.unitName }}
          </template>
        </el-input>
      </template>
      <template v-slot:sampleQuantity="{ row, $index }">
        <el-input
          v-model="row.sampleQuantity"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('sampleQuantity', row, $index)"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>

      <template v-slot:qualifiedQuantity="{ row, $index }">
        <el-input
          v-model="row.qualifiedQuantity"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('qualifiedQuantity', row, $index)"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:noQualifiedQuantity="{ row, $index }">
        <el-input
          v-model="row.noQualifiedQuantity"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('noQualifiedQuantity', row, $index)"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:lossNumber="{ row, $index }">
        <el-input
          v-model="row.lossNumber"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('lossNumber', row, $index)"
          @click.native="curretNum = row.lossNumber"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:lossNumberUnqualified="{ row, $index }">
        <el-input
          v-model="row.lossNumberUnqualified"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('lossNumberUnqualified', row, $index)"
          @click.native="curretNum = row.lossNumberUnqualified"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:retainedSampleQuantity="{ row, $index }">
        <el-input
          v-model="row.retainedSampleQuantity"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('retainedSampleQuantity', row, $index)"
          @click.native="curretNum = row.retainedSampleQuantity"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:retainedSampleUnqualified="{ row, $index }">
        <el-input
          v-model="row.retainedSampleUnqualified"
          placeholder="请输入"
          :disabled="type == 'detail'"
          type="number"
          @input="inputValue('retainedSampleUnqualified', row, $index)"
          @click.native="curretNum = row.retainedSampleUnqualified"
        >
          <template slot="append">{{ form.measureUnit }}</template>
        </el-input>
      </template>
      <template v-slot:qualityResults="{ row, $index }">
        <el-select
          v-model="row.qualityResults"
          placeholder="请选择"
          style="width: 100%"
          :disabled="type == 'detail'"
        >
          <el-option
            v-for="item in qualityResultsList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </template>
      <template v-slot:inspectImage="{ row, $index }">
        <fileMain
          v-model="row.inspectImage"
          :type="type == 'detail' ? 'view' : 'add'"
        ></fileMain>
      </template>
      <template v-slot:imgUrl="{ row, $index }">
        <fileMain v-model="row.imgUrl" type="view"></fileMain>
      </template>
      <template v-slot:defaultValue="{ row }">
        <div style="display: flex; justify-content: center">
          <span>{{ row.symbol }}</span>
          <span v-if="row.textType == 3">
            {{ row.minValue }}-{{ row.maxValue }}
          </span>

          <span v-else>
            <span>{{ row.defaultValue }}</span>
          </span>

          {{ row.unitName }}
        </div>
      </template>

      <template v-slot:isRequired="{ column }">
        <span class="is-required">{{ column.label }}</span>
      </template>
      <template v-slot:action="{ row }">
        <el-link
          type="primary"
          :underline="false"
          @click="experimentReport(row, 'report')"
          v-if="row.executionMethod == 2"
        >
          实验
        </el-link>
      </template>
    </ele-pro-table>
    <template v-slot:footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleConfirm" v-if="type != 'detail'">
        确认
      </el-button>
    </template>
    <experimentReport
      ref="experimentReport"
      @done="experimentReportDone"
      :pageName="pageName"
    ></experimentReport>
    <wokePopup ref="wokePopupRef"></wokePopup>
  </ele-modal>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import detailMixins from '../mixins/detailMixins';
  import toolButtom from './toolButtom.vue';
  import experimentReport from './experimentReport.vue';
  import { handleInput } from './unit.js';
  import {
    exeTaskReportWork,
    exeEntrustReportWork
  } from '@/api/inspectionProjectTask';
  import wokePopup from '@/components/workList/wokePopup.vue';
  import { parameterGetByCode } from '@/api/main/index';
  import { craftFiles } from '@/api/inspectionWork';

  export default {
    mixins: [dictMixins, detailMixins],

    components: { toolButtom, experimentReport, wokePopup },

    data() {
      return {
        handleInput,
        type: 'report',
        title: '检测项工单',
        visible: false,
        form: {},
        tableData: [],
        rowIndex: [],
        curretNum: 0,
        qms_qualityResultContent: 1,
        workColumns: [
          {
            minWidth: 150,
            prop: 'code',
            align: 'center',
            label: '检测项工单号',
            showOverflowTooltip: true
          },
          {
            minWidth: 150,
            prop: 'qualityWorkOrderCode',
            align: 'center',
            label: '检测工单编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 150,
            prop: 'qualityWorkOrderName',
            align: 'center',
            label: '检测工单名称',
            showOverflowTooltip: true
          },
          {
            minWidth: 150,
            prop: 'qualityWorkOrderCode',
            align: 'center',
            label: '来源单号',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'qualityType',
            slot: 'qualityType',
            align: 'center',
            label: '类型',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            slot: 'qualityMode',
            prop: 'qualityMode',
            align: 'center',
            label: '检测方式',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'productCode',
            align: 'center',
            label: '编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'productName',
            align: 'center',
            label: '名称',
            showOverflowTooltip: true
          },

          {
            minWidth: 100,
            prop: 'batchNo',
            align: 'center',
            label: '批次号',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'specification',
            align: 'center',
            label: '规格',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'brandNo',
            align: 'center',
            label: '牌号',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'produceTaskName',
            align: 'center',
            label: '工序名称',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'total',
            align: 'center',
            label: '总数量',
            formatter: (row) => {
              if (row.total) {
                return row.total + this.form.measureUnit || '';
              }
            },
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'sampleQuantity',
            headerSlot: 'isRequired',
            slot: 'sampleQuantity',
            align: 'center',
            label: '样品数',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'sampleNoQualifiedNumber',
            slot: 'sampleNoQualifiedNumber',
            align: 'center',
            label: '样品不合格数',
            showOverflowTooltip: true
          },
          {
            minWidth: 140,
            prop: 'sampleQualifiedNumber',
            headerSlot: 'isRequired',
            slot: 'sampleQualifiedNumber',
            align: 'center',
            formatter: (row) => {
              if (row.sampleQualifiedNumber) {
                return (
                  row.sampleQualifiedNumber + (this.form.measureUnit || '')
                );
              }
            },
            label: '样品合格数',
            showOverflowTooltip: true
          },
          {
            minWidth: 140,
            prop: 'lossNumber',
            slot: 'lossNumber',
            align: 'center',
            formatter: (row) => {
              if (row.lossNumber) {
                return row.lossNumber + (this.form.measureUnit || '');
              }
            },
            label: '损耗数（合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 140,
            prop: 'lossNumberUnqualified',
            slot: 'lossNumberUnqualified',
            align: 'center',
            formatter: (row) => {
              if (row.lossNumberUnqualified) {
                return (
                  row.lossNumberUnqualified + (this.form.measureUnit || '')
                );
              }
            },
            label: '损耗数（不合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 140,
            prop: 'retainedSampleQuantity',
            slot: 'retainedSampleQuantity',
            align: 'center',
            formatter: (row) => {
              if (row.retainedSampleQuantity) {
                return (
                  row.retainedSampleQuantity + (this.form.measureUnit || '')
                );
              }
            },
            label: '留样数（合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 140,
            prop: 'retainedSampleUnqualified',
            slot: 'retainedSampleUnqualified',
            align: 'center',
            formatter: (row) => {
              if (row.retainedSampleUnqualified) {
                return (
                  row.retainedSampleUnqualified + (this.form.measureUnit || '')
                );
              }
            },
            label: '留样数（不合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'hours',
            slot: 'hours',
            align: 'center',
            label: '工时',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'accessory',
            slot: 'accessory',
            align: 'center',
            label: '附件',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'qualityNames',
            slot: 'qualityNames',
            align: 'center',
            label: '检测人',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'qualityTimeEnd',
            slot: 'qualityTimeEnd',
            align: 'center',
            label: '检测时间',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'craftFiles',
            slot: 'craftFiles',
            align: 'center',
            label: '工艺文件',
            fixed: 'right',
            showOverflowTooltip: true
          }
        ],

        qualityResultsList: [
          {
            value: 1,
            label: '合格'
          },
          {
            value: 2,
            label: '不合格'
          },
          {
            value: 3,
            label: '让步接收'
          }
        ],
        sList: [], //质检工具筛选
        pageName: ''
      };
    },
    computed: {
      tableColumns() {
        return [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            minWidth: 150,
            prop: 'qualitySchemeTemplateCode',
            align: 'center',
            label: '检测方案编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'qualitySchemeTemplateName',
            align: 'center',
            label: '检测方案名称',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'categoryLevelClassName',
            align: 'center',
            label: '检测类型',
            showOverflowTooltip: true
          },
          {
            minWidth: 130,
            prop: 'inspectionCode',
            align: 'center',
            label: '检测项编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'inspectionName',
            align: 'center',
            label: '检测项名称',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'qualityStandardType',
            slot: 'qualityStandardType',
            align: 'center',
            label: '执行标准',
            showOverflowTooltip: true
          },
          {
            minWidth: 150,
            slot: 'defaultValue',
            prop: 'defaultValue',
            align: 'center',
            label: '工艺参数',
            showOverflowTooltip: true
          },
          {
            minWidth: 130,
            prop: 'executionMethod',
            slot: 'executionMethod',
            align: 'center',
            label: '执行方法',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'useTools',
            slot: 'useTools',
            align: 'center',
            label: '检测工具',
            showOverflowTooltip: true
          },
          {
            minWidth: 200,
            prop: 'qualityResultContent',
            align: 'center',
            slot: 'qualityResultContent',
            headerSlot: this.qms_qualityResultContent == 1 ? 'isRequired' : '',
            label: '检测内容',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'sampleQuantity',
            slot: 'sampleQuantity',
            headerSlot: 'isRequired',

            align: 'center',
            label: '样品数',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'qualifiedQuantity',
            align: 'center',
            slot: 'qualifiedQuantity',
            label: '合格数',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'noQualifiedQuantity',
            slot: 'noQualifiedQuantity',
            align: 'center',
            label: '不合格数',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'lossNumber',
            slot: 'lossNumber',
            align: 'center',
            label: '损耗数（合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'lossNumberUnqualified',
            slot: 'lossNumberUnqualified',
            align: 'center',
            label: '损耗数（不合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'retainedSampleQuantity',
            slot: 'retainedSampleQuantity',
            align: 'center',
            label: '留样数（合格品）',
            showOverflowTooltip: true
          },
          {
            minWidth: 180,
            prop: 'retainedSampleUnqualified',
            slot: 'retainedSampleUnqualified',
            align: 'center',
            label: '留样数（不合格品）',
            showOverflowTooltip: true
          },

          {
            minWidth: 130,
            prop: 'qualityResults',
            slot: 'qualityResults',
            align: 'center',
            label: '检测结果',
            showOverflowTooltip: true,
            fixed: 'right'
          },
          {
            minWidth: 150,
            prop: 'experimentCode',
            align: 'center',
            label: '实验编号',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'inspectImage',
            slot: 'inspectImage',
            align: 'center',
            label: '检验图片',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'imgUrl',
            slot: 'imgUrl',
            align: 'center',
            label: '附件',
            showOverflowTooltip: true
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 120,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true,
            fixed: 'right'
          }
        ];
      },
      getSampleQuantityCount() {
        return this.form.sampleQuantity;
      }
    },

    created() {
      this.requestDict('质检计划类型');
      this.requestDict('取样类型');
      this.requestDict('质检标准类型');
      parameterGetByCode({
        code: 'qms_qualityResultContent'
      }).then((res) => {
        this.qms_qualityResultContent = res?.value;
      });
    },
    methods: {
      async craftFiles(row) {
        const res = await parameterGetByCode({
          code: 'mes_craft_file_by_category_code'
        });
        const byCategory = res?.value === '1';

        if (byCategory) {
          this.$refs.wokePopupRef.openTwo(row);
        } else {
          const data = row.qualityWorkOrderId
            ? await craftFiles(row.qualityWorkOrderId)
            : [];
          this.$refs.wokePopupRef.open(data.map((item) => item.id));
        }
      },
      experimentReport(row, type) {
        console.log(this.getSampleQuantityCount, 'this.form');
        this.$refs.experimentReport.open(
          {
            ...row,
            batchNo: this.form.batchNo,
            qualityWorkOrderId: this.form.qualityWorkOrderId,
            getSampleQuantityCount: this.form.sampleQuantity
          },
          type
        );
      },
      experimentReportDone(data) {
        console.log(data);
        let index = this.tableData.findIndex((item) => item.id == data.id);
        this.$set(this.tableData, index, data);
        console.log(this.tableData);

        // this.initData();
      },

      async open({ workData, row, list }, type, pageName) {
        this.tableData = [];
        this.pageName = pageName;
        this.type = type;
        if (pageName == 'inspectionProjectTask') {
          this.title = '检测项任务单';
        }
        if (pageName == 'inspectionProjectRequest') {
          this.title = '检测项受托单';
        }
        if (type == 'report') {
          let data = { ...row, ...workData };
          console.log(data, workData);
          data.sampleQuantity = row.sampleQuantity || data.workSampleCount;
          data.sampleNoQualifiedNumber = row.sampleNoQualifiedNumber || 0;
          data.sampleQualifiedNumber =
            row.sampleQualifiedNumber ||
            data.sampleQuantity - data.sampleNoQualifiedNumber ||
            0;
          this.$set(this, 'form', JSON.parse(JSON.stringify(data)));
          console.log(this.form, 'this.form');
          this.tableData = JSON.parse(JSON.stringify(list));
          this.tableData.forEach((item, index) => {
            if (item.experimentCode) {
              this.$set(this.tableData[index], 'executionMethod', 2);
            }
            this.$set(
              this.tableData[index],
              'executionMethod',
              item.executionMethod || 1
            );
          });
          // if (row.sampleQuantity) {
          //   this.form.remainingSampleCount =
          //     Number(row.sampleQuantity) +
          //     Number(this.form.remainingSampleCount);
          // }
        } else {
          this.$set(this, 'form', JSON.parse(JSON.stringify(workData)));
          this.$set(
            this.form,
            'sampleNoQualifiedNumber',
            this.form.sampleNoQualifiedNumber || 0
          );
          this.$set(
            this.form,
            'sampleQualifiedNumber',
            this.form.sampleQualifiedNumber ||
              this.form.sampleQuantity - this.form.sampleNoQualifiedNumber ||
              0
          );

          this.tableData = JSON.parse(JSON.stringify(list));
          // if (this.form.qualityWorkOrderId) {
          //   this.form.remainingSampleCount =
          //     this.form.sampleQuantity + this.form.remainingSampleCount;
          // }
        }

        this.visible = true;
      },
      handleOneKeyQualified() {
        this.tableData.forEach((item, index) => {
          this.$set(this.tableData[index], 'qualityResults', 1);
        });
      },
      formSampleQuantityChange() {
        if (this.form.sampleQuantity < 0) {
          this.form.sampleQuantity = 0;
        }
        if (this.form.sampleQuantity > this.form.workSampleCount) {
          this.form.sampleQuantity = this.form.workSampleCount;
        }
        if (
          this.form.sampleQuantity <
          Math.max(...this.tableData.map((item) => item.sampleQuantity))
        ) {
          this.tableData.forEach((item, index) => {
            this.resetData(item, index, [
              'qualifiedQuantity',
              'noQualifiedQuantity',
              'sampleQuantity'
            ]);
          });
        }
        this.form.sampleQualifiedNumber = this.form.sampleQuantity;
        this.form.sampleNoQualifiedNumber = 0;
      },
      formSampleNoQualifiedNumberChange() {
        if (+this.form.sampleNoQualifiedNumber < 0) {
          this.form.sampleNoQualifiedNumber = 0;
        }
        if (+this.form.sampleNoQualifiedNumber > this.form.sampleQuantity) {
          this.form.sampleNoQualifiedNumber = this.form.sampleQuantity;
        }
        this.form.sampleQualifiedNumber =
          this.form.sampleQuantity - this.form.sampleNoQualifiedNumber;
      },

      handleClose() {
        this.visible = false;

        if (this.$refs.wokePopupRef) {
          this.$refs.wokePopupRef.visible = false;
        }
      },
      handleConfirm() {
        let isHandleConfirm = false;

        if (!this.form.sampleQuantity) {
          return this.$message.error('样品数不能为空！');
        }
        this.tableData.forEach((item, index) => {
          item.status = 1;
          if (!item.qualityResultContent) {
            isHandleConfirm = true;
          }
        });
        if (!this.pageName) {
          this.$emit('success', { data: this.form, tableData: this.tableData });
          this.visible = false;
        } else {
          if (isHandleConfirm && this.qms_qualityResultContent == 1) {
            return this.$message.error('检测内容不能为空！');
          }
          let api =
            this.pageName == 'inspectionProjectTask'
              ? exeTaskReportWork
              : exeEntrustReportWork;
          api({
            ...this.form,
            templateList: this.tableData
          }).then((res) => {
            this.$message.success('操作成功');
            this.$emit('reload');
            this.visible = false;
          });
        }
      },
      inputValue(type, item, index) {
        if (item[type] < 0) {
          item[type] = 0;
        }
        //样品数
        if (type == 'sampleQuantity') {
          this.isSampleQuantity(item, index);
        }
        //样品合格数、不合格数
        if (type == 'qualifiedQuantity' || type == 'noQualifiedQuantity') {
          this.isQualifiedQuantity(item, index, type);
        }
        //损耗数
        if (type == 'lossNumber' || type == 'lossNumberUnqualified') {
          this.setNumber(item, index, type, '损耗', 'lossNumber');
        }
        //留样数
        if (
          type == 'retainedSampleQuantity' ||
          type == 'retainedSampleUnqualified'
        ) {
          this.setNumber(item, index, type, '留样', 'retainedSampleQuantity');
        }
      }
    }
  };
</script>

<style scoped lang="scss">
  ::v-deep .warn {
    color: red;
    .el-input__inner {
      color: red;
    }
  }
</style>
