/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ /** * 页面的初始数据 */ data: { total : "0.00", orderNo : "", modelId : "", modelType : "", payType : "", orderNos : [], can : { coin : 0, wechat : 0, }, loding : false, noShow : false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { order_id, order_type, order_no } = JSON.parse(decodeURIComponent(options.params)) wx.showLoading({ title: '加载中...', mask : true }) wx.$api.pay.info({ order_id, order_type }).then(res => { let { can, total, model_type, model_id, order_nos } = res.data this.setData({ orderNo : order_no, payType : res.data.default, modelId : model_id, modelType : model_type, orderNos : order_nos, total, can }) wx.hideLoading() }) }, /** * 选择支付方式 */ onPayType(e){ let { value } = e.detail this.setData({ payType: value }) }, /** * 立即支付 */ onPay(){ this.setData({ loding: true }) switch (this.data.payType) { case 'wechat': this.wechatPay() break; case 'coin': wx.showToast({ title: '支付方式暂未开放', icon : 'none' }) this.setData({ loding: false }) break; case 'baofoo': this.baofuPay() break; } }, /** * 宝付微信 */ baofuPay(){ wx.login({ success: wxCode => { // wx.getFuzzyLocation({ // success: locationRes => { // let { latitude, longitude } = locationRes let { code } = wxCode; let data = { order_type : this.data.modelType, order_id : this.data.modelId, code : code, longitude : '171.21', latitude : '22.33', } wx.$api.pay.bfPay(data).then(res => { console.log(res) }).finally(() => { this.setData({ loding: false }) }) // } // }) } }) }, /** * 微信支付 */ wechatPay(){ wx.login({ success: wxCode => { let { code } = wxCode; wx.$api.pay.wechatPay({ order_type : this.data.modelType, order_id : this.data.modelId, type : "mini", code : code }).then(res => { let { wechat, trade_id } = res.data let wechatObj = JSON.parse(wechat) wx.requestPayment({ nonceStr : wechatObj.nonceStr, package : wechatObj.package, paySign : wechatObj.paySign, timeStamp: wechatObj.timeStamp, signType : wechatObj.signType, success : () => { wx.redirectTo({ url: './success/success?trade_id=' + trade_id, }) } }) }).finally(() => { this.setData({ loding: false }) }) } }) }, /** * 展开订单号 */ noTap() { this.setData({ noShow: !this.data.noShow }) } })