spring
2025-02-15 237f95b05e0f122ee9ec7beaf82ba366a8b220ed
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<template>
  <div>
    <div>
      <div style="margin: 10px 0;text-align: right">
        <el-button size="small" type="primary" @click="handleForm('add')"
          >新增</el-button
        >
      </div>
      <div>
        <el-table
          ref="yearTable"
          v-loading="yearTableDetailDataLoading"
          :data="yearTableDetailData"
          height="calc(100vh - 18em)"
          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="150"
            prop="arrivalDate"
          ></el-table-column>
          <el-table-column
            label="金额"
            min-width="100"
            prop="goldAmount"
          ></el-table-column>
          <el-table-column
            label="维修单位"
            min-width="150"
            prop="maintenanceunit"
          ></el-table-column>
          <!-- 操作按钮 -->
          <el-table-column align="center" label="操作" min-width="180">
            <template slot-scope="scope">
              <el-button
                size="small"
                type="text"
                @click="handleForm('edit', scope.row.acceptanceId)"
                >编辑</el-button
              >
              <el-button
                size="small"
                type="text"
                @click="handleForm('view', scope.row.acceptanceId)"
                >查看</el-button
              >
              <el-button size="small" type="text" @click="record(scope.row)"
                >附件</el-button
              >
              <el-button
                size="small"
                type="text"
                @click="handleDownOne(scope.row.acceptanceId)"
                >导出</el-button
              >
              <el-button
                size="small"
                style="color: #f56c6c"
                type="text"
                @click="deleteFun(scope.row.acceptanceId)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="1"
          :page-size="pagination1.size"
          :page-sizes="[10, 20, 30, 50, 100]"
          :total="pagination1.total"
          layout="->,total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"
        >
        </el-pagination>
      </div>
    </div>
    <acceptance-form
      v-if="applicationForm"
      ref="applicationForm"
      @closeDialog="closeDialog"
    ></acceptance-form>
    <!--上传报告-->
    <el-dialog
      :visible.sync="filesDialogVisible"
      title="附件"
      width="80%"
      @closed="closeFilesLook"
    >
      <div style="display: flex;justify-content: space-between;">
        <el-upload
          ref="upload"
          :action="fileAction"
          :auto-upload="true"
          :before-upload="fileBeforeUpload"
          :data="{ acceptanceId: acceptanceId }"
          :headers="headers"
          :on-error="onError"
          :on-success="handleSuccessUp"
          :show-file-list="false"
          accept=".jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar"
          style="width: 80px !important;"
        >
          <el-button size="small" style="height: 38px" type="primary"
            >附件上传</el-button
          >
        </el-upload>
      </div>
      <div>
        <ZTTable
          ref="yearTable"
          :column="columnData"
          :height="'calc(100vh - 30em)'"
          :highlightCurrentRow="true"
          :table-data="tableData"
          :table-loading="tableLoading"
          style="margin-top: 0.5em;"
        >
        </ZTTable>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="lookDialogVisible"
      fullscreen
      title="查看附件"
      top="5vh"
      width="800px"
    >
      <filePreview
        v-if="lookDialogVisible"
        :currentFile="{}"
        :fileUrl="fileUrl"
        style="height: 90vh;overflow-y: auto;"
      />
    </el-dialog>
  </div>
</template>
 
<script>
import AcceptanceForm from "./acceptance-form.vue";
import ZTTable from "../caorui/ZTTable/index.vue";
import filePreview from "../tool/file-preview.vue";
import file from "../../util/file";
 
export default {
  name: "equipment-acceptance",
  // import 引入的组件需要注入到对象中才能使用
  components: { filePreview, ZTTable, AcceptanceForm },
  props: {
    clickNodeVal: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    // 这里存放数据
    return {
      pagination1: {
        size: 10,
        current: 1,
        total: 0
      },
      yearTableDetailDataLoading: false,
      yearTableDetailData: [],
      applicationForm: false,
      filesDialogVisible: false,
      columnData: [
        {
          label: "文件名称",
          prop: "fileName",
          minWidth: "150px"
        },
        {
          dataType: "action",
          minWidth: "100",
          label: "操作",
          fixed: "right",
          operation: [
            {
              name: "预览",
              type: "text",
              clickFun: row => {
                this.handleLook(row);
              }
            },
            {
              name: "下载",
              type: "text",
              clickFun: row => {
                this.upload(row);
              }
            },
            {
              name: "删除",
              type: "text",
              color: "#f56c6c",
              clickFun: row => {
                this.delete(row);
              }
            }
          ]
        }
      ],
      tableData: [],
      tableLoading: false,
      acceptanceId: "", // 上传附件当前行的id
      currentInfo: {},
      lookDialogVisible: false,
      fileUrl: ""
    };
  },
  mounted() {
    this.getYearTableDetailData(this.clickNodeVal.value);
  },
  // 方法集合
  methods: {
    // 查询
    getYearTableDetailData(deviceId) {
      this.yearTableDetailDataLoading = true;
      this.$axios
        .post(
          this.$api.deviceAcceptance.pageDeviceAcceptance,
          {
            page: {
              current: this.pagination1.current,
              size: this.pagination1.size
            },
            entity: {
              deviceId: deviceId
            }
          },
          {
            headers: {
              "Content-Type": "application/json"
            },
            noQs: true
          }
        )
        .then(res => {
          if (res.code == 200) {
            this.yearTableDetailData = res.data.records;
            this.pagination1.total = res.data.total;
          }
          this.yearTableDetailDataLoading = false;
        })
        .catch(err => {
          this.yearTableDetailDataLoading = false;
        });
    },
    handleForm(type, id) {
      this.applicationForm = true;
      this.$nextTick(() => {
        this.$refs.applicationForm.openDialog(
          type,
          id,
          this.clickNodeVal.value
        );
      });
    },
    closeDialog() {
      this.applicationForm = false;
      this.getYearTableDetailData(this.clickNodeVal.value);
    },
    // 打开报告弹框
    record(row) {
      this.filesDialogVisible = true;
      this.acceptanceId = row.acceptanceId;
      this.searchTableList();
    },
    // 查询附件列表
    searchTableList() {
      this.tableLoading = true;
      this.$axios
        .get(
          this.$api.deviceAcceptance.getDeviceAcceptanceFileList +
            "?acceptanceId=" +
            this.acceptanceId
        )
        .then(res => {
          this.tableLoading = false;
          if (res.code === 201) return;
          this.tableData = res.data;
        })
        .catch(err => {
          this.tableLoading = false;
          console.log("err---", err);
        });
    },
    // 查看文件
    handleLook(row) {
      this.currentInfo = row;
      this.lookDialogVisible = true;
      const state = /\.(jpg|jpeg|png|gif)$/i.test(this.currentInfo.fileUrl);
      if (state) {
        this.fileUrl = this.javaApi + "/img/" + this.currentInfo.fileUrl;
      } else {
        this.fileUrl = this.javaApi + "/word/" + this.currentInfo.fileUrl;
      }
    },
    // 下载
    upload(row) {
      let url = "";
      if (row.type == 1) {
        url = this.javaApi + "/img/" + row.fileUrl;
        file.downloadIamge(url, row.fileName);
      } else {
        url = this.javaApi + "/word/" + row.fileUrl;
        const link = document.createElement("a");
        link.href = url;
        link.download = row.fileName;
        link.click();
      }
    },
    // 删除
    delete(row) {
      this.$confirm("此操作将删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.tableLoading = true;
          this.$axios
            .get(
              this.$api.deviceAcceptance.delDeviceAcceptanceFileList +
                "?acceptanceFileId=" +
                row.acceptanceFileId
            )
            .then(res => {
              this.tableLoading = false;
              if (res.code === 201) return;
              this.$message.success("删除成功");
              this.searchTableList();
            })
            .catch(err => {
              this.tableLoading = false;
              console.log("err---", err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 上传附件
    fileBeforeUpload(file) {
      let flag = true;
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error("上传文件不超过10M");
        this.$refs.upload.clearFiles();
        flag = false;
      }
      if (!flag) {
        return Promise.reject(flag); //正确的终止
      }
    },
    onError(err, file, fileList, type) {
      this.$message.error("上传失败");
      this.$refs.upload.clearFiles();
    },
    handleSuccessUp(response) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success("上传成功");
        this.searchTableList();
      }
    },
    closeFilesLook() {
      this.filesDialogVisible = false;
    },
    // 分页
    handleSizeChange1(val) {
      this.pagination1.size = val;
      this.getYearTableDetailData(this.clickNodeVal.value);
    },
    // 分页
    handleCurrentChange1(val) {
      this.pagination1.current = val;
      this.getYearTableDetailData(this.clickNodeVal.value);
    },
    // 导出
    handleDownOne(id) {
      this.outLoading = true;
      this.$axios
        .get(
          this.$api.deviceAcceptance.exportDeviceAcceptance +
            "?acceptanceId=" +
            id,
          {
            responseType: "blob"
          }
        )
        .then(res => {
          this.outLoading = false;
          const blob = new Blob([res], { type: "application/octet-stream" });
          //将Blob 对象转换成字符串
          let reader = new FileReader();
          reader.readAsText(blob, "utf-8");
          reader.onload = () => {
            try {
              let result = JSON.parse(reader.result);
              if (result.message) {
                this.$message.error(result.message);
              } else {
                const url = URL.createObjectURL(blob);
                const link = document.createElement("a");
                link.href = url;
                link.download = "设备验收.doc";
                link.click();
                this.$message.success("导出成功");
              }
            } catch (err) {
              console.log(err);
              const url = URL.createObjectURL(blob);
              const link = document.createElement("a");
              link.href = url;
              link.download = "设备验收.doc";
              link.click();
              this.$message.success("导出成功");
            }
          };
        });
    },
    // 删除
    deleteFun(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios
            .get(
              this.$api.deviceAcceptance.delDeviceAcceptance +
                "?acceptanceId=" +
                id
            )
            .then(res => {
              this.$message.success("删除成功!");
              this.getYearTableDetailData(this.clickNodeVal.value);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },
  watch: {
    // 监听点击el-tree的数据,进行数据刷新
    clickNodeVal(newVal) {
      if (newVal.value) {
        this.getYearTableDetailData(newVal.value);
      }
    }
  },
  computed: {
    headers() {
      return {
        token: sessionStorage.getItem("token")
      };
    },
    fileAction() {
      return (
        this.javaApi + this.$api.deviceAcceptance.uploadDeviceAcceptanceFile
      );
    }
  }
};
</script>
 
<style scoped>
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.title-search {
  display: flex;
  align-items: center;
  margin: 10px 0;
}
</style>