123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // pages/buyVip/buyVip.js
- var http = require('../../../utils/http.js');
- var config = require('../../../utils/config.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- duration: 1000,
- userInfo: {},
- userLevelInfo: {}, // 当前会员信息
- premiumVipList: [], // 付费会员等级列表
- currentLevelId: 0,
- selectPremiumVip: {},
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- // 获取会员信息
- this.getUserLevelInfo()
- // 获取年费会员列表
- this.getPayMemberList()
- this.setData({
- userInfo: wx.getStorageSync('loginResult')
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- this.setData({
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 获取当前会员信息
- */
- getUserLevelInfo() {
- var params = {
- url: '/p/score/scoreLevel/page',
- method: 'GET',
- data: {
- levelType: 0
- },
- callBack: res => {
- this.setData({
- userLevelInfo: res,
- currentLevelId: res.userLevel.id,
- currentGrowth: res.growth
- })
- }
- }
- http.request(params)
- },
- /**
- * 获取年费会员列表
- */
- getPayMemberList() {
- var params = {
- url: '/p/score/scoreLevel/page',
- method: 'GET',
- data: {
- levelType: 1
- },
- callBack: res => {
- this.setData({
- premiumVipList: res.userLevels,
- selectPremiumVip: res.userLevels[0],
- })
- }
- }
- http.request(params)
- },
- /**
- * 立即购买- 根据当前付费会员id
- */
- buyNow() {
- if (this.data.currentGrowth < this.data.selectPremiumVip.needGrowth){
- return wx.showToast({
- title: '成长值不足,无法购买',
- icon: 'none'
- })
- }
- if (this.data.userLevelInfo.levelType != 0 && this.data.userLevelInfo.userLevel.level < this.data.selectPremiumVip.level) {
- // 已有付费会员时购买付费会员
- wx.showModal({
- title: '提示',
- content: `您当前为${this.data.userLevelInfo.userLevel.levelName},即将购买${this.data.selectPremiumVip.levelName},升级会员将覆盖当前会员时限,是否确认购买?`,
- success: res => {
- if (res.confirm) {
- this.buyVip()
- } else {
- }
- }
- })
- return
- }
- this.buyVip()
- },
- /**
- * 购买会员
- */
- buyVip(){
- var ths = this
- var params = {
- url: '/p/level/payLevel',
- method: 'POST',
- data: {
- id: this.data.selectPremiumVip.id,
- scene: '',
- payType: 1, //支付方式 (1:微信小程序支付 2:支付宝 3微信扫码支付 4 微信h5支付)
- },
- callBack: res => {
- // 微信支付返回参数
- wx.requestPayment({
- timeStamp: res.timeStamp,
- nonceStr: res.nonceStr,
- package: res.packageValue,
- signType: res.signType,
- paySign: res.paySign,
- appId: res.appId,
- success: e => {
- console.log("支付成功");
- wx.showModal({
- title: '提示',
- content: '购买成功',
- showCancel: false,
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- ths.getUserLevelInfo()
- }
- }
- })
- },
- fail: err => {
- console.log("支付失败");
- wx.showModal({
- title: '提示',
- content: '支付失败,请重新支付',
- showCancel: false,
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- ths.getUserLevelInfo()
- }
- }
- })
- }
- })
- }
- }
- http.request(params)
- },
- /**
- * 切换轮播图
- */
- selectVip(e) {
- this.setData({
- selectPremiumVip: this.data.premiumVipList[e.detail.current]
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|