dm-wechat-mini/components/merchantOrder/index.js
2025-02-15 02:27:33 +08:00

67 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)=>{
userApi.createPayment(data.order_id,'PRODUCT').then((data)=>{
this.triggerEvent('orderCreated');
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)=>{
wx.navigateTo({
url: '/pages/shop/success/index',
})
},
fail:(res)=>{
console.log(res);
}
})
});
}).catch((error)=>{
this.setData({
isShowConfirm:false
})
wx.showModal({
title: error.message,
showCancel:false,
complete: (res) => {
}
})
});
},
}
})