|
|
|
// pages/book/setting/sms_buy.js
|
|
|
|
import util from '../../../utils/util';
|
|
|
|
import App from '../../../utils/api';
|
|
|
|
const {regeneratorRuntime} = global
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
form:{},
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
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;
|
|
|
|
App.Reserve.SmsBuy(this.data.form).then(res=>{
|
|
|
|
let pay=res.data;
|
|
|
|
wx.requestPayment({
|
|
|
|
'timeStamp': pay.timeStamp,
|
|
|
|
'nonceStr': pay.nonceStr,
|
|
|
|
'package': pay.package,
|
|
|
|
'signType': 'MD5',
|
|
|
|
'paySign': pay.paySign,
|
|
|
|
'success':function(res){
|
|
|
|
if(res){
|
|
|
|
App.Reserve.SmsInfo({seller_id:this.data.seller_id},'clear');
|
|
|
|
wx.showToast({
|
|
|
|
title: '支付成功',
|
|
|
|
icon: 'loading',
|
|
|
|
duration: 1000,
|
|
|
|
mask:true,
|
|
|
|
success:function () {
|
|
|
|
setTimeout(()=>{
|
|
|
|
wx.navigateBack();
|
|
|
|
},1500)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'fail':function(res){
|
|
|
|
wx.showToast({
|
|
|
|
title: '已取消支付',
|
|
|
|
icon: 'loading',
|
|
|
|
duration: 1000,
|
|
|
|
mask:true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|