吴羡
10 小时以前 d2eed0eb7c2f9537d5eaab7ccc3b6ab258959227
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<template>
  <div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible"
      :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-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" :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>
  </div>
</template>
 
<script>
import {
  addExamineRecord,
  reviewExamineRecord,
  deviceScopeSearch,
  findExaminePlanDetail,
  resolveExaminePlanDetail,
  updateDeviceExaminePlanDetail,
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/performance/class";
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",
  components: { LimsAttachment },
  data() {
    // 这里存放数据
    return {
      dialogVisible: false,
      form: createEmptyForm(),
      currentStep: 0,
      equipOptions: [],
      selectedDeviceId: '',
      submitFormLoading: false,
      userList: [],
      rules: {
        checkMethod: [{ required: true, message: '请填写核查方式', trigger: 'blur' }],
      },
    }
  },
  // 方法集合
  methods: {
    // 审核已提交的核查记录
    openDialog(row) {
      this.dialogVisible = true
      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.$nextTick(() => {
        if (this.$refs.recordForm) {
          this.$refs.recordForm.clearValidate()
        }
        this.resolveAttachmentPlan()
      })
    },
    // 按设备 id 回填名称和编号,避免同名设备选错
    changeMachineName(value) {
      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()
    },
    setCheckChargerUser(value) {
      const item = this.userList.find(user => user.id === value)
      this.form.checkChargerUser = item ? item.name : ''
    },
    // 提交核查记录
    submitCheck() {
      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 = 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(statue === 1 ? '审核通过' : '已退回')
          this.resetForm()
        }
        this.submitFormLoading = false
      }).catch(err => {
        this.submitFormLoading = false
      })
    },
    resetForm() {
      this.dialogVisible = false
      this.$emit('closeDialog1')
    },
    // 获取所有设备
    getEquipOptions() {
      this.equipOptions = []
      deviceScopeSearch({ status: 0 }).then(res => {
        if (res.code === 200 && res.data) {
          this.equipOptions = res.data.map(m => {
            m.value = m.managementNumber
            m.label = m.deviceName
            m.id = m.id
            return m
          })
        }
      }).catch(error => {
        console.error(error)
      })
    },
    getUserList() {
      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>
.record-steps {
  margin-bottom: 14px;
}
 
.form-section {
  padding: 12px 14px 0;
  border: 1px solid #ebeef5;
  border-radius: 6px;
  margin-bottom: 10px;
}
 
.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-section :deep(.el-form-item) {
  margin-bottom: 12px;
}
</style>