spring
2025-03-03 840de9662167b1d7758208b9c88adda806ed8fec
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
<template>
  <div>
    <div class="header">
      <div>照度记录</div>
      <div>
        <el-button size="small" type="primary" @click="clickAdd">新 增</el-button>
      </div>
    </div>
    <el-table :data="tableData" height="calc(100vh - 18em)" style="width: 100%">
      <el-table-column label="序号" type="index" width="120">
        <template v-slot="scope">
          <span>{{ (search.current - 1) * search.size + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结论" min-width="180" prop="conclusion"></el-table-column>
      <el-table-column label="测试日期" min-width="180" prop="testDate" width="testDate"></el-table-column>
      <el-table-column label="检测者" min-width="180" prop="testerUser"></el-table-column>
      <el-table-column label="核查人" min-width="180" prop="checkerUser"></el-table-column>
      <el-table-column label="设备名称" min-width="180" prop="deviceName"></el-table-column>
      <el-table-column label="设备编号" min-width="180" prop="managementNumber"></el-table-column>
      <el-table-column label="校准日期" min-width="180" prop="lastCalibrationDate"></el-table-column>
      <el-table-column label="下次校准日期" min-width="180" prop="nextCalibrationDate"></el-table-column>
      <el-table-column label="创建时间" min-width="180" prop="createTime"></el-table-column>
      <el-table-column fixed="right" label="操作" min-width="140">
        <template v-slot="scope">
          <el-button size="small" type="text" @click="downLoadPost(scope.row)">导出</el-button>
          <el-button size="small" type="text" @click="edit(scope.row)">编辑</el-button>
          <el-button size="small" type="text" @click="deleteRowFun(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="1" :page-size="search.size" :page-sizes="[10, 20, 30, 50, 100]" :total="search.total"
      layout="->,total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
    <el-dialog :visible.sync="dialogVisible" title="新增" width="50%" @open="openDialog">
      <div style="height: 50vh; overflow-y: auto">
        <el-form ref="form" :model="form" label-width="120px">
          <el-row>
            <el-col :span="12">
              <el-form-item :rules="[{ required: true, message: '请输入测试地点', trigger: 'change' }]" label="测试日期"
                prop="testDate">
                <el-date-picker v-model="form.testDate" 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-col :span="12">
              <el-form-item :rules="[{ required: true, message: '请输入设备名称', trigger: 'change' }]" label="设备名称"
                prop="deviceId">
                <el-select v-model="form.deviceId" class="table_input" clearable filterable placeholder="设备名称"
                  size="small" @change="getCalibrationDateFun">
                  <el-option v-for="item in equipOptions" :key="item.id" :label="item.deviceName" :value="item.id">
                    {{ item.deviceName + item.managementNumber }}
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备编号">
                <el-input v-model="form.managementNumber" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最近校准日期">
                <el-input v-model="form.lastCalibrationDate" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="下次校准日期">
                <el-input v-model="form.nextCalibrationDate" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检测者" prop="recipientUser">
                <el-select v-model="form.testerId" clearable filterable 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>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="核查人" prop="recipientUser">
                <el-select v-model="form.checkerId" clearable filterable 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>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="结论">
                <el-input v-model="form.conclusion" :rows="2" placeholder="请输入内容" type="textarea">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div>
            <div style="display: flex; justify-content: flex-end; margin-bottom: 0.5em">
              <el-button size="small" type="primary" @click="feMeasuredQuantityListAdd">新增</el-button>
            </div>
            <div>
              <el-table :data="form.illuminationDetectionAreaList" height="40vh" style="width: 100%; margin: auto">
                <el-table-column label="序号" type="index" width="80"></el-table-column>
                <el-table-column align="center" label="检测区域名称" min-width="180" prop="detectionAreaLabel">
                  <template #default="{ row }">
                    <el-input v-model="row.detectionAreaLabel" :rows="1" type="textarea"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="检测值" min-width="300" prop="name">
                  <template>
                    <el-table-column align="center" label="第一次" min-width="100" prop="valueOne">
                      <template #default="{ row }">
                        <el-input v-model="row.valueOne" :rows="1" @blur="getAverage(row)"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" label="第二次" min-width="100" prop="valueTwo">
                      <template #default="{ row }">
                        <el-input v-model="row.valueTwo" :rows="1" @blur="getAverage(row)"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" label="第三次" min-width="100" prop="valueThree">
                      <template #default="{ row }">
                        <el-input v-model="row.valueThree" :rows="1" @blur="getAverage(row)"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" label="平均值" min-width="100" prop="average">
                      <template #default="{ row }">
                        <el-input v-model="row.average" :rows="1"></el-input>
                      </template>
                    </el-table-column>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" min-width="180" prop="detectionAreaLabel">
                  <template #default="{ row }">
                    <el-input v-model="row.remark" :rows="1" type="textarea"></el-input>
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                  <template slot-scope="scope">
                    <el-button size="small" type="text" @click="feMeasuredQuantityListDelete(scope.row, scope.$index)">
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="submitLoading" @click="addPowerSupplyStability">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  getFeLightningProtection,
  deviceScopeSearch,
  selectUserCondition,
  treeDevice,
  addFeLightningProtection,
  deleteFeLightningProtection,
  getFeIlluminationDetectionArea,
  deleteFeIlluminationDetectionArea,
  exportFeIllumination
} from '@/api/cnas/resourceDemand/facilitiesEnvironment/facilitiesAndEnvironment'
 
export default {
  data() {
    return {
      search: {
        size: 10,
        current: 1,
        total: 0
      },
      tableData: [],
      dialogVisible: false,
      submitLoading: false,
      form: {
        testDate: '',
        deviceId: '',
        managementNumber: '',
        lastCalibrationDate: '',
        nextCalibrationDate: '',
        testerId: '',
        checkerId: '',
        conclusion: '',
        illuminationDetectionAreaList: []
      },
      cascaderList: [],
      responsibleOptions: [],
      equipOptions: [],
    }
  },
  mounted() {
    this.initData()
  },
  watch: {
    dialogVisible(newVal) {
      if (!newVal) {
        this.form = {
          deviceId: null,
          illuminationDetectionAreaList: []
        }
      }
    }
  },
  methods: {
    getAverage(row) {
      if (row.valueOne && row.valueTwo && row.valueThree) {
        if (!isNaN(row.valueOne) && !isNaN(row.valueTwo) && !isNaN(row.valueThree)) {
          const avg = Number(row.valueOne) + Number(row.valueTwo) + Number(row.valueThree)
          console.log(avg)
          row.average = Math.round(avg / 3);
        } else {
          this.$message.warning("必须为数字!")
        }
      }
    },
    edit(row) {
      getFeIlluminationDetectionArea({ intensityIlluminationId: row.intensityIlluminationId }).then(res => {
        this.form = { ...row }
        this.form.illuminationDetectionAreaList = res.data;
        this.dialogVisible = true
      });
    },
    initData() {
      getFeLightningProtection({ ...this.search }).then(res => {
        if (res.code === 200) {
          this.tableData = res.data.records;
          this.search.total = res.data.total;
        }
      });
    },
    handleSizeChange(val) {
      this.search.size = val;
      this.initData();
    },
    handleCurrentChange(val) {
      this.search.current = val;
      this.initData();
    },
    deleteRowFun(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteFeLightningProtection({ intensityIlluminationId: row.intensityIlluminationId }).then(res => {
          this.$message.success('删除成功!')
          this.initData()
        })
      })
    },
    feMeasuredQuantityListDelete(row, index) {
      if (row.detectionAreaId) {
        deleteFeIlluminationDetectionArea({ detectionAreaId: row.detectionAreaId }).then(res => {
          if (res.code === 200) {
            this.form.illuminationDetectionAreaList.splice(index, 1)
            this.$message.success('删除成功!')
          }
        })
      } else {
        this.form.illuminationDetectionAreaList.splice(index, 1)
        this.$message.success('删除成功!')
      }
    },
    openDialog() {
      treeDevice().then(res => {
        this.cascaderList = res.data;
      });
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
      this.getUserList()
    },
    clickAdd() {
      this.dialogVisible = true
      this.getEquipOptions()
    },
    // 获取所有设备
    getEquipOptions() {
      this.equipOptions = []
      deviceScopeSearch({ status: '0' }).then(res => {
        if (res.code === 200 && res.data) {
          this.equipOptions = res.data
        }
      }).catch(error => {
        console.error(error)
      })
    },
    feMeasuredQuantityListAdd() {
      const obj = {
        detectionAreaLabel: null,
        valueOne: null,
        valueTwo: null,
        valueThree: null,
        average: null,
        remark: null,
      }
      this.form.illuminationDetectionAreaList.push(obj)
    },
    addPowerSupplyStability() {
      this.submitLoading = true
      this.$refs.form.validate((valid) => {
        if (valid) {
          addFeLightningProtection(this.form).then(res => {
            this.submitLoading = false
            if (res.code === 200) {
              this.initData()
              this.dialogVisible = false
            }
          }).catch(error => {
            this.submitLoading = false
          })
        }
      });
    },
    // 获取负责人信息接口
    getUserList() {
      selectUserCondition().then(res => {
        if (res.code == 200) {
          this.responsibleOptions = res.data
        }
      })
    },
    getCalibrationDateFun(val) {
      const index = this.equipOptions.findIndex(item => item.id === val)
      if (index > -1) {
        this.form.managementNumber = this.equipOptions[index].managementNumber
        this.form.lastCalibrationDate = this.equipOptions[index].lastCalibrationDate
        this.form.nextCalibrationDate = this.equipOptions[index].nextCalibrationDate
      }
    },
    // 导出
    downLoadPost(row) {
      exportFeIllumination({ intensityIlluminationId: row.intensityIlluminationId }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/msword' });
        this.$download.saveAs(blob, '照度记录.docx')
      })
    },
  }
}
</script>
 
<style scoped>
.header {
  height: 3em;
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>