// pages/orders/order-detail.ts import { api_executeOrder, api_executePayment, api_queryByParamName } from "../../api/login"; // 获取应用实例 const app = getApp() Page({ /** * 页面的初始数据 */ data: { status: 'ing', statusList: { ing: { logo: './images/ing.png', title: '等待付款', content: '请尽快完成支付,以便我们为您处理订单' }, success: { logo: './images/success.png', title: '交易完成', content: '登录「音乐数字课堂」APP使用AI学练' }, error: { logo: './images/error.png', title: '交易取消', content: '您的交易订单已关闭' }, wait: { logo: './images/wait.png', title: '等待使用', content: '请尽快扫描下方二维码进行激活' } }, goodsInfo: {} as any, paymentType: null as any, // 支付类型 }, /** * 生命周期函数--监听页面加载 */ onLoad(options: any) { this.queryPayType() if (options.orderInfo) { const goods = JSON.parse(decodeURIComponent(options.orderInfo)); this.setData({ goodsInfo: goods, status: goods.status }); } }, // 获取后台配置的支付方式 async queryPayType() { try { const { data } = await api_queryByParamName({ paramName: 'payment_service_provider' }); if (data.code == 200) { const paramValue = data.data.paramValue ? JSON.parse(data.data.paramValue) : {} this.setData({ paymentType: paramValue.vendor, }); } } catch (error) { console.log(error, "error"); } }, // 购买 async onSubmit() { wx.showLoading({ mask: true, title: "订单提交中...", }); try { const { salePrice, shopId, name, id } = this.data.goodsInfo const { data } = await api_executeOrder({ "orderType": "WECHAT_MINI", "paymentType": this.data.paymentType, "paymentCashAmount": salePrice, "paymentCouponAmount": 0, "shopId": shopId, "opneId": app.globalData.userInfo?.liteOpenid, "goodsInfos": [{ "goodsId": id, "goodsNum": 1, "goodsType": "ACTIVATION_CODE", "paymentCashAmount": salePrice, "paymentCouponAmount": 0 }], "orderName": name, "orderDesc": name }) console.log(data, 'data') if (data.code === 200) { const { paymentConfig, paymentType } = data.data const res = await api_executePayment({ merOrderNo: paymentConfig.merOrderNo, paymentChannel: 'wxpay-app', paymentType, userId: app.globalData.userInfo?.id }) wx.hideLoading() this.onPay(paymentType, res.data.data.reqParams) } else { wx.hideLoading() wx.showToast({ title: '支付失败', icon: 'none' }) } } catch { wx.hideLoading() } }, onPay(paymentType: string, paymentConfig: any) { const isYeePay = paymentType.indexOf('yeepay') !== -1 const prePayInfo = isYeePay ? JSON.parse(paymentConfig.prePayTn) : paymentConfig?.expend ? JSON.parse(paymentConfig?.expend?.pay_info) : paymentConfig wx.requestPayment({ timeStamp: prePayInfo.timeStamp, nonceStr: prePayInfo.nonceStr, package: prePayInfo.package ? prePayInfo.package : prePayInfo.packageValue, paySign: prePayInfo.paySign, signType: prePayInfo.signType ? prePayInfo.signType : 'MD5', success(resInfo) { console.log('支付成功', resInfo) wx.showToast({ title: '支付成功~', icon: 'success' }); // that.onClose('end') }, fail(ressonInfo) { console.log('支付失败', ressonInfo) wx.showToast({ title: '支付失败!', icon: 'none' }); } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })