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
<template>
  <div class="capacity-scope">
    <div>
      <div class="search">
        <div>
          <el-form :model="searchForm" ref="searchForm" size="small" :inline="true">
            <el-form-item label="客户名称" prop="unitName" v-if="tabIndex === '0'">
              <el-input v-model="searchForm.unitName" clearable size="small"></el-input>
            </el-form-item>
            <el-form-item label="文件名称" prop="fileName" v-if="tabIndex === '1'">
              <el-input v-model="searchForm1.fileName" clearable size="small"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="small" @click="searchList">查询</el-button>
              <el-button size="small" @click="resetSearchForm">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-button v-if="tabIndex === '0'" size="small" type="primary" @click="openFormDia('add')">新 增</el-button>
          <el-button v-if="tabIndex === '0'" size="small" type="primary" @click="openExportDialog">导 出</el-button>
          <el-upload v-if="tabIndex === '1'" ref='upload' :action="action" :before-upload="beforeUpload"
                     :headers="uploadHeader" :on-error="onError" :on-success="handleSuccessUp" :show-file-list="false"
                     accept='.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'>
            <el-button :loading="upLoading" size="small" type="primary">导入</el-button>
          </el-upload>
        </div>
      </div>
      <div class="table">
        <div class="table-tab">
          <el-radio-group v-model="tabIndex" @change="searchList" size="small">
            <el-radio-button value="0">客户满意度</el-radio-button>
            <el-radio-button value="1">综合分析</el-radio-button>
          </el-radio-group>
        </div>
        <div v-if="tabIndex === '0'">
          <limsTable :column="tableColumn" :height="'calc(100vh - 22em)'" :table-data="tableData"
                     :table-loading="tableLoading" @pagination="pagination"
                     :page="page">
          </limsTable>
        </div>
        <div v-if="tabIndex === '1'">
          <limsTable :column="tableColumn1" :height="'calc(100vh - 22em)'" :table-data="tableData1"
                     :table-loading="tableLoading1" @pagination="pagination0">
          </limsTable>
        </div>
      </div>
    </div>
    <el-dialog v-model="lookDialogVisible" fullscreen title="查看附件" top="5vh" width="800px">
      <filePreview v-if="lookDialogVisible" :currentFile="{}" :fileUrl="javaApi + '/word/' + currentInfo.fileUrl"
        style="height: 90vh;overflow-y: auto;" />
    </el-dialog>
    <el-dialog v-model="exportDialogVisible" title="导出年度汇总" width="360px" :close-on-click-modal="false">
      <el-form label-width="80px">
        <el-form-item label="汇总年度">
          <el-date-picker v-model="exportYear" type="year" format="YYYY年" value-format="YYYY" placeholder="选择年度"
            style="width: 100%"></el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="exportDialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="exportLoading" @click="handleExport">导 出</el-button>
      </template>
    </el-dialog>
    <FormDialog v-if="formDialog" ref="formDialog" @closeFormDia="closeFormDia"></FormDialog>
    <lims-attachment ref="attachmentDialog" title="满意度附件" name-field="unitName" id-param="clientSatisfactionId"
      upload-url="/clientSatisfaction/uploadAttachment" select-url="/clientSatisfaction/selectAttachments"
      delete-url="/clientSatisfaction/deleteAttachment" />
  </div>
</template>
 
<script>
import limsTable from "@/components/Table/lims-table.vue";
import FormDialog from './components/formDialog.vue';
import filePreview from '@/components/Preview/filePreview.vue'
import limsAttachment from '@/components/Attachment/lims-attachment.vue'
import {
  pageClientSatisfaction,
  pageAnalyseFile,
  delClientSatisfaction,
  delAnalyseFile,
  exportAnnualSummary,
} from '@/api/cnas/systemManagement/customerSatisfaction.js'
 
export default {
  name: 'CustomerSatisfaction',
  // import 引入的组件需要注入到对象中才能使用
  components: { filePreview, FormDialog, limsTable, limsAttachment },
  data() {
    // 这里存放数据
    return {
      searchForm: {
        unitName: '',
      },
      searchForm1: {
        fileName: '',
      },
      tabIndex: '0',
      tableColumn: [
        {
          label: '客户名称',
          prop: 'unitName',
          minWidth: '140'
        },
        {
          label: '地址',
          prop: 'address',
          minWidth: '150'
        },
        {
          label: '联系人',
          prop: 'contactPerson',
          minWidth: '100'
        },
        {
          label: '填表日期',
          prop: 'fillDate',
          minWidth: '100'
        },
        {
          label: '总分',
          prop: 'totalScore',
          minWidth: '80',
          formatData: (val) => (val === null || val === undefined || val === '') ? '--' : val
        },
        {
          label: '满意度评定',
          prop: 'satisfactionResult',
          minWidth: '110',
          dataType: 'tag',
          formatData: (val) => {
            if (val === null || val === undefined || val === '') {
              return '--'
            }
            return Number(val) === 0 ? '满意' : '不满意'
          },
          formatType: (val) => {
            if (val === null || val === undefined || val === '') {
              return 'info'
            }
            return Number(val) === 0 ? 'success' : 'danger'
          }
        },
        {
          label: '委托单编号',
          prop: 'entrustCode',
          minWidth: '110'
        },
        {
          label: '样品名称',
          prop: 'sampleName',
          minWidth: '120'
        },
        {
          label: '创建日期',
          prop: 'createTime',
          minWidth: '160',
        },
        {
          dataType: 'action',
          label: '操作',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.openFormDia('edit', row);
              },
            },
            {
              name: '附件',
              type: 'text',
              clickFun: (row) => {
                this.$refs.attachmentDialog.open(row);
              },
            },
            {
              name: '删除',
              type: 'text',
              color: 'var(--el-color-danger)',
              clickFun: (row) => {
                this.delPlan(row)
              }
            }
          ]
        }
      ],
      tableData: [],
      tableLoading: false,
      page: {
        size: 20,
        current: 1,
        total: 0,
      },
      tableColumn1: [
        {
          label: '附件名称',
          prop: 'fileName',
          minWidth: '100'
        },
        {
          label: '创建人',
          prop: 'userName',
          minWidth: '100'
        },
        {
          label: '创建时间',
          prop: 'createTime',
          minWidth: '100'
        },
        {
          dataType: 'action',
          label: '操作',
          operation: [
            {
              name: '预览',
              type: 'text',
              clickFun: (row) => {
                this.handleLook(row)
              }
            },
            {
              name: '下载',
              type: 'text',
              clickFun: (row) => {
                this.upload(row);
              },
            },
            {
              name: '删除',
              type: 'text',
              color: 'var(--el-color-danger)',
              clickFun: (row) => {
                this.delFile(row)
              }
            }
          ]
        }
      ],
      tableData1: [],
      tableLoading1: false,
      page1: {
        size: 20,
        current: 1,
        total: 0,
      },
      formDialog: false,
      upLoading: false,
      currentInfo: {},
      lookDialogVisible: false,
      exportDialogVisible: false,
      exportYear: String(new Date().getFullYear()),
      exportLoading: false,
    };
  },
  mounted() {
    this.searchList()
  },
  // 方法集合
  methods: {
    // 查询列表
    searchList() {
      const entity = this.tabIndex === '0' ? this.searchForm : this.searchForm1
      const page = this.tabIndex === '0' ? this.page : this.page1
      if (this.tabIndex === '0') {
        this.tableLoading = true
        pageClientSatisfaction({ ...entity, ...page }).then(res => {
          this.tableLoading = false
          this.tableData = res.data.records
          this.page.total = res.data.total
        }).catch(err => {
          console.log('err---', err);
          this.tableLoading = false
        })
      } else {
        this.tableLoading1 = true
        pageAnalyseFile({ ...entity, ...page }).then(res => {
          this.tableLoading1 = false
          this.tableData1 = res.data.records
          this.page1.total = res.data.total
        }).catch(err => {
          console.log('err---', err);
          this.tableLoading1 = false
        })
      }
    },
    openFormDia(type, row) {
      this.formDialog = true
      this.$nextTick(() => {
        this.$refs.formDialog.openDia(type, row);
      })
    },
    closeFormDia() {
      this.formDialog = false
      this.searchList()
    },
    // 打开年度汇总导出弹窗
    openExportDialog() {
      this.exportYear = String(new Date().getFullYear())
      this.exportDialogVisible = true
    },
    // 导出年度汇总 Word
    handleExport() {
      if (!this.exportYear) {
        this.$message.warning('请选择汇总年度')
        return
      }
      this.exportLoading = true
      exportAnnualSummary({ year: this.exportYear }).then(async data => {
        // 后端无数据时返回的是 JSON,需转成文本提示,避免存成坏文件
        if (data && data.type && data.type.indexOf('json') !== -1) {
          let msg = '导出失败'
          try {
            const resText = await data.text()
            const rspObj = JSON.parse(resText)
            msg = rspObj.msg || msg
          } catch (e) {
            console.log('err---', e)
          }
          this.exportLoading = false
          this.$message.error(msg)
          return
        }
        const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' })
        this.$download.saveAs(blob, '客户满意度年度汇总表_' + this.exportYear + '年.docx')
        this.exportLoading = false
        this.exportDialogVisible = false
      }).catch(err => {
        console.log('err---', err)
        this.exportLoading = false
      })
    },
    // 重置查询条件
    resetSearchForm() {
      this.searchForm.unitName = '';
      this.searchForm1.fileName = '';
      this.searchList()
    },
    // 导入流程
    beforeUpload(file) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        this.upLoading = true;
        return true;
      }
    },
    onError(err, file, fileList) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
    handleSuccessUp(response) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.searchList()
      }
    },
    // 删除客户满意度
    delPlan(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoading = true
        delClientSatisfaction({ clientSatisfactionId: row.clientSatisfactionId }).then(res => {
          this.tableLoading = false
          this.$message.success('删除成功')
          this.searchList()
        }).catch(err => {
          this.tableLoading = false
          console.log('err---', err);
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 查看文件
    handleLook(row) {
      this.currentInfo = row
      this.lookDialogVisible = true
    },
    // 下载客户福建
    upload(row) {
      this.$download.saveAs(row.fileUrl, row.fileName);
    },
    // 删除客户分析附件
    delFile(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoading = true
        delAnalyseFile({ analyseFileId: row.analyseFileId }).then(res => {
          this.tableLoading = false
          this.$message.success('删除成功')
          this.searchList()
        }).catch(err => {
          this.tableLoading = false
          console.log('err---', err);
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 分页
    pagination({ page, limit }) {
      this.page.current = page;
      this.page.size = limit;
      this.searchList();
    },
    // 分页
    pagination0({ page, limit }) {
      this.page.current = page;
      this.page.size = limit;
      this.searchList();
    },
  },
  // 用于上传文件的信息
  computed: {
    action() {
      return this.javaApi + '/clientSatisfaction/uploadAnalyseFile'
    }
  },
};
</script>
 
<style scoped>
.search {
  height: 46px;
  display: flex;
  justify-content: space-between;
}
 
.table-tab {
  margin: 0 0 20px 0;
}
</style>