吴羡
5 小时以前 a1faa94fbf85553f22da934a1abc745d89dd8667
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
<template>
  <!--  设备保养计划-->
  <div>
    <div style="margin: 10px 0 14px;">
      <div class="plan-top">
        <div class="plan-top-left">
          <span class="title" style="margin-bottom: 0;">{{ planInfo.planName || (planYear + '年度设备保养计划') }}</span>
          <el-select v-model="planYear" size="small" style="width: 110px; margin-left: 16px;" @change="handleYearChange">
            <el-option v-for="y in yearOptions" :key="y" :label="y" :value="y"></el-option>
          </el-select>
        </div>
        <div>
          <el-button size="small" type="primary" @click="loadPlan">刷新</el-button>
          <el-button size="small" type="primary" :loading="outLoading" @click="handleDownOne">导出</el-button>
        </div>
      </div>
      <div class="plan-info-bar">
        <span>编制人:{{ planInfo.compiler || '—' }}</span>
        <span>编制日期:{{ planInfo.datePreparationStr || '—' }}</span>
        <span v-if="planInfo.status === 1">审核状态:<el-tag type="success">通 过</el-tag></span>
        <span v-else-if="planInfo.status === 0">审核状态:<el-tag type="danger">不通过</el-tag></span>
        <span v-if="planInfo.auditRemark">审核信息:{{ planInfo.auditRemark }}</span>
        <span v-if="isAudited && planInfo.audit">审核人:{{ planInfo.audit }}</span>
        <span v-if="isAudited && planInfo.auditDateStr">审核时间:{{ planInfo.auditDateStr }}</span>
      </div>
    </div>
    <div class="search">
      <div>
        <el-form :model="searchForm" ref="searchForm" size="small" :inline="true">
          <el-form-item label="设备名称" prop="deviceName">
            <el-input v-model="searchForm.deviceName" clearable @keyup.enter="handleQuery"
              size="small"></el-input>
          </el-form-item>
          <el-form-item label="设备编号" prop="deviceNumber">
            <el-input v-model="searchForm.deviceNumber" @keyup.enter="handleQuery" clearable
              size="small"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="handleQuery">查询</el-button>
            <el-button size="small" @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div>
      <el-table ref="yearTable" v-loading="tableLoading" :data="tableData" border
        :row-class-name="tableRowClassName" :height="'calc(100vh - 29em)'" style="width: 100%;">
        <el-table-column align="center" header-align="center" label="序号" prop="prop" type="index"
          width="70"></el-table-column>
        <el-table-column label="设备名称及型号" min-width="180" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.deviceName }}{{ scope.row.specificationModel ? ' ' + scope.row.specificationModel : '' }}
          </template>
        </el-table-column>
        <el-table-column label="设备编号" min-width="140" prop="deviceNumber"></el-table-column>
        <el-table-column label="归属实验室" min-width="120" prop="storagePoint"></el-table-column>
        <el-table-column label="保养关键部位" min-width="150" prop="maintenanceSite" show-overflow-tooltip></el-table-column>
        <el-table-column label="保养内容" min-width="180" prop="maintenanceContent" show-overflow-tooltip></el-table-column>
        <el-table-column label="保养周期" min-width="100" prop="maintenanceIntervals"></el-table-column>
        <el-table-column label="计划保养时间" min-width="130" prop="maintenanceDate"
          :formatter="formatDateCell"></el-table-column>
        <el-table-column align="center" fixed="right" label="操作" min-width="160">
          <template #default="scope">
            <el-button size="small" link type="primary"
              @click="handleForm('edit', scope.row)">编辑</el-button>
            <el-button size="small" link type="primary" @click="handleForm('view', scope.row)">查看</el-button>
            <el-button size="small" link type="danger"
              @click="deleteRow(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="pagination1.current" :page-size="pagination1.size"
        :page-sizes="[10, 20, 30, 50, 100]" background :total="pagination1.total"
        layout="->,total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1">
      </el-pagination>
    </div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible"
      title="设备保养计划明细" width="60%" @close="resetForm">
      <el-form ref="modelForm" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备名称:">
              <el-input v-model="form.deviceName" disabled size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备编号:">
              <el-input v-model="form.deviceNumber" disabled size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属实验室:">
              <el-input v-model="form.storagePoint" disabled size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保养周期:">
              <el-input v-model="form.maintenanceIntervals" :disabled="operationType === 'view'" clearable
                size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="保养关键部位:">
              <el-input v-model="form.maintenanceSite" :disabled="operationType === 'view'" clearable size="small"
                type="textarea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="保养内容:">
              <el-input v-model="form.maintenanceContent" :disabled="operationType === 'view'" clearable size="small"
                type="textarea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划保养时间:" prop="maintenanceDate">
              <el-date-picker v-model="form.maintenanceDate" :disabled="operationType === 'view'" clearable
                format="YYYY-MM-DD" placeholder="选择日期" size="small" style="width:100%" type="date"
                value-format="YYYY-MM-DD"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer><span class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button :loading="submitFormLoading" type="primary" @click="submitForm"
          v-if="operationType !== 'view'">确 认</el-button>
      </span></template>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  selectDeviceMaintenancePlanByPage,
  getMaintenancePlanByYear,
  pageMaintenancePlanDetail,
  updateMaintenancePlanDetail,
  deleteMaintenancePlanDetail,
  exportDeviceMaintenancePlan,
} from '@/api/cnas/resourceDemand/device.js'
import { formatDateOnly } from './dateFormat'
import { saveBlobOrShowError } from '@/utils/saveBlob'
export default {
  name: "equipment-maintenance-plan",
  props: {
    clickNodeVal: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      planYear: '',
      yearOptions: [],
      planInfo: {},
      searchForm: {
        deviceName: '',
        deviceNumber: '',
      },
      tableData: [],
      tableLoading: false,
      pagination1: {
        size: 10,
        current: 1,
        total: 0,
      },
      dialogVisible: false,
      operationType: '',
      form: {},
      rules: {
        maintenanceDate: [{ required: true, message: '请选择计划保养时间', trigger: 'change' }],
      },
      submitFormLoading: false,
      outLoading: false,
    }
  },
  mounted() {
    this.loadYearOptions()
  },
  methods: {
    // 年份下拉选项:已有计划年份 + 当前年份
    loadYearOptions() {
      const currentYear = String(new Date().getFullYear())
      const finish = (years) => {
        if (years.indexOf(currentYear) === -1) {
          years.push(currentYear)
        }
        this.yearOptions = [...new Set(years)].sort((a, b) => b.localeCompare(a))
        this.planYear = currentYear
        this.loadPlan()
      }
      selectDeviceMaintenancePlanByPage({
        current: 1,
        size: 99,
      }).then(res => {
        let years = []
        if (res.code == 200) {
          years = (res.data.records || []).map(r => r.planYear).filter(Boolean)
        }
        finish(years)
      }).catch(() => {
        finish([])
      })
    },
    // 切换年份
    handleYearChange() {
      this.pagination1.current = 1
      this.loadPlan()
    },
    // 查询年份计划(不存在自动创建并补全到点明细),随后刷新明细
    loadPlan() {
      getMaintenancePlanByYear({ planYear: this.planYear }).then(res => {
        if (res.code == 200) {
          this.planInfo = res.data || {}
        }
        this.getTableList()
      }).catch(() => {
        this.planInfo = {}
        this.tableData = []
        this.pagination1.total = 0
        this.tableLoading = false
      })
    },
    // 查询条件变化后从第一页开始查
    handleQuery() {
      this.pagination1.current = 1
      this.getTableList()
    },
    // 明细-查询
    getTableList() {
      if (!this.planInfo.maintenancePlanId) {
        return
      }
      this.tableLoading = true
      pageMaintenancePlanDetail({
        current: this.pagination1.current,
        size: this.pagination1.size,
        planId: this.planInfo.maintenancePlanId,
        deviceName: this.searchForm.deviceName,
        deviceNumber: this.searchForm.deviceNumber,
      }).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.records
          this.pagination1.total = res.data.total
        }
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 到点需保养的行标红
    formatDateCell(row, column, cellValue) {
      return formatDateOnly(cellValue)
    },
    tableRowClassName({ row }) {
      return row.redFlag === 1 ? 'red-row' : ''
    },
    reset() {
      this.searchForm = {
        deviceName: '',
        deviceNumber: '',
      }
      this.pagination1.current = 1
      this.getTableList()
    },
    // 分页
    handleSizeChange1(val) {
      this.pagination1.size = val
      this.getTableList()
    },
    // 分页
    handleCurrentChange1(val) {
      this.pagination1.current = val
      this.getTableList()
    },
    // 打开明细弹框
    handleForm(type, row) {
      this.operationType = type
      this.form = this.HaveJson(row)
      this.dialogVisible = true
      this.$nextTick(() => {
        if (this.$refs.modelForm) {
          this.$refs.modelForm.clearValidate()
        }
      })
    },
    // 提交表单(只回传明细表字段)
    submitForm() {
      this.$refs.modelForm.validate(valid => {
        if (valid) {
          this.submitFormLoading = true
          const payload = {
            maintenancePlanDetailId: this.form.maintenancePlanDetailId,
            maintenancePlanId: this.form.maintenancePlanId,
            deviceId: this.form.deviceId,
            maintenanceSite: this.form.maintenanceSite,
            maintenanceContent: this.form.maintenanceContent,
            maintenanceIntervals: this.form.maintenanceIntervals,
            maintenanceDate: this.form.maintenanceDate,
          }
          updateMaintenancePlanDetail(payload).then(res => {
            if (res.code == 200) {
              this.$message.success('修改成功')
              this.dialogVisible = false
              this.getTableList()
            }
            this.submitFormLoading = false
          }).catch(() => {
            this.submitFormLoading = false
          })
        }
      })
    },
    resetForm() {
      this.dialogVisible = false
    },
    // 明细-删除
    deleteRow(row) {
      this.$confirm('此操作将永久删除该条明细, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteMaintenancePlanDetail({ maintenancePlanDetailId: row.maintenancePlanDetailId }).then(() => {
          this.$message.success('删除成功!');
          this.getTableList()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 导出
    handleDownOne() {
      this.outLoading = true
      exportDeviceMaintenancePlan({ maintenancePlanId: this.planInfo.maintenancePlanId }).then(res => {
        this.outLoading = false
        saveBlobOrShowError(res, '设备保养计划表.docx', 'application/msword')
      }).catch(() => {
        this.outLoading = false
      })
    }
  },
  computed: {
    // 是否已完成审核(通过/不通过)
    isAudited() {
      return this.planInfo.status === 0 || this.planInfo.status === 1;
    },
  },
}
</script>
 
<style scoped>
.title {
  position: relative;
  font-size: 16px;
  color: var(--lims-text);
  font-weight: 400;
  padding-left: 10px;
  margin-bottom: 10px;
}
 
.title::before {
  position: absolute;
  left: 0;
  top: 4px;
  content: '';
  width: 4px;
  height: 16px;
  background-color: var(--el-color-primary);
  border-radius: 2px;
}
 
.plan-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
 
.plan-top-left {
  display: flex;
  align-items: center;
}
 
.plan-info-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 32px;
  background: #f5f7fa;
  border-radius: 4px;
  padding: 10px 16px;
  margin-top: 14px;
  font-size: 14px;
  color: #606266;
}
 
.search {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}
 
:deep(.red-row td) {
  background: #ffcccc !important;
}
</style>