吴羡
11 小时以前 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">
@@ -229,10 +229,12 @@
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/performance/class";
import {mapGetters} from "@/utils/store-compat";
import draftSave from '@/mixins/draftSave'
export default {
  name: "check-record",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [draftSave],
  data() {
    // 这里存放数据
    return {
@@ -281,6 +283,7 @@
        { label: '相对偏差', value: 2 },
      ],
      equipOptions: [],
      selectedDeviceId: '',
      submitFormLoading: false,
      userList: [],
      reviewUserId: '',
@@ -297,6 +300,7 @@
  methods: {
    openDialog(row) {
      this.dialogVisible = true
      this.selectedDeviceId = ''
      this.form.planDetailsId = row.planDetailsId
      this.checkChargerUserId = row.checkChargerUserId
      this.getEquipOptions()
@@ -319,15 +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: '' })
@@ -340,6 +367,8 @@
      addExamineRecord(this.form).then(res => {
        if (res.code == 200) {
          this.$message.success('新增成功')
          this.draftClear('checkRecordForm')
          this.draftClear('checkRecordRows')
          this.resetForm()
        }
        this.submitFormLoading = false
@@ -356,6 +385,8 @@
      reviewExamineRecord(params).then(res => {
        if (res.code == 200) {
          this.$message.success('审核成功')
          this.draftClear('checkRecordForm')
          this.draftClear('checkRecordRows')
          this.resetForm()
        }
        this.submitFormLoading = false
@@ -364,6 +395,8 @@
      })
    },
    resetForm() {
      this.draftStop('checkRecordForm')
      this.draftStop('checkRecordRows')
      this.dialogVisible = false
      this.$emit('closeDialog1')
    },
@@ -378,6 +411,7 @@
            m.id = m.id
            return m
          })
          this.matchDeviceOption()
        }
      }).catch(error => {
        console.error(error)