licp
2024-12-24 e4bb381c896015c4b87faa002ba6875c06a2fd16
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
<template>
  <div>
    <div class="header">
      <div>防雷检测</div>
      <div>
        <el-button type="primary" size="small" @click="clickAdd">导 入</el-button>
        <el-button type="primary" size="small" @click="downLoadPost">导 出</el-button>
      </div>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      height="calc(100vh - 18em)">
      <el-table-column type="index" label="序号" width="120">
        <template v-slot="scope">
          <span>{{ (search.current - 1) * search.size + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fileName"
        label="原文件名"
        min-width="180">
      </el-table-column>
      <el-table-column
        prop="detectionDate"
        label="检测日期"
        min-width="180">
      </el-table-column>
      <el-table-column
        prop="termValidity"
        min-width="180"
        label="有效期">
      </el-table-column>
      <el-table-column
        prop="detectionUnit"
        min-width="180"
        label="检测单位">
      </el-table-column>
      <el-table-column fixed="right" label="操作" min-width="100">
        <template v-slot="scope">
          <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="deleteRowFun(scope.row)">删除</el-button>
          <el-button type="text" size="small" @click="download(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
      title="新 增"
      :visible.sync="dialogVisible"
      width="50%">
      <div style="height: 50vh;">
        <el-form ref="form" :model="form" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="检测日期" prop="detectionDate"
                            :rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  style="width: 100%"
                  size="small"
                  v-model="form.detectionDate"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="有效期" prop="termValidity"
                            :rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  style="width: 100%"
                  size="small"
                  v-model="form.termValidity"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="检测单位" prop="detectionUnit"
                            :rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
                <el-input v-model="form.detectionUnit" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检测单位" >
                <el-upload
                  class="upload-demo"
                  drag
                  action="#"
                  :on-remove="handleRemove"
                  :http-request="httpRequest"
                  :file-list="form.fileList"
                  :on-exceed="handleExceed"
                  :limit="1"
                  multiple>
                  <i class="el-icon-upload"></i>
                  <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="addImport">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
 
<script>
 
export default {
  data() {
    return {
      search: {
        size: 20,
        current: 1,
        total: 0
      },
      tableData: [],
      dialogVisible: false,
      form: {
        fileList: [],
        fileData: []
      },
    }
  },
  mounted() {
    this.initData()
  },
  watch: {
    dialogVisible(newVal) {
      if (!newVal) {
        this.form = {
          fileList: [],
          fileData: []
        }
      }
    }
  },
  methods: {
    // 导出
    downLoadPost() {
      this.$axios.get(this.$api.facilitiesAndEnvironment.exportOfLightningProtectionDetection,{responseType: "blob"}).then(res => {
        this.outLoading = false
        const blob = new Blob([res],{ type: 'application/msword' });
        //将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 = '防雷检测导出' + '.xlsx';
              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 = '防雷检测导出' + '.xlsx';
            link.click();
            this.$message.success('导出成功')
          }
        }
      })
    },
    initData() {
      this.$axios.get(this.$api.facilitiesAndEnvironment.getLightningProtectionDetection + '?size=' + this.search.size + '&current=' + this.search.current).then(res => {
        if (res.code === 201) return;
        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();
    },
    clickAdd() {
      this.dialogVisible = true
    },
    // 文件数量过多时提醒
    handleExceed() {
      this.$message({type: 'error', message: '最多支持1个附件上传'})
    },
    // 覆盖默认的上传行为,可以自定义上传的实现,将上传的文件依次添加到fileList数组中,支持多个文件
    httpRequest(option) {
      this.form.fileData.push(option)
    },
    addImport() {
      console.log(this.form)
      this.$refs.form.validate((valid) => {
        if (valid) {
          let params = new FormData()
          if (this.form.lightningProtectionId) {
            params.append("lightningProtectionId", this.form.lightningProtectionId)
          }
          params.append("termValidity", this.form.termValidity)
          params.append("detectionUnit", this.form.detectionUnit)
          params.append("detectionDate", this.form.detectionDate)
          if (this.form.fileData.length > 0) {
            params.append("file", this.form.fileData[0].file)
          }
          this.$axios.post(this.$api.facilitiesAndEnvironment.addLightningProtectionDetection, params, {
            headers: {'Content-Type': 'multipart/form-data;'},
            noQs: true
          }).then(res => {
            if (res.code === 201) return;
            this.dialogVisible = false
            this.initData()
          });
        }
      });
    },
    edit(row) {
      this.dialogVisible = true
      this.form = {...row}
      this.form.fileList = []
      this.form.fileData = []
      this.form.fileList.push({name: row.systemFileName, url: "123434"})
      console.log(this.form)
    },
    deleteRowFun(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete(this.$api.facilitiesAndEnvironment.deleteLightningProtectionDetection + '?lightningProtectionId=' + row.lightningProtectionId).then(res => {
          this.$message.success('删除成功!')
          this.initData()
        })
      })
    },
    handleRemove(file) {
      this.$axios.delete(this.$api.personnel.deleteCNASFile + "?fileName=" + file.name).then(res => {
        if (res.code === 201) return;
        this.$message.success('删除成功!')
        let index = this.form.fileList.indexOf(fileName)
        if (index != -1) {
          this.successFileList.splice(index, 1)
        }
      })
    },
    download(row) {
      let url = '';
 
      // fileDownload.downloadIamge(url, row.fileName)
      url = this.javaApi + 'img/' + row.systemFileName
      const link = document.createElement('a');
      link.href = url;
      link.download = row.fileName;
      link.click();
    }
  }
}
</script>
 
<style scoped>
.header {
  height: 3em;
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>