const request = require('../../utils/request') //导入模块 const util = require('../../utils/util') const event = require('../../utils/event.js') const app = getApp() Page({ /** * 页面的初始数据 */ data: { backUrl: null, status: null, payType: 0, payIndex: 2, payText: '', payment: '', requesting: false, paymodel: { channelId: '478256441266933760' } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.orderId) { this.data.paymodel.tradeOrderId = options.orderId this.fetchPaymentInfo(options.orderId) this.data.payType = Number(options.type) if (options.url) { this.data.backUrl = options.url } if (options.status) { this.data.status = options.status } } else { util.showToast('数据错误,无法支付') wx.navigateBack({ delta: 1 }) } }, fetchPaymentInfo: function (orderId) { wx.showLoading({ title: '加载中', mask: true }) request.get('/payment-settlement-center/get/payment-order/by-trade-order-id/' + orderId).then(result => { //成功回调 this.setData({ payment: result.data.amount, payText: result.data.comment }) wx.hideLoading() }).catch(err => { //异常回调 wx.hideLoading() util.showToast(err) }) }, checkRadio: function (e) { this.setData({ payIndex: parseInt(e.currentTarget.id) }) }, submitForm: function () { if (this.data.requesting) { return } wx.showLoading({ title: '加载中', mask: true }) this.data.requesting = true request.post('/payment-settlement-center/pay', this.data.paymodel).then(result => { //成功回调 wx.hideLoading() this.requestPayment(result.data.extra) }).catch(err => { //异常回调 wx.hideLoading() this.data.requesting = false util.showToast(err) }) }, // 微信支付流程 requestPayment: function (data) { var that = this data.success = function (res) { util.showToast('支付成功') wx.requestSubscribeMessage({ tmplIds: app.tmplIds, complete(res) { that.handlePayment() } }) } data.fail = function (res) { util.showToast('支付失败') that.data.requesting = false } wx.requestPayment(data) }, handlePayment: function(){ if(this.data.payType == 2){ // Vip购买成功 app.globalData.userInfo.isVIP = 1 event.emit('EventMessage', { what: 200, desc: 'Vip' }) } else if(this.data.payType == 11 || this.data.payType == 14){ event.emit('EventMessage', { what: 320, desc: 'OrderChange' }) } if (!util.isEmpty(this.data.backUrl)) { if (!util.isEmpty(this.data.status)) { this.data.backUrl += '?status=' + this.data.status } wx.redirectTo({ url: this.data.backUrl }) } else if(this.data.payType == 2){ wx.navigateBack({ delta: 1 }) } else if(this.data.payType == 11 || this.data.payType == 14){ this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog') var contentString = '' if(this.data.payType == 11){ contentString = '您已成功支付订单诚意金,请等待卖家上传的商品磅单,并核对磅单信息是否正确' } else { contentString = '您已成功支付尾款,请等待卖家送货,收到货后请及时点击确认收货' } this.wuxDialog.open({ maskClosable: false, title: '温馨提示', content: contentString, buttons: [{ text: '确定', type: 'primary', onTap(e) { wx.navigateBack({ delta: 1 }) } }] }) } } })