EditTransfer.vue
9.96 KB
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
<template>
<d2-dialog title="应付转账" :is-visible="editTransferVisible" class="privacyDailog" width="1080px" @closeDialog="handleClose" @confirmDialog="handleConfirm">
<glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="250px" default-width="450px" :isBlock="isBlock" :form-ref="editChildRef" :form-obj="editData" :form-data="editFormData" :form-rules="formRules">
<template slot="fileHtml" slot-scope="scope">
<el-upload action="" accept=".xlsx,.xls,.docx,.pdf,.png,.jpg,.jpeg" class="upload-file" drag :show-file-list="false" :file-list="uploadFileList" :limit="5" :auto-upload="false" :on-remove="importFileChange" :on-change="(file, fileList) => handleFileChange(file, fileList, scope.scope)" :on-exceed="hanldeOnExceed" multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">点击或将文件拖拽到此区域上传</div>
<div class="item-tips text-tips">
支持格式.xlsx.xls.docx.pdf.png.jpg单个文件不能超过10M
</div>
<div class="item-tips">最多上传5个文件</div>
</el-upload>
<!-- 文件列表区域 -->
<div class="file-box">
<div v-for="(subItem, subIndex) in editData.fileUrlList" :key="subIndex">
<div class="file-item" v-if="!filterEmpty(subItem.uploadProgress) || subItem.fileUrl">
<div class="file-content" @click="handleFileView(subItem)">
<el-progress define-back-color="#F5F7FA" :text-inside="true" text-color="#333333" :show-text="false" :stroke-width="26" stroke-linecap="butt" :percentage="subItem.uploadProgress"></el-progress>
<div class="file-name">{{ subItem.fileName }}</div>
</div>
<i v-if="!subItem.fileUrl" class="el-icon-close del-icon" @click="doCancel(scope.scope, subIndex)"></i>
<i v-if="subItem.fileUrl" class="el-icon-delete" @click="handleFileDelete(scope.scope, subIndex)"></i>
</div>
</div>
</div>
</template>
</glsx-combi-form>
<div style="margin-left: 250px;">* 说明:发起应付转账后,请到企微“SaaS+商务付款”流程中查看审批状态。</div>
</d2-dialog>
</template>
<script>
import { editBillTransferOut } from '@api/accountManage'
import { deepClone } from '@/common/util'
import { limitPrice } from '@/common/format'
import GlOssApi from "glsk-oss-jssdk"
import { baseConfig } from "@/main"
export default {
name: 'EditTransfer',
data() {
return {
isBlock: true,
editChildRef: 'editChildRef',
formRules: {
amount: [
{ required: true, message: "请输入转账金额", trigger: 'change' },
{
required: true,
validator: (rule, value, callback) => {
if (value <= 0) {
callback(new Error("转账金额不能为0"))
} else {
callback()
}
},
trigger: 'change'
}
],
fileUrlList: [{ required: true, message: "请选择转账凭证", trigger: 'change' }],
remark: [{ required: true, message: "请输入备注", trigger: 'change' }],
invoiceRemark: [{ required: true, message: "请输入发票及其他说明", trigger: 'change' }]
},
editData: {
platformMerchantId: '',
platformMerchantName: '',
fileUrlList: [],
amount: '',
remark: '',
invoiceRemark: ''
},
oldValue: {},
editFormData: [
{
label: "所属平台方",
name: "platformMerchantName",
type: "showTxt"
},
{
label: "对账服务商",
name: "billMerchantName",
type: "showTxt"
},
{
label: "转账金额",
name: "amount",
type: "input",
inputFn: (newVal) => {
this.editData.amount = limitPrice(newVal, this.oldValue.amount, 12, 2)
this.oldValue.amount = this.editData.amount
}
},
{
label: "转账凭证",
name: "fileUrlList",
addHtml: "fileHtml"
},
{
label: "备注",
name: "remark",
type: "input",
maxlength: 50
},
{
label: "发票及其他说明",
name: "invoiceRemark",
type: "input",
maxlength: 100
}
],
baseData: {
},
uploadFileList: [],
imgViewerVisible: false,
loading: false
}
},
props: {
editTransferVisible: {
type: Boolean,
default: false
},
info: {
type: Object,
default: () => ({})
}
},
watch: {
"editData.fileUrlList": {
handler(newVal) {
if (newVal) {
console.log('newVal', newVal)
this.uploadFileList = newVal.filter(
(v) => !this.filterEmpty(v.uploadProgress) || v.fileUrl
) // 文件列表
}
},
deep: true
}
},
mounted() {
this.GlOssApi = new GlOssApi({
baseConfig
})
this.editData = {
...this.editData,
...this.info
}
// this.editData = deepClone(this.info)
// this.editData.fileUrlList = []
this.oldValue.amount = this.editData.amount
this.editFormData[this.findIdx('billMerchantName')].label = this.editData.billType == '1' ? '对账流量方' : '对账服务商'
console.log('editData', this.editData)
},
methods: {
findIdx(attr) {
return this.editFormData.findIndex(item => item.name === attr)
},
handleConfirm() {
// this.editData.fileUrlList = ['https://pics5.baidu.com/feed/03087bf40ad162d961034fabc0ed00e38b13cd5e.jpeg@f_auto?token=0aca42cd8d1f4381c9518431db657a5b']
// this.editData.fileUrlList = ['https://pics5.baidu.com/feed/03087bf40ad162d961034fabc0ed00e38b13cd5e.jpeg@f_auto?token=0aca42cd8d1f4381c9518431db657a5b']
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
if (valid) {
const params = deepClone(this.editData)
params.fileUrlList = params.fileUrlList.map(item => item.fileUrl)
editBillTransferOut(params).then(() => {
this.$message.success("操作成功")
this.$emit('handleConfirm')
}).finally(() => {
this.loading = false
})
}
})
},
handleClose() {
this.$emit('dialogClose')
},
// 获取文件
importFileChange(file, fileList) {
this.uploadFileList = fileList
this.editData.fileUrlList = deepClone(fileList)
console.log(fileList, "fileList")
},
handleFileChange(file, fileList, targetItem) {
// setTimeout(() => {
// var reader = new FileReader()
var fileInfo = file.raw
const fileName = fileInfo.name
const allowedExtensions = [".xlsx", ".xls", ".docx", ".pdf", ".png", ".jpg", ".jpeg"]
const isValidType = allowedExtensions.some(ext => fileInfo.name.toLowerCase().includes(ext))
if (!isValidType) {
this.$message({
message: "文件格式不支持上传,支持格式:.xlsx .xls .docx .pdf .png .jpg",
type: "error"
})
return false
}
// 默认10MB
const limitSize = 10
const isLt = fileInfo.size / 1024 / 1024 < limitSize
if (!isLt) {
this.$message({
message: "上传文件大小不能超过" + limitSize + "MB!",
type: "error"
})
this.uploadFileList = this.uploadFileList.filter((item) => {
return item.size / 1024 / 1024 < 10
})
return false
}
const _formData = this.editData
_formData[targetItem.name].push({
fileUrl: "",
uploadProgress: 0,
fileName: fileInfo.name?.substring(0, 128),
fileSize: fileInfo.size,
cancelAxios: {}
})
const index = _formData[targetItem.name].length - 1
const success = (res) => {
_formData[targetItem.name][index].fileUrl = res.aliyunAddress // 文件地址
}
const fail = (err) => {
this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
}
this.handleOssUpload(fileInfo, fileName, success, fail)
},
handleOssUpload(file, fileName, success, fail) {
const bucketName = "jinrong-huidan-test" // 桶名
const fileType = fileName.substr(fileName.lastIndexOf(".") + 1)
this.GlOssApi.multipartUpload(file, success, fail, bucketName, fileType)
},
hanldeOnExceed(files, fileList) {
this.$message({
message: "最多可上传5个文件",
type: "error"
})
},
// 删除文件
handleFileDelete(targetItem, subIndex) {
// this.clearItem(targetItem, subIndex)
console.log(subIndex)
this.editData.fileUrlList.splice(subIndex, 1)
// this.editData.fileUrlList = []
},
// 预览文件
handleFileView(item) {
// if (!item.fileUrl) return
// if (item?.fileUrl.includes('.pdf')) { // pdf文件直接打开新窗口预览
// window.open(item.fileUrl)
// } else {
// this.imgViewerVisible = true
// this.imageFileArr.forEach((val, index) => {
// if (val == item.fileUrl) this.initialIndex = index
// })
// }
},
closeImgViewer() {
this.imgViewerVisible = false
},
// 取消上传
doCancel(targetItem, subIndex) {
const _formData = this.editData
const cancelUploadObj = _formData[targetItem.name][subIndex].cancelAxios
cancelUploadObj && cancelUploadObj.cancel && cancelUploadObj.cancel()
this.clearItem(targetItem, subIndex)
},
filterEmpty(data) {
return (data ?? "") === ""
},
// 清空上传文件数组项内容
clearItem(targetItem, subIndex) {
this.$set(this.editData[targetItem.name][subIndex], "fileUrl", "")
this.$set(this.editData[targetItem.name][subIndex], "uploadProgress", "")
}
}
}
</script>
<style>
.privacyDailog .el-dialog {
min-width: 700px;
}
</style>