uploadPayVoucher.js
2.58 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
// packageStoreAssistant/packageActivity/pages/uploadPayVoucher/uploadPayVoucher.js
import {
commonApi
} from '~/api/api'
import ActivityApi from '~/api/activityApi/index'
import environment from '~/utils/request/environment.js'
Page({
/**
* 页面的初始数据
*/
data: {
success: true
},
/**
* 生命周期函数--监听页面加载
*/
onRoute({
subOrderCode,
verificationVoucher
}) {
this.setData({
subOrderCode,
paymentVoucheUrl: verificationVoucher
})
},
previewImage() {
const urls = [this.data.paymentVoucheUrl]
wx.previewImage({
urls
})
},
async upload() {
const {
tempFiles
} = await wx.chooseMedia({
count: 1,
mediaType: ['image']
}),
[file] = tempFiles,
_this = this
wx.$api.showLoading('上传中...')
try {
wx.uploadFile({
url: `${environment.domain}/rpc-scrm-entmicro-container/file/img?desFileSize=10`,
// url: 'http://192.168.3.101:8186/rpc-scrm-entmicro-container/file/img?desFileSize=10',
filePath: file.tempFilePath,
name: 'file',
formData: {
desFileSize: 10
},
success({
data
}) {
wx.hideLoading()
const response = JSON.parse(data),
paymentVoucheUrl = response.result
if (paymentVoucheUrl) _this.setData({
paymentVoucheUrl
})
else throw response.message
},
fail(err) {
throw err
}
})
} catch (error) {
wx.$api.showToast(String(JSON.stringify(error)))
}
},
dialogClose() {
this.setData({
showModal: false
})
},
dialogConfirm() {
const {
success
} = this.data
if (success) wx.$router.back()
else this.dialogClose()
},
async submit() {
this.setData({
submitLoading: true
})
try {
const {
paymentVoucheUrl,
subOrderCode
} = this.data, {
message,
code
} = await ActivityApi.uploadPaymentVoucher({
subOrderCode,
paymentVoucheUrl
})
this.setData({
submitLoading: false
})
if (code == '0') {
this.setData({
showModal: true,
success: true
})
} else {
if (message == '请勿上传同一张付款凭证') this.setData({
showModal: true,
success: false
})
else wx.$api.showToast(message)
}
} catch (error) {
this.setData({
submitLoading: false
})
wx.$api.showToast(error)
}
}
})