70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
import shopApi from '../../api/shop';
|
|
import userApi from '../../api/user';
|
|
|
|
Component({
|
|
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
calculatedPrice:{},
|
|
product:{},
|
|
isShowConfirm:false
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
preOrder(product){
|
|
shopApi.calculateOrderPrice(product.id).then((data)=>{
|
|
this.setData({
|
|
calculatedPrice:data,
|
|
product,
|
|
isShowConfirm:true
|
|
});
|
|
})
|
|
},
|
|
getOrder(){
|
|
shopApi.order(this.data.product.id).then((data)=>{
|
|
this.setData({
|
|
isShowConfirm:false
|
|
});
|
|
this.triggerEvent('orderCreated');
|
|
this.createPayment(data.order_id);
|
|
}).catch((error)=>{
|
|
this.setData({
|
|
isShowConfirm:false
|
|
})
|
|
});
|
|
},
|
|
createPayment(orderId,needStay){
|
|
userApi.createPayment(orderId).then((data)=>{
|
|
wx.requestPayment({
|
|
timeStamp:data.payment_params.timeStamp,
|
|
nonceStr:data.payment_params.nonceStr,
|
|
package:data.payment_params.package,
|
|
signType:data.payment_params.signType,
|
|
paySign:data.payment_params.paySign,
|
|
success:(res)=>{
|
|
this.triggerEvent('paySuccess');
|
|
if(!needStay){
|
|
wx.navigateTo({
|
|
url: '/pages/shop/success/index',
|
|
})
|
|
}
|
|
},
|
|
fail:(res)=>{
|
|
console.log(res);
|
|
}
|
|
})
|
|
});
|
|
}
|
|
}
|
|
}) |