吴羡
15 小时以前 c6e96cdb8b1cfb51e9a45bf86c38d1353e983127
src/views/CNAS/resourceDemand/device/component/checkRecord.vue
@@ -1,7 +1,7 @@
<template>
  <div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible"
      title="仪器设备期间核查比对记录表" width="80%" @close="resetForm">
      title="仪器设备期间核查记录表" width="80%" @close="resetForm">
      <el-steps :active="currentStep" align-center finish-status="success">
        <el-step title="填写设备核查对比记录"></el-step>
        <el-step title="审核"></el-step>
@@ -10,9 +10,9 @@
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 110px">仪器名称:</span>
            <el-select v-model="form.deviceName" :disabled="currentStep !== 0" class="table_input" clearable filterable
              placeholder="设备名称" size="small" style="width:200px" @change="(val) => changeMachineName(val)">
              <el-option v-for="item in equipOptions" :key="item.value" :label="item.label" :value="item.label">
            <el-select v-model="selectedDeviceId" :disabled="currentStep !== 0" class="table_input" clearable filterable
              placeholder="设备名称" size="small" style="width:200px" @change="changeMachineName">
              <el-option v-for="item in equipOptions" :key="item.id" :label="item.label" :value="item.id">
                {{ item.label + '-' + item.value }}
              </el-option>
            </el-select>
@@ -84,11 +84,11 @@
          </div>
        </el-col>
      </el-row>
      <el-button size="small" style="margin: 10px 0" type="primary" @click="addRow">添加</el-button>
      <el-button v-if="currentStep === 0" size="small" style="margin: 10px 0" type="primary" @click="addRow">添加</el-button>
      <el-table :data="recordDetailList" height="300" style="width: 100%" border>
        <el-table-column label="测试点" min-width="130" prop="testPoint">
          <template #default="scope">
            <el-input v-model="scope.row.testPoint" clearable size="small"></el-input>
            <el-input v-model="scope.row.testPoint" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
@@ -283,6 +283,7 @@
        { label: '相对偏差', value: 2 },
      ],
      equipOptions: [],
      selectedDeviceId: '',
      submitFormLoading: false,
      userList: [],
      reviewUserId: '',
@@ -299,6 +300,7 @@
  methods: {
    openDialog(row) {
      this.dialogVisible = true
      this.selectedDeviceId = ''
      this.form.planDetailsId = row.planDetailsId
      this.checkChargerUserId = row.checkChargerUserId
      this.getEquipOptions()
@@ -321,19 +323,38 @@
            this.currentStep = 2
          }
          this.reviewUserId = this.form.reviewUserId
          this.matchDeviceOption()
          this.$nextTick(() => {
            this.draftRestore('checkRecordForm', 'form', this.form.planDetailsId, 'dialogVisible')
            this.draftRestore('checkRecordRows', 'recordDetailList', this.form.planDetailsId, 'dialogVisible')
            // 草稿里可能改过设备,恢复后重新匹配下拉选中项
            this.matchDeviceOption()
          })
        }
      }).catch(error => {
        console.error(error)
      })
    },
    // 赋值仪器编号
    // 按设备 id 回填名称和编号,避免同名设备选错
    changeMachineName(value) {
      const index = this.equipOptions.findIndex(item => item.deviceName === value)
      this.form.deviceNumber = this.equipOptions[index].managementNumber
      const item = this.equipOptions.find(device => device.id === value)
      if (item) {
        this.form.deviceName = item.deviceName
        this.form.deviceNumber = item.managementNumber
      } else {
        this.form.deviceName = ''
        this.form.deviceNumber = ''
      }
    },
    // 历史记录没有 deviceId,按名称+编号反查下拉选项
    matchDeviceOption() {
      if (!this.equipOptions.length || !this.form.deviceName) {
        return
      }
      const match = this.form.deviceNumber
        ? this.equipOptions.find(item => item.deviceName === this.form.deviceName && item.managementNumber === this.form.deviceNumber)
        : this.equipOptions.find(item => item.deviceName === this.form.deviceName)
      this.selectedDeviceId = match ? match.id : ''
    },
    addRow() {
      this.recordDetailList.push({ testPoint: '' })
@@ -390,6 +411,7 @@
            m.id = m.id
            return m
          })
          this.matchDeviceOption()
        }
      }).catch(error => {
        console.error(error)