sms_buy.js
3.13 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
// pages/book/setting/sms_buy.js
import util from '../../../../utils/util';
import App from '../../../../utils/api';
const {regeneratorRuntime} = global
Page({
/**
* 页面的初始数据
*/
data: {
form:{},
},
/**
* 生命周期函数--监听页面加载
*/
hasScene:false,
onLoad: function (options) {
//转化场景值到 options
if(options.scene){//扫码进入
let query=decodeURIComponent(options.scene);
query.split('&').forEach(q=>{
let _q=q.split('=');
options[_q[0]]=_q[1];
})
this.hasScene=true
}
if(!options.seller_id){
let enter_params=util.cache('enter_params');
options.seller_id=enter_params.seller_id;
}
App.Reserve.SmsInfo({seller_id:options.seller_id}).then(res=>{
if(res.ret==404){
res.data={
last_num:100,
meals:[
{id:1,total:550,price_ave:0.09,price_old:50,price:50,discount:0},
{id:2,total:1200,price_ave:0.083,price_old:100,price:100,discount:0},
{id:3,total:3650,price_ave:0.082,price_old:328,price:300,discount:9.1},
],
};
}
this.setData({
seller_id:options.seller_id,
sms:res.data,
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
chooseMeal(e){
this.setData({
form:{
meal_id:util.attr(e,'id'),
price:util.attr(e,'price'),
seller_id:this.data.seller_id
}
})
},
buy(){
if(!this.data.form.meal_id) return;
let prarms={
sellerid: this.data.form.seller_id,
//price:this.data.form.price,
price:0.01,
meal_id:this.data.form.meal_id,
openid:getApp().openid,
}
App.Reserve.SmsBuy(prarms).then(res=>{
let pay=res.data;
wx.requestPayment({
'timeStamp': pay.timeStamp,
'nonceStr': pay.nonceStr,
'package': pay.package,
'signType': 'MD5',
'paySign': pay.paySign,
'success':(payRes)=>{
if(payRes){
App.Reserve.SmsInfo({seller_id:prarms.sellerid},'clear');
wx.showToast({
title: '支付成功',
icon: 'loading',
duration: 1000,
mask:true,
success:()=> {
setTimeout(()=>{
if(this.hasScene){
wx.redirectTo({
url:'/pages/book/setting/sms?seller_id='+prarms.sellerid
});
}else{
wx.navigateBack();
}
},1500)
}
})
}
},
'fail':function(res){
wx.showToast({
title: '已取消支付',
icon: 'loading',
duration: 1000,
mask:true,
})
}
})
});
},
})