var util = require('../../utils/util.js'); var api = require('../../config/api.js'); Page({ data: { // 0创建,1发起支付中,2支付成功,3退款,4取消 id:'', diffList:[], orderInfo:{ }, }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 console.log(options); this.setData({ id: options.id, }); // this.getDiffOrder(); }, onShow: function () { // 页面显示 this.getDiffOrder(); }, onPullDownRefresh() { wx.showNavigationBarLoading(); //在标题栏中显示加载 this.getDiffOrder(); wx.hideNavigationBarLoading(); //完成停止加载 wx.stopPullDownRefresh(); //停止下拉刷新 }, getDiffOrder: function () { wx.showLoading({ title: '加载中' }); util.request(api.getDiffList, { bookDetailId: this.data.id }).then(res=> { wx.hideLoading(); if (res.errno === 0) { this.setData({ diffList:res.data.diffList, orderInfo:res.data.bookDetail }); } }).catch(err=> { console.log(err); wx.hideLoading(); }); }, diffDetail(e){ let difNo=e.currentTarget.dataset.no; wx.navigateTo({ url: '/pages/diffOrderDetail/diffOrderDetail?difNo='+difNo, }); }, goPay(e){ wx.showLoading({ title: '加载中' }); let difNo=e.currentTarget.dataset.no; util.request(api.prepayDiff, { diffOrderNo: difNo }).then(res=> { wx.hideLoading(); if (res.errno === 0) { let payParam=res.data; wx.requestPayment({ 'timeStamp': payParam.timeStamp, 'nonceStr': payParam.nonceStr, 'package': payParam.packageValue, 'signType': payParam.signType, 'paySign': payParam.paySign, success: function(res) { console.log("支付过程成功"); wx.showToast({ title: '支付成功', duration:3000, mask:true, }); setTimeout(()=>{ wx.navigateTo({ url: '/pages/diffOrderDetail/diffOrderDetail?difNo='+difNo, }); },4000); }, fail: function(res) { console.log("支付过程失败"); util.showErrorToast('支付失败'); }, complete: function(res) { console.log("支付过程结束") } }); }else{ wx.showToast({ title: res.errmsg, icon:'none', duration:3000 }) } }).catch(err=> { console.log(err); wx.hideLoading(); }); }, // “去付款”按钮点击效果 payOrder: function () { let that = this; util.request(api.OrderPayCheck, { orderId: that.data.orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { const outOrderNo = res.data; console.log(res); wx.continueToPay({ // orderId: this.data.orderId, // 内部订单号 outOrderNo: outOrderNo, // 外部订单号 2个订单号必填一个 success: res => { console.log(res); const { orderId, outOrderNo } = res; console.log('success res', res); console.log('orderId', orderId, 'outOrderNo', outOrderNo); wx.redirectTo({ url: '/pages/ucenter/order/order' }); }, fail: res => { console.log(res); const { orderId, outOrderNo, errNo, errMsg, errLogId } = res; if (errLogId) { console.log('查询订单信息失败', errNo, errMsg, errLogId); } if (orderId || outOrderNo) { console.log('支付失败', errNo, errMsg, orderId, outOrderNo); } util.showErrorToast('支付失败'); }, }); } }); }, onReady: function () { // 页面渲染完成 }, onHide: function () { console.log('onHide'); // clearInterval(this.data.timer); }, onUnload: function () { console.log('onunload'); }, });