confirmPayment.js
10.8 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
// 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: '',
time: 300,
countdown: '',
name:"",
date: "",
phone:"",
calendarData:'',
sex:"先生",
indexs:0,
sexList:[
{
sex:'先生',
value:'1',
},
{
sex:'女士',
value:'2',
},
{
sex:'公司',
value:'3',
}
]
},
modal:'',
/**
* 生命周期函数--监听页面加载
*/
onLoad(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:'',
sellerid:options.sellerid?options.sellerid:'',
types:options.types,
},
type:options.type,
})
console.log('onLoad',{...this.data.opt});
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.countdown()
this.modal = this.selectComponent("#payModal"); //通过给组件所起的id调用组件
},
// 购买完成券之后关注公众号
wananchi() {
this.closeModal()
wx.navigateTo({
url: `/pages/me/wananchi?type=1&oid=${this.data.opt.detail.oid}`
})
},
showModal() {
this.modal.showModal() //调用组件中打开模态框方法
},
confirmPayment(){
App.PayOnline.CombineTransactionsByNewRecharge({
combine_out_trade_no:this.data.opt.combine_out_trade_no
}).then(res=>{
console.log(res.data);
let that=this;
if(res.ret!='200'){
wx.showToast({
title: res.msg,
duration: 1000,
icon:'none',
success: function () {
console.log('支付失败',that.data.opt.types);
let url='';
if(that.data.opt.types=='1'){
url='/pages/customer/detail_owner_invitation_new?id='+that.data.opt.detail.oid;
}
if(that.data.opt.types=='2'){
url='/pack-cookbook/pages/success_new';
}
if(that.data.opt.types=='3'){
url='/pages/reserve/index';
}
setTimeout(function () {
wx.reLaunch({
url
})
}, 1000);
}
})
}
if(res.ret=='200'){
console.log(res.ret);
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 () {
setTimeout(function () {
wx.reLaunch({
url: `/pages/customer/detail_owner_invitation_new?id=${that.data.opt.detail.oid}&hasInvitation=1&hasSellerShare=1&tplid=1`
})
}, 1000);
}
})
},
fail (ress) {
console.log('支付失败',ress);
wx.showToast({
title: '支付失败,请重新下单',
duration: 1000,
icon:'none',
success: function () {
console.log('支付失败',that.data.opt.types);
let url='';
if(that.data.opt.types=='1'){
url='/pages/customer/detail_owner_invitation_new?id='+that.data.opt.detail.oid;
}
if(that.data.opt.types=='2'){
url='/pack-cookbook/pages/success_new';
}
if(that.data.opt.types=='3'){
url='/pages/reserve/index';
}
setTimeout(function () {
wx.reLaunch({
url
})
}, 1000);
}
})
},
})
}
})
},
// 充值后跳转
recharge(){
console.log('充值完成跳转',this.data.opt.detail.oid);
this.closeModal()
wx.reLaunch({
url: `/pages/customer/detail_owner_invitation_new?id=${this.data.opt.detail.oid}&hasInvitation=1&hasSellerShare=1&tplid=1`
})
},
// 绑定名称
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.time==0){
return util.toast('当前订单已过期,请重新进入优惠券购买页面下单', 'none');
}
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.addInfo()
}else{
this.confirmPayment()
}
},
addInfo(){
let params={
sellerid:this.data.opt.sellerid,
rname:this.data.name,
sex:this.data.indexs*1+1,//1男 2女 3公司
phone:this.data.phone,
c_day:this.data.calendarData
}
console.log({...params});
App.GuestManage.InsGuest(params).then(res=>{
console.log(res);
if(res.ret=='200'){
this.confirmPayment()
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)
}
})
},
// 选择日期
bind_ChangeDate(event) {
let date = event.detail.value
var calendarData = new Date(date)*1;
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() {
},
// 倒计时
countdown() {
var minute = Math.floor(this.data.time*1 / 60);
var second = this.data.time % 60;
second < 10 ? second = '0' + second : '';
this.setData({
countdown: minute + ':' + second,
time: this.data.time - 1
})
if(this.data.time==0){
this.setData({
countdown: '0:00'
})
return false;
}
setTimeout(this.countdown, 1000);
},
// 返回
navEvent(){
// 1 邀请函 2 提前点餐 3商家端分享
if(this.data.opt.types=='1'){
return wx.reLaunch({
url: '/pages/customer/detail_owner_invitation_new?id='+this.data.opt.detail.oid,
})
}
if(this.data.opt.types=='2'){
return wx.reLaunch({
url: '/pack-cookbook/pages/success_new',
})
}
if(this.data.opt.types=='3'){
return wx.reLaunch({
url: '/pages/reserve/index',
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})