let util = require('../../../utils/util.js'); var that Page({ /** * 页面的初始数据 */ data: { paydata: {} }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { // console.log(wx.getStorageSync("userinfo").id) that = this // options = { // num: 10, // year: 2, // pid: 1, // name: 'aaa', // currentPrice: 0.01, // originalPrice: 100 // } this.setData({ paydata: { packageNum: options.num, packageYears: options.year, memberPackage: { id: options.pid } }, showdata: { name: options.name, currentPrice: options.currentPrice, originalPrice: options.originalPrice, } }) }, freshmyinfo() { util.query('userinfo/wxapi/findbyid', { id: wx.getStorageSync("userinfo").id }, function(e) { wx.setStorage({ key: 'userinfo', data: e.data, }) }) }, buy() { util.query('memberOrder/wxapi/create', this.data.paydata, function(d) { if (d.code === 10000) { wx.requestPayment({ 'timeStamp': d.data.timeStamp + "", 'nonceStr': d.data.nonceStr, 'package': d.data.packageValue, 'signType': 'MD5', 'paySign': d.data.paySign, 'success': function(res) { console.log(res); if (res.errMsg == "requestPayment:ok") { util.showToast('支付成功') that.freshmyinfo() setTimeout(function() { wx.switchTab({ url: '/pages/myinfo/myinfo/myinfo', }) }, 2000) } }, 'fail': function(res) { util.showToast('支付失败') }, 'completev': function(res) { // if (res.requestPayment == "cancel") { // common.showToast('支付取消1') // } } }) } }, 'POST') }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })