gaoluyang
2025-02-19 7e35455e4bbad2edfe64bf6f56beff105c94eb94
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
<template>
  <div>
    <el-dialog title="附件查看" :visible.sync="isShow" width="80%" @closed="$emit('closeFilesLook')">
      <div style="display: flex;justify-content: space-between;">
        <ul class="tab">
          <li v-for="(m,i) in dataVisibleTitle" :key="i" :class="{active:i===dataVisibleIndex}" @click="handleDataVisibleTab(m,i)">{{m.label}}</li>
        </ul>
        <el-upload :action="action"
                   :auto-upload="true"
                   :data="{orderId: dataVisibleIndex === 0 ? filesLookInfo.enterOrderId : filesLookInfo.quarterOrderId}"
                   :on-success="handleSuccessUp" :show-file-list="false"
                   accept='.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar' :headers="headers"
                   :before-upload="beforeUpload"
                   style="width: 80px !important;"
                   :on-error="onError" ref='upload'>
          <el-button size="small" type="primary" style="height: 38px">附件上传</el-button>
        </el-upload>
      </div>
      <div v-if="filesDialogVisible">
        <lims-table :tableData="tableData" :column="column"
                    @pagination="pagination" height="500px" key="tableData"
                    :page="page" :tableLoading="tableLoading"></lims-table>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import ValueTable from "@/components/Table/value-table.vue";
import file from "@/utils/file";
import limsTable from "@/components/Table/lims-table.vue";
import {delfile, downFile, getFileList} from "@/api/business/rawMaterialOrder";
 
export default {
  name: "filesLookVisible",
  // import 引入的组件需要注入到对象中才能使用
  components: {limsTable, ValueTable},
  props: {
    filesDialogVisible: {
      type: Boolean,
      default: () => false
    },
    filesLookInfo: {
      type: Object,
      default: () => {}
    },
  },
  data() {
    // 这里存放数据
    return {
      tableData: [],
      tableLoading: false,
      column: [
        {
          dataType: 'tag',
          label: '类型',
          prop: 'type',
          formatData: (params) => {
            if (params == 1) {
              return '合格'
            } else if (params == 0) {
              return '不合格'
            } else if (params == 3) {
              return '不判定'
            } else {
              return ''
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 0) {
              return 'danger'
            } else if (params == 3) {
              return ''
            }  else {
              return ''
            }
          }
        },
        {label: '附件名称', prop: 'fileName'},
        {label: '上传人', prop: 'name'},
        {label: '上传时间', prop: 'createTime'},
        {
          dataType: 'action',
          fixed: 'right',
          label: '操作',
          width: '170px',
          operation: [
            {
              name: '下载',
              type: 'text',
              clickFun: (row) => {
                this.handleDown(row);
              }
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.delete(row);
              }
            },
          ]
        }
      ],
      page: {
        total:0,
        size:10,
        current:1
      },
      isShow: this.filesDialogVisible,
      dataVisibleTitle: [
        {
          label: '进厂检验',
          value: 0
        },
        {
          label: '季度检验',
          value: 1
        },
      ],
      dataVisibleIndex: 0, // tab栏选择值
      entity: {
        insOrderId:''
      },
    }
  },
  mounted() {
    this.refreshTable()
  },
  // 方法集合
  methods: {
    // 切换数据查看tab栏
    handleDataVisibleTab (m, i) {
      this.dataVisibleIndex = i
      this.refreshTable()
    },
    // 查询回调
    refreshTable() {
      if (this.dataVisibleIndex === 0) {
        this.entity.insOrderId = this.filesLookInfo.enterOrderId
      } else {
        this.entity.insOrderId = this.filesLookInfo.quarterOrderId
      }
      this.tableLoading = true
      const params = {...this.entity}
      getFileList(params).then(res => {
        this.tableLoading = false
        if (res.code === 200) {
          this.tableData = res.data.records
          this.page.total = res.data.total
        }
      }).catch(err => {
        this.tableLoading = false
      })
    },
    pagination (page) {
      this.page.size = page.limit
      this.refreshTable()
    },
    // 下载
    handleDown(row){
      downFile({id: row.id,}).then(res => {
        if (res.code === 200) {
          let url = '';
          if(res.data.type==1){
            url = this.javaApi+'/img/'+res.data.fileUrl
            file.downloadIamge(url,row.fileName)
          }else{
            url = this.javaApi+'/word/'+res.data.fileUrl
            const link = document.createElement('a');
            link.href = url;
            link.download = row.fileName;
            link.click();
          }
        }
      }).catch(error => {
 
      })
    },
    handleSuccessUp(response, ) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.$refs.fileList.selectList()
      }
    },
    beforeUpload(file) {
      let flag = true
      if (this.dataVisibleIndex === 0 && !this.filesLookInfo.enterOrderId) {
        this.$message.warning('没有相应的检验任务')
        return
      } else if (this.dataVisibleIndex === 1 && !this.filesLookInfo.quarterOrderId) {
        this.$message.warning('没有相应的检验任务')
        return
      }
      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) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
    // 删除
    delete (row) {
      this.$confirm('是否删除当前数据?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        delfile({id: row.id}).then(res => {
          if (res.code === 500) {
            return
          }
          this.$message.success('删除成功')
          this.getList()
        }).catch(e => {
          this.$message.error('删除失败')
        })
      }).catch(() => {})
    }
  },
  computed: {
    headers() {
      return {
        'token': sessionStorage.getItem('token')
      }
    },
    action() {
      return this.javaApi + '/insOrderPlan/uploadFile'
    }
  },
}
</script>
 
<style scoped>
.tab {
  list-style-type: none;
  display: flex;
  margin-top: 0 !important;
  padding-left: 0 !important;
}
 
.tab li {
  line-height: 24px;
  padding: 6px 14px;
  font-size: 14px;
  color: #333333;
  border: 1px solid #EEEEEE;
  cursor: pointer;
}
 
.tab li:nth-child(1) {
  border-radius: 8px 0 0 8px;
}
 
.tab li:nth-child(2) {
  border-radius: 0 8px 8px 0;
}
 
.tab li.active {
  border-color: #3A7BFA;
  color: #3A7BFA;
}
</style>