gaoluyang
2025-04-18 ff6d23c5d61d1c6bee47e5863b57a915d98f7be1
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<template>
  <div>
    <div class="search">
      <el-button size="small" type="primary" @click="refreshTableList">刷 新</el-button>
      <el-button size="small" type="primary" @click="openDia('add')">新 增</el-button>
      <el-button :loading="outLoading" size="small" type="primary" @click="openHandleOut">导 出</el-button>
    </div>
    <div>
      <lims-table :tableData="tableData" :column="column"
                  height="calc(100vh - 20em)" @pagination="pagination"
                  :page="page" :tableLoading="tableLoading"></lims-table>
    </div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="usageTableDia"
               title="设备保养计划表" width="80%" @close="closeDialog">
      <div style="display: flex;align-items: center;">
        <el-button size="small" type="primary" @click="addTableRow" v-if="operationType !== 'check'">添加</el-button>
        <span style="width: 60px;margin-left: 10px">年份:</span>
        <el-date-picker v-model="form.impowerYear" type="year" value-format="yyyy" clearable size="small" format="yyyy"
                        placeholder="选择年" :disabled="operationType === 'check'">
        </el-date-picker>
      </div>
      <div style="margin: 10px 0">
        <el-table ref="deviceImpowerDetails" :data="deviceImpowerDetails" id="templateParamTable" row-key="deviceId"
                  :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }" border
                  height="560px" style="width: 100% ;">
          <el-table-column align="center" header-align="center" label="序号" type="index" width="60"></el-table-column>
          <el-table-column label="设备名称" min-width="170" prop="deviceName">
            <template slot-scope="scope">
              <el-input v-model="scope.row.deviceName" clearable
                        size="small" :disabled="operationType === 'check'"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="设备编号" min-width="140" prop="managementNumber">
            <template slot-scope="scope">
              <el-input v-model="scope.row.managementNumber" clearable
                        size="small" :disabled="operationType === 'check'"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="规格型号" min-width="120" prop="specificationModel">
            <template slot-scope="scope">
              <el-input v-model="scope.row.specificationModel" clearable
                        size="small" :disabled="operationType === 'check'"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="检测项目" min-width="120" prop="inspectionItem<">
            <template slot-scope="scope">
              <el-input v-model="scope.row.inspectionItem" clearable size="small"
                       :disabled="operationType === 'check'"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="被授权人" min-width="160" prop="delegatee">
            <template slot-scope="scope">
              <el-select v-model="scope.row.delegatedUserArr"
                         clearable filterable multiple
                         :disabled="operationType === 'check'"
                         placeholder="请选择" size="small" style="width: 100%;">
                <el-option v-for="item in responsibleOptions" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="80" align="center" v-if="operationType !== 'check'">
            <template slot-scope="scope">
              <el-button style="color: #f56c6c" type="text" @click="deleteRow(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button v-if="operationType !== 'check'" :loading="submitFormLoading" type="primary" @click="submitForm">确认</el-button>
        <el-button v-if="operationType === 'check'" :loading="submitFormLoading" type="primary"
                   @click="checkStatus(0)">不通过</el-button>
        <el-button v-if="operationType === 'check'" :loading="submitFormLoading" type="primary"
                   @click="checkStatus(1)">通过</el-button>
      </span>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="addEquipDia" title="添加设备"
               width="50%">
      <div style="display: flex;align-items: center;">
        <span style="width: 90px;margin-left: 10px">被授权人:</span>
        <el-select v-model="delegatedUser" clearable filterable multiple
                   placeholder="请选择" size="small" style="width: 100%;">
          <el-option v-for="item in responsibleOptions" :key="item.name" :label="item.name" :value="item.name">
          </el-option>
        </el-select>
      </div>
      <el-table ref="multipleTable" :data="equipOptions" tooltip-effect="dark" height="500" style="width: 100%"
                :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }" border
                @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="设备名称" prop="label" width="190"></el-table-column>
        <el-table-column prop="value" label="设备编号" width="130"></el-table-column>
        <el-table-column prop="storagePoint" label="归属实验室"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addEquipDia = false">取 消</el-button>
        <el-button :loading="submitFormLoading" type="primary" @click="changeMachineName">确认</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="notificationDia" title="提交审核" width="30%" @close="closeNotificationDia">
      <span style="margin-top: 10px;display: inline-block">
        请选择审核人:
        <el-select v-model="auditId" clearable filterable size="small" style="width: 90%;">
          <el-option v-for="item in responsibleOptions" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="notificationLoading" @click="closeNotificationDia">取 消</el-button>
        <el-button :loading="notificationLoading" type="primary" @click="notification">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import limsTable from "@/components/Table/lims-table.vue";
import {
  addImpower,
  deleteImpower, deviceScopeSearch, getImpowerDetail, reviewImpowerStatus,
  selectDeviceImpowerByPage, submitReviewImpowerStatus, updateImpower
} from "@/api/cnas/resourceDemand/device";
import {exportQualityMonitorDetail} from "@/api/cnas/process/ensureResults/qualityMonitor";
import {selectUserCondition} from "@/api/system/user";
import {mapGetters} from "vuex";
 
export default {
  name: '',
  // import 引入的组件需要注入到对象中才能使用
  components: {limsTable},
  props: {
    clickNodeVal: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    // 这里存放数据
    return {
      outLoading: false,
      tableData: [],
      tableLoading: false,
      page: {
        total: 0,
        size: 20,
        current: 1
      },
      column: [
        { label: '计划年份', prop: 'impowerYear' },
        { label: '编制人', prop: 'compiler' },
        { label: '编制时间', prop: 'datePreparation' },
        { label: '授权人', prop: 'audit' },
        { label: '授权日期', prop: 'auditDate' },
        {
          dataType: 'tag',
          label: '授权状态',
          prop: 'status',
          formatData: (params) => {
            if (params === 1) {
              return '已授权'
            } else if (params == 0) {
              return '未授权'
            } else {
              return null
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params === 0) {
              return 'danger'
            } else {
              return null
            }
          }
        },
        {
          dataType: 'action',
          label: '操作',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.openDia('edit', row);
              },
              disabled: (row) => {
                return row.status === 1;
              },
            },
            {
              name: '审核通知',
              type: 'text',
              clickFun: (row) => {
                this.tellApprove(row.impowerId);
              },
              disabled: (row) => {
                return row.status === 1;
              },
            },
            {
              name: '审核',
              type: 'text',
              clickFun: (row) => {
                this.openDia('check', row);
              },
              disabled: (row) => {
                return row.status === 1 || this.userId !== row.auditId;
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.handleDeleteClick(row);
              },
              disabled: (row) => {
                return row.status === 1;
              },
            },
          ]
        }
      ],
      responsibleOptions: [],
      operationType: '',
      usageTableDia: false,
      deviceImpowerDetails: [],
      submitFormLoading: false,
      addEquipDia: false,
      equipOptions: [],
      selectionRows: [],
      form: {
        impowerYear: ''
      },
      delegatedUser: [],
      impowerId: '',
      notificationDia: false,
      auditId: '',
      notificationLoading: false,
    };
  },
  mounted() {
    this.refreshTableList()
  },
  // 方法集合
  methods: {
    // 点击刷新
    refreshTableList () {
      this.page.current = 1;
      this.getTableList()
    },
    // 分页切换
    pagination(page) {
      this.page.size = page.limit
      this.getTableList()
    },
    getTableList () {
      this.tableLoading = true
      selectDeviceImpowerByPage({
        ...this.page
      }).then(res => {
        this.tableLoading = false
        this.tableData = res.data.records
        this.page.total = res.data.total
      }).catch(err => {
        this.tableLoading = false
      })
    },
    // 打开提交批准弹框
    tellApprove(impowerId) {
      this.getUserList()
      this.notificationDia = true
      this.impowerId = impowerId
    },
    // 提交批准通知
    notification() {
      if (!this.auditId) {
        this.$message.warning('请选择审核人')
        return
      }
      this.notificationLoading = true
      submitReviewImpowerStatus({
        auditId: this.auditId,
        impowerId: this.impowerId,
      }).then(res => {
        this.notificationLoading = false
        if (res.code == 200) {
          this.closeNotificationDia()
          this.refreshTableList()
        }
      }).catch(err => {
        this.notificationLoading = false
      })
    },
    // 关闭提交批准弹框
    closeNotificationDia() {
      this.notificationDia = false
      this.auditId = ''
    },
    // 打开操作弹框
    openDia (type, row) {
      this.operationType = type
      this.usageTableDia = true
      this.form = {
        impowerYear: '',
        deviceImpowerDetails: [],
      }
      this.deviceImpowerDetails = []
      if (row) {
        this.impowerId = row.impowerId
        getImpowerDetail({ impowerId: this.impowerId }).then(res => {
          if (res.code === 200) {
            this.form = res.data
            this.deviceImpowerDetails = this.form.deviceImpowerDetails
            this.deviceImpowerDetails.forEach(item => {
              this.$set(item, 'delegatedUserArr', item.delegatedUser.split(','))
            })
          }
        }).catch(error => {
          console.error(error)
        })
      }
      this.getEquipOptions()
      this.getUserList()
    },
    closeDialog () {
      this.usageTableDia = false
      this.getTableList()
    },
    // 添加设备
    addTableRow() {
      this.addEquipDia = true
      this.delegatedUser = this.responsibleOptions.map((item) => item.name);
      this.getEquipOptions()
    },
    // 删除表格行
    deleteRow(index) {
      this.deviceImpowerDetails.splice(index, 1)
    },
    // 提交新增和修改
    submitForm() {
      this.form.deviceImpowerDetails = this.HaveJson(this.deviceImpowerDetails)
      this.form.deviceImpowerDetails.forEach((item) => {
        item.delegatedUser = item.delegatedUserArr.join(',')
      })
      this.submitFormLoading = true
      if (this.operationType === 'add') {
        addImpower(this.form).then(res => {
          if (res.code == 200) {
            this.$message.success('新增成功')
            this.usageTableDia = false
            this.refreshTableList()
          }
          this.submitFormLoading = false
        }).catch(err => {
          this.submitFormLoading = false
        })
      } else {
        updateImpower(this.form).then(res => {
          if (res.code == 200) {
            this.$message.success('修改成功')
            this.usageTableDia = false
            this.refreshTableList()
          }
          this.submitFormLoading = false
        }).catch(err => {
          this.submitFormLoading = false
        })
      }
    },
    // 提交审核
    checkStatus(status) {
      const params = {
        status: status,
        impowerId: this.impowerId
      }
      reviewImpowerStatus(params).then(res => {
        if (res.code == 200) {
          this.$message.success('审核成功')
          this.usageTableDia = false
          this.refreshTableList()
        }
        this.submitFormLoading = false
      }).catch(err => {
        this.submitFormLoading = false
      })
    },
    handleSelectionChange(selection) {
      this.selectionRows = selection
    },
    // 赋值仪器编号
    changeMachineName() {
      this.deviceMaintenancePlanDetails = []
      this.selectionRows.map(val => {
        this.deviceImpowerDetails.push({ deviceId: val.id, deviceName: val.label, managementNumber: val.value, specificationModel: val.specificationModel, delegatedUserArr: this.delegatedUser })
      })
      this.addEquipDia = false
    },
    // 获取所有设备
    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.storagePoint = m.storagePoint
            return m
          })
        }
      }).catch(error => {
        console.error(error)
      })
    },
    openHandleOut (row) {
      exportQualityMonitorDetail({ impowerId: row.impowerId }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/msword' });
        this.$download.saveAs(blob, row.monitorName + '.docx')
      })
    },
    handleDeleteClick(row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteImpower({ impowerId: row.impowerId }).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.refreshTableList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 获取负责人信息接口
    getUserList() {
      selectUserCondition({type: 2}).then(res => {
        if (res.code == 200) {
          this.responsibleOptions = res.data
        }
      })
    },
  },
  watch: {
    // 监听点击el-tree的数据,进行数据刷新
    clickNodeVal(newVal) {
      if (newVal.value) {
        this.refreshTableList();
      }
    },
  },
  computed: {
    ...mapGetters(["userId"]),
  },
};
</script>
 
<style scoped>
.search {
  height: 46px;
  text-align: right;
  margin-top: 10px;
}
</style>