OrderPopup.js
6.92 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
// components/OrderPopup/OrderPopup.js
import qrcode from '../../utils/wxqrcode'
import api from '~/api/api.js'
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
*/
options: {
styleIsolation: 'shared', // 自定义覆盖vant样式
},
properties: {
show: Boolean,
orderType: {
type: String,
observer: function (n) {
if (n == '0') {
api
.getConfigList({
confGroup: 'SMARTCARLIFE_NOT_UPGRADE_LABEL'
})
.then(res => {
let list = []
let { code, data } = res
if (code == 0) {
list = data
}
this.setData({
shortcutList: list
})
})
}
}
},
price: String,
qrCode: {
type: String,
observer: function (n) {
if (n) {
this.createQRCode(n)
}
}
},
orderCode: String,
orderInfo: Object
},
/**
* 组件的初始数据
*/
data: {
shortcutList: [],
orderTypeList: [
{
name: '旧单补录',
tips: '以旧的下单时间为客户补录生成新工单',
active: true,
value: 6
},
{
name: '新增一单',
tips: '根据当前时间为客户新建一笔新工单',
value: 4
}
],
textareaValue: '',
routerBack: null,
outTradeNo: '',
wxqrcode: '',
payVoucherList: []
},
/** 组件生命周期 */
lifetimes: {
attached: function () {
// 支付方式为微信
if (this.data.orderType == 1) {
this.createWxQrcode()
}
}
},
/**
* 组件的方法列表
*/
methods: {
noScroll() { },
close() {
let { routerBack } = this.data
if (routerBack) {
wx.navigateBack()
return
}
this.setData({
show: false
})
},
blur(e) {
console.log(e)
let { value } = e.detail
let { shortcutList } = this.data
value = value.substring(0, 30)
if (!value) {
shortcutList.map(i => (i.active = false))
}
this.setData({
textareaValue: value,
shortcutList,
focus: false
})
},
chooseShortcut(e) {
let { item, index } = e.currentTarget.dataset
let { textareaValue, shortcutList } = this.data
if (shortcutList[index].active) return
textareaValue += item.confValue
textareaValue = textareaValue.substring(0, 30)
this.setData({
textareaValue,
[`shortcutList[${index}].active`]: true,
focus: true
})
},
createQRCode(text) {
console.log(text)
let size = 0
try {
const info = getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale
size = width
} catch (e) {
size = 150
}
let _img = qrcode.createQrCodeImg(text, {
size: parseInt(size)
})
this.setData({
qr: _img
})
},
input(e) {
let { value } = e.detail
let val = value.replace(/[\u4E00-\u9FA5]/g, '')
this.setData({
outTradeNo: val
})
},
// 上传付款凭证
upLoad(event) {
let _this = this
let { payVoucherList } = _this.data
const { file } = event.detail
let tempFiles = file?.url
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
api
.uploadImg({
file: `${type}@${_res.data}`
})
.then(img => {
wx.$util.hideLoading()
console.log(img)
let { code, data, message } = img
if (code == 0) {
payVoucherList.push({ url: data })
_this.setData({
payVoucherList
})
} else {
wx.$util.showToast(message)
}
})
}
})
},
// 删除上传
deletePayVoucher(e) {
let { index } = e?.detail
let _this = this
let { payVoucherList } = _this.data
payVoucherList.splice(index, 1)
this.setData({
payVoucherList
})
},
changeOrderSource(e) {
console.log(e)
let { index } = e.currentTarget.dataset
let { orderTypeList } = this.data
orderTypeList.map(i => (i.active = false))
orderTypeList[index].active = true
this.setData({
orderTypeList
})
},
confirm(e) {
let { orderType, outTradeNo, payVoucherList, textareaValue, orderTypeList, confirmStatus } = this.data
// debugger
// console.log(wx.$router)
// 做防抖
if (confirmStatus) return
this.setData({
confirmStatus: true
})
setTimeout(() => {
this.setData({
confirmStatus: false
})
}, 1000)
console.log(thisPage, 'thisPage');
let thisPage = wx.$router.getPageInstance()
// 支付方式 2:门店收款 5:嘀加收款 6:对公转账 7:其它收款
if ([2, 5, 6, 7].includes(Number(orderType))) {
if (payVoucherList.length && outTradeNo) {
thisPage.setData({
outTradeNo,
payVoucherList
})
thisPage.createPayOrder()
} else {
wx.$util.showToast('交易流水号或付款凭证不能为空!')
}
} else if (orderType == 0) {
if (textareaValue) {
console.log(textareaValue)
thisPage.installOnly(textareaValue)
} else {
wx.$util.showToast('请输入内容!')
}
} else {
orderTypeList.map(i => {
if (i.active) {
return console.log(i.value)
console.log(thisPage.keepGoing)
return
thisPage.keepGoing(i.value)
}
})
}
},
// 生成小程序码
createWxQrcode() {
let _this = this
let oParams = {}
oParams.appId = this.data.orderInfo.paymentChannel.wechatAppId
oParams.qrcodeType = 'QR_WXA_UNLIMIT'
oParams.path = 'packagesPayment/pages/payment/index'
// oParams.path = 'packagesPayment/pages/QRPayment/QRPayment'
// oParams.scene = `merchantId=111`
oParams.scene = `orderCode=${_this.data.orderCode}&workWxSessionId=${wx.getStorageSync('dj_boutique_sessionId')}`
oParams.channelType = 1
// B端小程序调用接口生成领券码时,传参userId用uuid,类型由int变string
api.createQrcodeImage(oParams).then(res => {
console.log(res.data)
console.log(res.code)
_this.setData({
wxqrcode: res.data
})
})
}
}
})