// pages/pay/index.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { id: 106, info: null, temps: [], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { var that = this; console.log(options); this.setData({ id: options.id }) this.getTemps(); this.getData(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { var that = this; app.ajaxReadyCallback = res => { //各个接口统一回调方法 var apiname = res.data.apiname; if(apiname == 'pay'){ console.log(res.data.data); that.setData({ info: res.data.data }) }else if(apiname == 'temps'){ if(res.data.data.temps.length > 0){ that.setData({ temps: res.data.data.temps }); wx.showModal({ title: '温馨提示', content: res.data.data.tips, confirmText: "同意", cancelText: "拒绝", complete: (res) => { if (res.cancel) { } if (res.confirm) { that.paySubscribe(); } } }) } } }; }, paySubscribe(){ let that = this; if(that.data.temps.length > 0){ wx.requestSubscribeMessage({ tmplIds: that.data.temps, success (res) { console.log('temp',res); }, fail(res){ console.log('fail',res); }, complete(){ // that.pay(); } }); } }, getData:function(){ app.ajax({ url: app.globalData.serverUrl + 'PhOrders/pay', type: 'POST', apiname: 'pay', data: { payId: this.data.id } }); }, getTemps:function(){ app.ajax({ url: app.globalData.serverUrl + 'PhOrders/temps', type: 'POST', apiname: 'temps', }); }, pay(){ // let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam()); // wx.navigateTo({ // url: '/pages/webview/index?url='+url // }); wx.requestPayment({ timeStamp: this.data.info.timestamp, nonceStr: this.data.info.noncestr, package: this.data.info.package, signType: this.data.info.signtype, paySign: this.data.info.paysign, success (res) { let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam()); wx.navigateTo({ url: '/pages/webview/index?url='+url }); }, fail (res) { wx.showToast({ title: '支付调用失败', icon: 'none', duration: 2000 }) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })