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
<template>
<el-dialog
:title="title"
visible
:before-close="closeDialog"
:close-on-click-modal="false"
width="800px"
>
<div v-for="item in fileList" :key="item.id" class="file-list">
<span>{{ getFileName(item.url) }}</span>
<div @click="deleteFile(item.id)">{{ $t('删除') }}</div>
<div @click="downloadFile(item.url)">{{ $t('下载') }}</div>
</div>
<div style="margin-top: 30px;display:flex;">
<el-upload action="#" accept="png" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUploadimg1">
<el-button size="small">
{{ $t('上传新附件') }}
<i class="el-icon-upload el-icon--right" />
</el-button>
</el-upload>
<el-button style="margin-left: 60px;" @click="closeDialog">{{ $t('返回') }}</el-button>
</div>
</el-dialog>
</template>
<script>
import { warehousePictureList, warehousePictureCreate, warehousePictureDelete,uploadOrgname } from '@/api/ecw/order'
export default {
props: {
orderId: [String, Number],
orderNo: [String, Number]
},
data() {
return {
show: false,
detail: null,
fileList: []
}
},
computed: {
title() {
let t = this.$t('报关资料')
if (this.orderNo) {
t += '-' + this.orderNo
}
return t
}
},
created() {
this.show = true
this.loadData()
},
methods: {
loadData() {
warehousePictureList({ bizId: this.orderId, type: 6 }).then((res) => {
this.fileList = res.data
})
},
getFileName(url) {
if (!url) return '/'
var file = url.split('/')
return file[file.length - 1]
},
closeDialog() {
this.show = false
this.$emit('close')
},
// 覆盖默认的上传行为
requestUpload() {
},
// 上传预处理
beforeUploadimg1(file) {
if (this.fileList.length >= 10) {
this.$message.error(this.$t('您最多上传10个附件'))
return
}
console.log(file)
var type = file.name.split('.')
if (['xls', 'doc', 'ppt', 'txt', 'pdf', 'jpg', 'png', 'jpeg', 'docx', 'xlsx'].indexOf(type[type.length - 1]) === -1) {
this.$message.error(this.$t('附件仅限doc/xls/ppt/txt/pdf/jpg/png/jpeg/docx/xlsx格式'))
} else {
// 上传
const formData = new FormData()
formData.append('file', file)
// formData.append('path', this.uuid())
uploadOrgname(formData).then(response => {
if (response.data) {
this.createImage(response.data)
}
})
}
},
createImage(url) {
warehousePictureCreate({ bizId: this.orderId, type: 6, url: url }).then(res => {
this.$message.success(this.$t('上传成功'))
this.loadData()
})
},
downloadFile(url) {
window.open(url, '_self')
},
deleteFile(id) {
this.$confirm(this.$t('确定删除附件吗?')).then(function() {
return warehousePictureDelete(id)
}).then(() => {
this.loadData()
this.$message({
message: this.$t('删除成功'),
type: 'success'
})
}).catch(() => {})
},
uuid() {
var s = []
var hexDigits = '0123456789abcdef'
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
}
s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = '-'
var uuid = s.join('')
return uuid
}
}
}
</script>
<style lang="scss" scoped>
.title {
font-size: 16px;
margin: 20px 0;
display: flex;
align-items: center;
&:before {
content: '';
width: 5px;
height: 15px;
background: #666;
margin-right: 10px;
}
}
.file-list{
display: flex;
align-items: center;
color: #297CE7;
margin-left: 30px;
font-size:16px;
margin-bottom:10px;
div{
cursor: pointer;
margin-left: 30px;
}
}
</style>