confirmPayment.js
14.1 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
// pack-activity/pack/confirmPayment.js
import util, {
unixtoTime
} from '../../utils/util';
import App from '../../utils/api';
Page({
/**
* 页面的初始数据
*/
data: {
opt: {
detail: {},
combine_out_trade_no: '',
totalize: '',
types: '',
},
type: '',
name: "",
date: "",
phone: "",
calendarData: '',
sex: "先生",
indexs: 0,
StyleType:'',//邀请函模板
sexList: [{
sex: '先生',
value: '1',
},
{
sex: '女士',
value: '2',
},
{
sex: '公司',
value: '3',
},
{
sex: '贵宾',
value: '4',
}
]
},
modal: '',
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('options---',options);
this.setData({
opt: {
detail: options.detail ? JSON.parse(options.detail) : '',
combine_out_trade_no: options.combine_out_trade_no,
totalize: options.totalize ? options.totalize : '',
sid: options.sid ? options.sid : '',
types: options.types,
oid: options.oid ? options.oid : '',
rid: options.rid ? options.rid : '',
sellerName: options.sellerName ? options.sellerName : '',
},
type: options.type,
})
console.log('onLoad',{...options});
let obj = wx.getStorageSync('info')
console.log('objobjobjobj',{...obj})
if (obj) {
this.setData({
name: obj.name,
date: obj.date,
phone: obj.phone,
indexs: obj.sex * 1 - 1,
calendarData: obj.calendarData,
})
}
this.modal = this.selectComponent("#payModal"); //通过给组件所起的id调用组件
this.getSellerTemplateConfFun(options.sid)
},
// 获取商家设置营销信息---获取模板
getSellerTemplateConfFun(sid){
App.Seller.GetSellerTemplateConf({
sid
}).then(res => {
let StyleType = res.data.type;
this.setData({
StyleType
})
console.log('StyleType',StyleType);
})
},
// 购买完成券之后关注公众号
wananchi() {
this.closeModal()
wx.navigateTo({
url: `/pages/me/wananchi?type=1&oid=${this.data.opt.detail.oid}&sid=${this.data.opt.sid}`
})
},
showModal() {
this.modal.showModal() //调用组件中打开模态框方法
},
confirmPayment(gid) {
let that = this;
App.PayOnline.CombineTransactionsByNewRecharge({
combine_out_trade_no: this.data.opt.combine_out_trade_no,
gid:gid?gid:'',
}).then(res => {
console.log(res.data);
if (res.ret != '200') {
wx.showToast({
title: res.msg,
duration: 1000,
icon: 'none',
success: function () {
console.log('支付失败', that.data.opt.types);
that.callbackFun()
}
})
}
if (res.ret == '200') {
wx.requestPayment({
timeStamp: res.data.timeStamp + '',
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success(ress) {
if (ress.errMsg == 'requestPayment:ok') {
console.log('支付成功', ress);
return that.showModal()
}
console.log('支付失败', ress);
wx.showToast({
title: '支付失败,请重新下单',
duration: 1000,
success: function () {
that.callbackFun()
}
})
},
fail(ress) {
console.log('支付失败', ress);
wx.showToast({
title: '支付失败,请重新下单',
duration: 1000,
icon: 'none',
success: function () {
console.log('支付失败', that.data.opt.types);
that.callbackFun()
}
})
},
})
}
})
},
// 支付成功/失败回调 types 1邀请函 2提前点餐 3商家端app分享 4支付页充值 5我的页面余额充值
callbackFun() {
let that = this;
let url = '/pack-invitation/pages/detail_owner_invitation1?id=' + that.data.opt.detail.oid;
if(that.data.opt.types == '1'){
console.log('StyleType',this.data.StyleType);
let arr = [9, 10, 11, 12, 13, 14, 15, 16, 17];
let StyleType = this.data.StyleType;
let style =arr.includes(parseInt(StyleType))
if (!style) {
url = `/pack-invitation/pages/detail_owner_invitation${StyleType}?id=${that.data.opt.detail.oid}`;
} else {
url = `/pack-invitation/pages/detail_owner_invitation9?id=${that.data.opt.detail.oid}`;
}
if(StyleType == '18' || StyleType == '21') url = `/pack-invitation/pages/detail_owner_invitation11?id=${that.data.opt.detail.oid}`;
if(StyleType == '19' || StyleType == '22') url = `/pack-invitation/pages/detail_owner_invitation12?id=${that.data.opt.detail.oid}`;
if(StyleType == '20') url = `/pack-invitation/pages/detail_owner_invitation10?id=${that.data.opt.detail.oid}`;
if(StyleType == '18' || StyleType == '19') url += '&bookType=1';
if(StyleType == '21' || StyleType == '22') url += '&bookType=2';
}
if (that.data.opt.types == '2') {
let data={}
data.sid=that.data.opt.sid;
data.sellerName=that.data.opt.sellerName;
data.oid=that.data.opt.oid;
data.hasSuccess='1'
data.type='1'
data.rid=that.data.opt.rid?that.data.opt.rid:''
url = `/pack-cookbook/pages/success_new?hasSuccess=${data.hasSuccess}&identity=${data.identity}&oid=${data.oid}&rid=${data.rid}&sellerName=${data.sellerName}&sid=${data.sid}`;
}
if (that.data.opt.types == '3') {
url = '/pages/reserve/index_new';
}
if (that.data.opt.types == '4' || this.data.opt.types == '5') {
return wx.navigateBack(2)
}
setTimeout(function () {
wx.reLaunch({
url
})
}, 1000);
},
// 充值后跳转
recharge() {
console.log('充值完成跳转', this.data.opt.detail.oid);
console.log('StyleType',this.data.StyleType);
this.closeModal()
this.callbackFun()
},
// 绑定名称
bindKeyNameInput(event) {
const value = event.detail.value.replace(/\s+/g, "");
this.setData({
name: value
})
console.log(value);
},
// 绑定电话
bindKeyPhoneInput(event) {
const value = event.detail.value.replace(/\s+/g, "");
this.setData({
phone: value
})
console.log(value);
},
// 购买代金券后跳转
certificate() {
console.log({...this.data.opt.detail});
wx.reLaunch({
url: '/pages/me/coupon_news'
})
},
closeModal() {
this.modal.closeModal() //调用组件中关闭模态框方法
},
// 点击确认支付
formSubmit() {
if (this.data.type == '2') {
let data = this.data
if (!data.name) {
util.toast('未填写姓名', 'none')
return;
}
if (!data.phone) {
util.toast('未填写手机号码', 'none')
return;
}
if (!/^1\d{10}$/.test(data.phone)) {
util.toast('手机号码错误', 'none')
return;
}
let recharge_money = this.data.opt.detail.recharge_money * 1;
if (recharge_money == 0) {
setTimeout(() => {
util.toast('您的会员充值已经在办理中,到店消费时请和收银核实,谢谢!', 'none', 3000);
wx.navigateBack(1)
}, 3500);
return
}
this.getInfo()
} else {
this.confirmPayment()
}
},
getInfo() {
let sex = this.data.indexs * 1 + 1; //1男 2女 3公司 4贵宾
App.GuestManage.GetIsMemberByPhone({
sid: this.data.opt.sid,
phone: this.data.phone,
}).then(res => {
console.log('用户是否录入',res);
let params = {
sellerid: this.data.opt.sid,
rname: this.data.name,
sex,
phone: this.data.phone,
c_day: this.data.calendarData
}
console.log({...params});
if (res.data && res.data.id) {
if (this.data.phone == res.data.phone && this.data.name == res.data.rname && sex == res.data.sex && this.data.calendarData == res.data.c_day) {
console.log('信息都一样,直接支付');
this.confirmPayment(res.data.id)
} else {
params.id=res.data.id;
console.log('要修改信息');
this.editInfo(params)
}
} else {
console.log('没有客户信息,保存信息');
this.addInfo(params)
}
})
},
// 修改客户信息
editInfo(params) {
App.GuestManage.SetGuestInfo(params).then(res => {
if (res.data) {
this.confirmPayment(params.id)
}
})
},
// 新增客户信息
addInfo(params) {
App.GuestManage.InsGuest(params).then(res => {
if (res.ret == '200' && res.data && res.data.id) {
let obj = {
name: this.data.name,
phone: this.data.phone,
sex: this.data.indexs * 1 + 1,
calendarData: this.data.calendarData,
date: this.data.date,
}
wx.setStorageSync('info', obj)
this.confirmPayment(res.data.id)
}
})
},
// 选择日期
bind_ChangeDate(event) {
let date = event.detail.value
var calendarData = new Date(date) * 1 / 1000;
this.setData({
date,
calendarData
})
},
// 选择性别
bind_Changesex(event) {
console.log('event.detail',{...event.detail});
let indexs = event.detail.value;
this.setData({
indexs
})
console.log('indexs',indexs);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
// 返回
navEvent() {
console.log('types---------',this.data.opt.types);
// 1 邀请函 2 提前点餐 3商家端分享 4支付页充值 5我的页面余额充值
if (this.data.opt.types == '1') {
let arr = [9, 10, 11, 12, 13, 14, 15, 16, 17];
let StyleType = this.data.StyleType
let style =arr.includes(parseInt(this.data.StyleType))
let url = '';
if (!style) {
url = `/pack-invitation/pages/detail_owner_invitation${StyleType}?id=${this.data.opt.detail.oid}`;
} else {
url = `/pack-invitation/pages/detail_owner_invitation9?id=${this.data.opt.detail.oid}`;
}
if(StyleType == '18' || StyleType == '21') url = `/pack-invitation/pages/detail_owner_invitation11?id=${this.data.opt.detail.oid}`;
if(StyleType == '19' || StyleType == '22') url = `/pack-invitation/pages/detail_owner_invitation12?id=${this.data.opt.detail.oid}`;
if(StyleType == '20') url = `/pack-invitation/pages/detail_owner_invitation10?id=${this.data.opt.detail.oid}`;
if(StyleType == '18' || StyleType == '19') url += '&bookType=1';
if(StyleType == '21' || StyleType == '22') url += '&bookType=2';
return wx.reLaunch({
url
})
}
if (this.data.opt.types == '2') {
let data={}
data.oid=this.data.opt.oid;
data.sid=this.data.opt.sid;
data.sellerName=this.data.opt.sellerName;
data.hasSuccess='1';
data.identity='1';
data.type='1'
data.rid=this.data.opt.rid?this.data.opt.rid:''
let url = `/pack-cookbook/pages/success_new?hasSuccess=${data.hasSuccess}&identity=${data.identity}&oid=${data.oid}&rid=${data.rid}&sellerName=${data.sellerName}&sid=${data.sid}`;
return wx.reLaunch({
url
})
}
if (this.data.opt.types == '3') {
return wx.reLaunch({
url: '/pages/reserve/index_new',
})
}
if (this.data.opt.types == '4' || this.data.opt.types == '5') {
wx.navigateBack(2)
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
})