吴羡
9 小时以前 c6e96cdb8b1cfb51e9a45bf86c38d1353e983127
src/views/CNAS/resourceDemand/device/component/equipmentCheck.vue
@@ -17,7 +17,7 @@
          <span style="width: 80px">A仪器名称:</span>
          <el-select v-model="form.adeviceId" :disabled="currentStep !== 0" class="table_input" clearable filterable
            placeholder="设备名称" size="small" style="width:200px" @change="(val) => changeMachineName(val, 'A')">
            <el-option v-for="item in equipOptions" :key="item.value" :label="item.label" :value="item.id">
            <el-option v-for="item in equipOptions" :key="item.id" :label="item.label" :value="item.id">
              {{ item.label + '-' + item.value }}
            </el-option>
          </el-select>
@@ -36,7 +36,7 @@
          <span style="width: 80px">B仪器名称:</span>
          <el-select v-model="form.bdeviceId" :disabled="currentStep !== 0" class="table_input" clearable filterable
            placeholder="设备名称" size="small" style="width:200px" @change="(val) => changeMachineName(val, 'B')">
            <el-option v-for="item in equipOptions" :key="item.value" :label="item.label" :value="item.id">
            <el-option v-for="item in equipOptions" :key="item.id" :label="item.label" :value="item.id">
              {{ item.label + '-' + item.value }}
            </el-option>
          </el-select>
@@ -55,7 +55,7 @@
          <span style="width: 80px">C仪器名称:</span>
          <el-select v-model="form.cdeviceId" :disabled="currentStep !== 0" class="table_input" clearable filterable
            placeholder="设备名称" size="small" style="width:200px" @change="(val) => changeMachineName(val, 'C')">
            <el-option v-for="item in equipOptions" :key="item.value" :label="item.label" :value="item.id">
            <el-option v-for="item in equipOptions" :key="item.id" :label="item.label" :value="item.id">
              {{ item.label + '-' + item.value }}
            </el-option>
          </el-select>
@@ -73,7 +73,7 @@
        <el-button v-if="currentStep === 0" size="small" type="primary" @click="addTableRow">添加</el-button>
      </div>
      <div style="margin: 10px 0">
        <el-table ref="yearTable" :data="recordContrastDetailsList" height="300px" style="width: 100% ;"
        <el-table ref="yearTable" :data="form.recordContrastDetailsList" height="300px" style="width: 100% ;"
 border>
          <el-table-column align="center" header-align="center" label="序号" type="index" width="60"></el-table-column>
          <el-table-column label="核查项目" min-width="170" prop="checkItems">
@@ -127,7 +127,7 @@
        </div>
      </div>
      <template #footer><span  class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button @click="handleCancel">取 消</el-button>
        <el-button v-if="currentStep === 0 && userId == checkChargerUserId" :loading="submitFormLoading" type="primary" @click="submitCheck">确
          定</el-button>
        <el-button v-if="currentStep === 1 && userId == reviewUserId" :loading="submitFormLoading" @click="examine(0)">不通过</el-button>
@@ -147,10 +147,12 @@
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/business/inspectionTask";
import {mapGetters} from "@/utils/store-compat";
import draftSave from '@/mixins/draftSave'
export default {
  name: "equipment-check",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [draftSave],
  data() {
    // 这里存放数据
    return {
@@ -177,7 +179,6 @@
        planDetailsId: '',
      },
      equipOptions: [],
      recordContrastDetailsList: [],
      userList: [],
      checkChargerUserId: '',
      reviewUserId: ''
@@ -200,10 +201,12 @@
      this.searchInfo()
    },
    searchInfo() {
      getExamineRecordContrast({ planDetailsId: this.form.planDetailsId }).then(res => {
      const planDetailsId = this.form.planDetailsId
      getExamineRecordContrast({ planDetailsId }).then(res => {
        if (res.code === 200) {
          this.form = { ...res.data }
          this.recordContrastDetailsList = this.form.recordContrastDetailsList || []
          // 无历史记录时接口可能返回空,planDetailsId 必须保留,否则无法提交
          this.form = { ...(res.data || {}), planDetailsId }
          this.form.recordContrastDetailsList = this.form.recordContrastDetailsList || []
          if (!this.form.reviewUserId) {
            this.currentStep = 0
          } else {
@@ -213,6 +216,9 @@
            this.currentStep = 2
          }
          this.reviewUserId = this.form.reviewUserId
          if (this.currentStep === 0) {
            this.draftRestore('equipmentCheck', 'form', this.form.planDetailsId, 'dialogVisible')
          }
        }
      }).catch(error => {
        console.error(error)
@@ -220,29 +226,36 @@
    },
    // 赋值仪器编号
    changeMachineName(value, type) {
      const index = this.equipOptions.findIndex(item => item.id === value)
      if (index > -1) {
        if (type === 'A') {
          this.form['adeviceNumber'] = this.equipOptions[index].value
        }
        if (type === 'B') {
          this.form['bdeviceNumber'] = this.equipOptions[index].value
        }
        if (type === 'C') {
          this.form['cdeviceNumber'] = this.equipOptions[index].value
        }
      const item = this.equipOptions.find(device => device.id === value)
      if (type === 'A') {
        this.form['adeviceNumber'] = item ? item.value : ''
      }
      if (type === 'B') {
        this.form['bdeviceNumber'] = item ? item.value : ''
      }
      if (type === 'C') {
        this.form['cdeviceNumber'] = item ? item.value : ''
      }
    },
    // 添加表格数据
    addTableRow() {
      this.recordContrastDetailsList.push({ checkItems: '' })
      if (!this.form.recordContrastDetailsList) {
        this.form.recordContrastDetailsList = []
      }
      this.form.recordContrastDetailsList.push({ checkItems: '' })
    },
    submitCheck() {
      this.form.recordContrastDetailsList = this.HaveJson(this.recordContrastDetailsList)
      const deviceIds = [this.form.adeviceId, this.form.bdeviceId, this.form.cdeviceId].filter(Boolean)
      if (new Set(deviceIds).size !== deviceIds.length) {
        this.$message.error('A/B/C 仪器不能选择同一台设备')
        return
      }
      this.form.recordContrastDetailsList = this.HaveJson(this.form.recordContrastDetailsList || [])
      this.submitFormLoading = true
      addExamineRecordContrast(this.form).then(res => {
        if (res.code == 200) {
          this.$message.success('新增成功')
          this.draftClear('equipmentCheck')
          this.resetForm()
        }
        this.submitFormLoading = false
@@ -258,6 +271,7 @@
      reviewExamineRecordContrast(params).then(res => {
        if (res.code == 200) {
          this.$message.success('审核成功')
          this.draftClear('equipmentCheck')
          this.resetForm()
        }
        this.submitFormLoading = false
@@ -265,7 +279,23 @@
        this.submitFormLoading = false
      })
    },
    // 取消按钮:确认后整体清空本次草稿;右上角关闭/意外退出则保留草稿
    handleCancel() {
      if (this.currentStep !== 0) {
        this.resetForm()
        return
      }
      this.$confirm('取消后本次填写的数据将被清空,且无法恢复,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '继续填写',
        type: 'warning'
      }).then(() => {
        this.draftClear('equipmentCheck')
        this.resetForm()
      }).catch(() => {})
    },
    resetForm() {
      this.draftStop('equipmentCheck')
      this.dialogVisible = false
      this.$emit('closeDialog')
    },