吴羡
13 小时以前 d2eed0eb7c2f9537d5eaab7ccc3b6ab258959227
src/views/CNAS/resourceDemand/device/component/checkRecord.vue
@@ -1,219 +1,132 @@
<template>
  <div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible"
      title="仪器设备期间核查比对记录表" width="80%" @close="resetForm">
      <el-steps :active="currentStep" align-center finish-status="success">
        <el-step title="填写设备核查对比记录"></el-step>
      :title="currentStep === 0 ? '新增核查记录' : '设备核查记录'" top="5vh" width="960px" @close="resetForm">
      <el-steps v-if="currentStep === 1" class="record-steps" :active="1" align-center finish-status="success">
        <el-step title="填写核查记录"></el-step>
        <el-step title="审核"></el-step>
      </el-steps>
      <el-row>
        <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">
                {{ item.label + '-' + item.value }}
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">仪器编号:</span>
            <el-input v-model="form.deviceNumber" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">精度等级:</span>
            <el-input v-model="form.accuracyGrade" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
      </el-row>
      <div style="margin: 10px">核查使用物质</div>
      <el-row>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">名称:</span>
            <el-input v-model="form.materialName" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">编号:</span>
            <el-input v-model="form.materialNumber" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">精度/不确定度:</span>
            <el-input v-model="form.materialAccuracyUncertainty" :disabled="currentStep !== 0" clearable
              size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">型号:</span>
            <el-input v-model="form.materialModel" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">核查方式:</span>
            <el-input v-model="form.materialCheckMethod" :disabled="currentStep !== 0" clearable
              size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">核查项目:</span>
            <el-input v-model="form.materialCheckItems" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">温度:</span>
            <el-input v-model="form.temperature" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
            <span style="width: 130px">湿度:</span>
            <el-input v-model="form.humidity" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
      </el-row>
      <el-button 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>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue1" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue1" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue2" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue2" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue3" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue3" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue4" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue4" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue5" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue5" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="180">
          <template #header="scope">
            <el-input v-model="form.dataValue6" :disabled="currentStep !== 0" size="small" />
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.dataValue6" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <table border="1" cellspacing="10" class="table">
        <tr>
          <td>最大偏差</td>
          <th>
            <el-input v-model="form.maximun1" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.maximun2" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.maximun3" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.maximun4" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.maximun5" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.maximun6" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
        </tr>
        <tr>
          <td>相对偏差</td>
          <th>
            <el-input v-model="form.relative1" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.relative2" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.relative3" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.relative4" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.relative5" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
          <th>
            <el-input v-model="form.relative6" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </th>
        </tr>
      </table>
      <el-row>
        <el-col :span="24">
          <div class="form-item">
            <span style="width: 80px">判定:</span>
            <el-input v-model="form.determine" :disabled="currentStep !== 0" clearable size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="form-item">
            <span style="width: 80px">备注:</span>
            <el-input v-model="form.remark" :disabled="currentStep !== 0" clearable size="small"
              type="textarea"></el-input>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="form-item">
            <span style="width: 116px">审核人:</span>
            <el-select v-model="form.reviewUserId" :disabled="currentStep !== 0" placeholder="请选择" size="small"
              style="width: 100%">
              <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </div>
        </el-col>
      </el-row>
      <template #footer><span  class="dialog-footer">
      <el-form ref="recordForm" :model="form" :rules="rules" label-width="104px">
        <div class="form-section">
          <div class="form-section-title">基本信息</div>
          <el-row :gutter="12">
            <el-col :span="12">
              <el-form-item label="仪器名称:" prop="deviceName">
                <el-select v-if="currentStep === 0" v-model="selectedDeviceId" clearable filterable
                  placeholder="请选择设备" size="small" style="width: 100%" @change="changeMachineName">
                  <el-option v-for="item in equipOptions" :key="item.id" :label="item.label + '-' + item.value"
                    :value="item.id"></el-option>
                </el-select>
                <el-input v-else v-model="form.deviceName" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检查日期:" prop="checkTime">
                <el-date-picker v-if="currentStep === 0" v-model="form.checkTime" clearable format="YYYY-MM-DD"
                  placeholder="选择检查日期" size="small" style="width: 100%" type="date" value-format="YYYY-MM-DD"
                  @change="resolveAttachmentPlan">
                </el-date-picker>
                <el-input v-else v-model="form.checkTime" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="管理编号:" prop="deviceNumber">
                <el-input v-model="form.deviceNumber" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="设备型号:" prop="deviceModel">
                <el-input v-model="form.deviceModel" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查人:" prop="checkChargerUserId">
                <el-select v-if="currentStep === 0" v-model="form.checkChargerUserId" clearable filterable
                  placeholder="请选择" size="small" style="width: 100%" @change="setCheckChargerUser">
                  <el-option v-for="item in chargerOptions" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
                </el-select>
                <el-input v-else v-model="form.checkChargerUser" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="form-section">
          <div class="form-section-title">核查内容</div>
          <el-row :gutter="12">
            <el-col :span="8">
              <el-form-item label="环境温湿度:" prop="environment">
                <el-input v-model="form.environment" :disabled="currentStep !== 0" clearable size="small"
                  placeholder="如:25℃ / 50%RH"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查依据:" prop="checkBasis">
                <el-input v-model="form.checkBasis" :disabled="currentStep !== 0" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查指标:" prop="checkIndex">
                <el-input v-model="form.checkIndex" :disabled="currentStep !== 0" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="核查方式:" prop="checkMethod">
                <el-input v-model="form.checkMethod" :disabled="currentStep !== 0" clearable :rows="2" size="small"
                  type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结果如何判定:" prop="howResults">
                <el-input v-model="form.howResults" :disabled="currentStep !== 0" clearable :rows="2" size="small"
                  type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="外观情况:">
                <el-radio-group v-model="form.appearanceStatus" :disabled="currentStep !== 0">
                  <el-radio value="良好">良好</el-radio>
                  <el-radio value="一般">一般</el-radio>
                  <el-radio value="损坏">损坏</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="运行状态:">
                <el-radio-group v-model="form.runningStatus" :disabled="currentStep !== 0">
                  <el-radio value="正常">正常</el-radio>
                  <el-radio value="异常">异常</el-radio>
                  <el-radio value="停机">停机</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注:" prop="remark">
                <el-input v-model="form.remark" :disabled="currentStep !== 0" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="form-section">
          <div class="form-section-title">附件资料</div>
          <el-form-item label-width="0">
            <lims-attachment ref="recordAttachment" inline upload-url="/deviceExaminePlan/uploadAttachment"
              select-url="/deviceExaminePlan/selectAttachments" delete-url="/deviceExaminePlan/deleteAttachment"
              id-param="planDetailsId" name-field="deviceName" title="核查记录附件"
              :main-id="form.planDetailsId" :readonly="currentStep === 1"
              :defer-upload="currentStep === 0" :tip="attachmentTip"></lims-attachment>
            <el-link v-if="form.fileUrl" type="primary" @click="openAttachment">
              {{ form.fileName || '查看原附件' }}
            </el-link>
          </el-form-item>
        </div>
      </el-form>
      <template #footer><span class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button v-if="currentStep === 0 && checkChargerUserId == userId" :loading="submitFormLoading" type="primary" @click="submitCheck">确
          定</el-button>
        <el-button v-if="currentStep === 1 && userId == reviewUserId" :loading="submitFormLoading" @click="examine(0)">不通过</el-button>
        <el-button v-if="currentStep === 1 && userId == reviewUserId" :loading="submitFormLoading" type="primary" @click="examine(1)">通
        <el-button v-if="currentStep === 0" :loading="submitFormLoading" type="primary" @click="submitCheck">确
          认</el-button>
        <el-button v-if="currentStep === 1" :loading="submitFormLoading" @click="examine(0)">不通过</el-button>
        <el-button v-if="currentStep === 1" :loading="submitFormLoading" type="primary" @click="examine(1)">通
          过</el-button>
      </span></template>
    </el-dialog>
@@ -222,140 +135,207 @@
<script>
import {
  getExamineRecord,
  addExamineRecord,
  reviewExamineRecord,
  deviceScopeSearch,
  findExaminePlanDetail,
  resolveExaminePlanDetail,
  updateDeviceExaminePlanDetail,
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/performance/class";
import {mapGetters} from "@/utils/store-compat";
import LimsAttachment from '@/components/Attachment/lims-attachment.vue'
const createEmptyForm = () => ({
  deviceId: '',
  deviceName: '',
  deviceNumber: '',
  deviceModel: '',
  checkTime: '',
  checkIndex: '',
  checkMethod: '',
  howResults: '',
  checkChargerUserId: '',
  checkChargerUser: '',
  environment: '',
  checkBasis: '',
  appearanceStatus: '',
  runningStatus: '',
  remark: '',
  fileName: '',
  fileUrl: '',
  planDetailsId: '',
})
export default {
  name: "check-record",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  components: { LimsAttachment },
  data() {
    // 这里存放数据
    return {
      dialogVisible: false,
      recordDetailList: [],
      search: "",
      form: {
        deviceName: '',
        deviceNumber: '',
        accuracyGrade: '',
        materialName: '',
        materialNumber: '',
        materialAccuracyUncertainty: '',
        materialModel: '',
        materialCheckMethod: '',
        materialCheckItems: '',
        temperature: '',
        humidity: '',
        recordDetailList: [],
        dataValue1: '',
        dataValue2: '',
        dataValue3: '',
        dataValue4: '',
        dataValue5: '',
        dataValue6: '',
        maximun1: '',
        maximun2: '',
        maximun3: '',
        maximun4: '',
        maximun5: '',
        maximun6: '',
        relative1: '',
        relative2: '',
        relative3: '',
        relative4: '',
        relative5: '',
        relative6: '',
        determine: '',
        remark: '',
        planDetailsId: '',
        reviewUserId: '',
      },
      form: createEmptyForm(),
      currentStep: 0,
      distributionDetailList: [
        { label: '最大偏差', value: 1 },
        { label: '相对偏差', value: 2 },
      ],
      equipOptions: [],
      selectedDeviceId: '',
      submitFormLoading: false,
      userList: [],
      reviewUserId: '',
      checkChargerUserId: '',
      rules: {
        checkMethod: [{ required: true, message: '请填写核查方式', trigger: 'blur' }],
      },
    }
  },
  mounted() {
  },
  computed: {
    ...mapGetters(["userId"]),
  },
  // 方法集合
  methods: {
    // 审核已提交的核查记录
    openDialog(row) {
      this.dialogVisible = true
      this.form.planDetailsId = row.planDetailsId
      this.checkChargerUserId = row.checkChargerUserId
      this.currentStep = 1
      this.selectedDeviceId = row.deviceId || ''
      this.form = {
        deviceId: row.deviceId || '',
        deviceName: row.deviceName || '',
        deviceNumber: row.deviceNumber || '',
        deviceModel: row.deviceModel || '',
        checkTime: row.checkTime || '',
        checkIndex: row.checkIndex || '',
        checkMethod: row.checkMethod || '',
        howResults: row.howResults || '',
        checkChargerUserId: row.checkChargerUserId || '',
        checkChargerUser: row.checkChargerUser || '',
        environment: row.environment || '',
        checkBasis: row.checkBasis || '',
        appearanceStatus: row.appearanceStatus || '',
        runningStatus: row.runningStatus || '',
        remark: row.remark || '',
        fileName: row.fileName || '',
        fileUrl: row.fileUrl || '',
        planDetailsId: row.planDetailsId,
      }
    },
    // 新增核查记录:自选设备,提交时自动匹配/创建本轮计划明细
    openAddDialog() {
      this.dialogVisible = true
      this.currentStep = 0
      this.form = createEmptyForm()
      this.selectedDeviceId = ''
      const now = new Date()
      this.form.checkTime = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0')
      this.getEquipOptions()
      this.getUserList()
      this.searchInfo()
    },
    searchInfo() {
      getExamineRecord({ planDetailsId: this.form.planDetailsId }).then(res => {
        if (res.code === 200) {
          let planDetailsId = this.form.planDetailsId
          this.form = { ...res.data }
          this.form.planDetailsId = planDetailsId
          this.recordDetailList = this.form.recordDetailList || []
          if (!this.form.reviewUserId) {
            this.currentStep = 0
          } else {
            this.currentStep = 1
          }
          if (this.form.reviewStatus === 1) {
            this.currentStep = 2
          }
          this.reviewUserId = this.form.reviewUserId
      this.$nextTick(() => {
        if (this.$refs.recordForm) {
          this.$refs.recordForm.clearValidate()
        }
      }).catch(error => {
        console.error(error)
        this.resolveAttachmentPlan()
      })
    },
    // 赋值仪器编号
    // 按设备 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.deviceId = item.id
        this.form.deviceName = item.deviceName
        this.form.deviceNumber = item.managementNumber
        this.form.deviceModel = item.specificationModel || ''
      } else {
        this.form.deviceId = ''
        this.form.deviceName = ''
        this.form.deviceNumber = ''
        this.form.deviceModel = ''
      }
      this.resolveAttachmentPlan()
    },
    addRow() {
      this.recordDetailList.push({ testPoint: '' })
    setCheckChargerUser(value) {
      const item = this.userList.find(user => user.id === value)
      this.form.checkChargerUser = item ? item.name : ''
    },
    // 提交表单
    // 提交核查记录
    submitCheck() {
      console.log(333, this.form)
      this.form.recordDetailList = this.HaveJson(this.recordDetailList)
      this.submitFormLoading = true
      addExamineRecord(this.form).then(res => {
        if (res.code == 200) {
          this.$message.success('新增成功')
          this.resetForm()
      if (!this.selectedDeviceId) {
        this.$message.error('请选择设备')
        return
      }
      if (!this.form.checkTime) {
        this.$message.error('请选择核查时间')
        return
      }
      this.$refs.recordForm.validate(valid => {
        if (!valid) {
          return
        }
        this.submitFormLoading = false
      }).catch(err => {
        this.submitFormLoading = true
        resolveExaminePlanDetail({ deviceId: this.selectedDeviceId, checkTime: this.form.checkTime }).then(res => {
          if (res.code !== 200) {
            this.$message.error(res.msg || '获取核查计划失败')
            this.submitFormLoading = false
            return
          }
          this.saveRecord(res.data.planDetailsId)
        }).catch(() => {
          this.submitFormLoading = false
        })
      })
    },
    saveRecord(planDetailsId) {
      this.form.planDetailsId = planDetailsId
      const params = {
        planDetailsId,
        deviceId: this.form.deviceId,
        deviceName: this.form.deviceName,
        deviceNumber: this.form.deviceNumber,
        checkTime: this.form.checkTime,
      }
      if (this.form.checkIndex) params.checkIndex = this.form.checkIndex
      if (this.form.checkMethod) params.checkMethod = this.form.checkMethod
      if (this.form.howResults) params.howResults = this.form.howResults
      if (this.form.checkChargerUserId) params.checkChargerUserId = this.form.checkChargerUserId
      if (this.form.checkChargerUser) params.checkChargerUser = this.form.checkChargerUser
      if (this.form.deviceModel) params.deviceModel = this.form.deviceModel
      params.environment = this.form.environment || ''
      params.checkBasis = this.form.checkBasis || ''
      params.appearanceStatus = this.form.appearanceStatus || ''
      params.runningStatus = this.form.runningStatus || ''
      if (this.form.remark) params.remark = this.form.remark
      if (this.form.fileName) params.fileName = this.form.fileName
      if (this.form.fileUrl) params.fileUrl = this.form.fileUrl
      // 附件先暂存在页面上,确认提交时再连同核查记录一起保存,取消则什么都不留
      const attachmentRef = this.$refs.recordAttachment
      const flushPending = attachmentRef ? attachmentRef.flushPending(planDetailsId) : Promise.resolve()
      flushPending.then(() => {
        updateDeviceExaminePlanDetail(params).then(res => {
          if (res.code !== 200) {
            this.$message.error(res.msg || '保存核查记录失败')
            this.submitFormLoading = false
            return
          }
          addExamineRecord({ planDetailsId }).then(recordRes => {
            if (recordRes.code == 200) {
              this.$message.success('核查记录已提交,等待审核')
              this.resetForm()
            } else {
              this.$message.error(recordRes.msg || '提交核查记录失败')
            }
            this.submitFormLoading = false
          }).catch(() => {
            this.submitFormLoading = false
          })
        }).catch(() => {
          this.submitFormLoading = false
        })
      }).catch(() => {
        // 上传失败的具体原因由 request 拦截器统一提示
        this.submitFormLoading = false
      })
    },
    // 提交审核
    examine(statue) {
      this.submitFormLoading = true
      const params = {
        planDetailsId: this.form.planDetailsId,
        reviewStatus: statue,
      }
      reviewExamineRecord(params).then(res => {
        if (res.code == 200) {
          this.$message.success('审核成功')
          this.$message.success(statue === 1 ? '审核通过' : '已退回')
          this.resetForm()
        }
        this.submitFormLoading = false
@@ -384,37 +364,86 @@
      })
    },
    getUserList() {
      selectUserCondition().then(res => {
      selectUserCondition({ type: 4 }).then(res => {
        this.userList = res.data
      })
    },
    // 附件内嵌在表单里:设备+日期确定后只查可复用明细,不提前建档,避免取消后留下空记录
    resolveAttachmentPlan() {
      if (this.currentStep !== 0 || !this.selectedDeviceId || !this.form.checkTime) {
        this.form.planDetailsId = ''
        return
      }
      const deviceId = this.selectedDeviceId
      const checkTime = this.form.checkTime
      this.form.planDetailsId = ''
      findExaminePlanDetail({ deviceId, checkTime }).then(res => {
        if (res.code !== 200 || !res.data) {
          return
        }
        // 请求期间用户可能已切换设备或日期,避免回填过期明细
        if (this.selectedDeviceId === deviceId && this.form.checkTime === checkTime) {
          this.form.planDetailsId = res.data.planDetailsId
        }
      }).catch(() => {
      })
    },
    // 兼容历史单附件
    openAttachment() {
      if (!this.form.fileUrl) {
        return
      }
      const isImage = /\.(jpg|jpeg|png|gif)$/i.test(this.form.fileUrl)
      window.open(this.javaApi + (isImage ? '/img/' : '/word/') + this.form.fileUrl, '_blank')
    },
  },
  computed: {
    // 附件不提前上传,选好后随核查记录一起提交保存
    attachmentTip() {
      return '可直接选择附件,点“确认”时随核查记录一起保存'
    },
    // 责任人下拉:已保存的责任人不在候选列表时补一条,避免回显成用户ID
    chargerOptions() {
      const list = this.userList || []
      const id = this.form.checkChargerUserId
      if (id && !list.some(item => String(item.id) === String(id))) {
        return [...list, { id, name: this.form.checkChargerUser || String(id) }]
      }
      return list
    },
  },
}
</script>
<style scoped>
.table td {
  padding: 10px;
.record-steps {
  margin-bottom: 14px;
}
.table th {
  padding: 10px;
.form-section {
  padding: 12px 14px 0;
  border: 1px solid #ebeef5;
  border-radius: 6px;
  margin-bottom: 10px;
}
.form {
.form-section:last-child {
  margin-bottom: 0;
}
.form-section-title {
  display: flex;
  align-items: center;
  padding-left: 8px;
  border-left: 3px solid var(--el-color-primary);
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: #303133;
}
.form-item {
  display: flex;
  align-items: center;
  margin-right: 10px;
  margin-top: 10px;
}
:deep(.el-dialog__body) {
  max-height: 650px;
  overflow-y: auto;
.form-section :deep(.el-form-item) {
  margin-bottom: 12px;
}
</style>