纸通宝小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

131 lines
4.5 KiB

// pages/ztbvip/index.js
const request = require('../../../utils/request') //导入模块
const util = require('../../../utils/util')
const events = require('../../../utils/event.js')
import WxCountUp from '../../../utils/countup.js'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight,
userInfo: null,
number: 0,
taskList: null,
pointList: null,
toViewId: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ userInfo: app.globalData.userInfo, height: app.globalData.fragmentHeight })
this.fetchUserInfo()
this.countUp = new WxCountUp('number', 5024, {}, this)
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
},
fetchUserInfo: function () {
wx.showLoading({ title: '处理中', mask: true })
// /user/userInfo 获取用户信息
request.get('/recycle-service/user/get/base-info').then(result => {
app.globalData.userInfo = result.data
this.countUp.update(app.globalData.userInfo.memberRewardPoint)
})
//point-task/get/potn-task/list查询所有积分任务
request.get('/recycle-service/point-task/get/potn-task/list').then(result => {
var shareIndex = -1
for (let index = 0; index < result.data.length; index++) {
const element = result.data[index]
if(element.linkUrlJson && element.linkUrlJson.redirectInfo && element.linkUrlJson.redirectInfo.targetView == 'shareProxyOrder'){
shareIndex = index
break
}
}
if(shareIndex >= 0){
result.data.splice(shareIndex, 1)
}
this.setData({ taskList: result.data })
})
// /point-product/get/point-product-list 查询所有积分产品
request.get('/recycle-service/point-product/get/point-product-list').then(result => {
this.setData({ pointList: result.data })
wx.hideLoading()
}).catch(error => {
wx.hideLoading()
})
},
lookTask: function(event){
var item = this.data.taskList[event.currentTarget.dataset.index]
var targetView = null
if(item.linkUrlJson && item.linkUrlJson.redirectInfo && item.linkUrlJson.redirectInfo.targetView){
targetView = item.linkUrlJson.redirectInfo.targetView
}
if(!targetView){
return
}
if(targetView == 'createShop'){
// 开店铺
wx.redirectTo({ url: '/pages/shop/index/index' })
} else if(targetView == 'updateShopInfo'){
// 完善店铺
wx.redirectTo({ url: '/pages/shop/index/index' })
} else if(targetView == 'createProduct'){
// 发布商品
wx.redirectTo({ url: '/pages/shop/index/index' })
} else if(targetView == 'replyArticle'){
// 回复帖子
events.emit('EventMessage', { what: 250, desc: 'Share' })
wx.navigateBack({ delta: 1 })
} else if(targetView == 'createArticle'){
// 发布帖子
wx.redirectTo({ url: '/pages/article/publish/index' })
}
},
exchangePoint: function(event){
var item = this.data.pointList[event.currentTarget.dataset.index]
if(parseInt(app.globalData.userInfo.memberRewardPoint) < parseInt(item.price)){
util.showToast('您的积分不够,赶快去赚取积分吧')
return
}
if(!app.globalData.userInfo.isAuth){
this.wuxDialog.open({
resetOnClose: true,
title: '温馨提示',
content: '您还没有进行个人信息认证,无法兑换会员,现在去进行个人信息认证?',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateTo({ url: '/pages/home/idcard/index' })
}
}]
})
return
}
wx.showLoading({ title: '处理中', mask: true })
// /point-product/buy/point-product/{id} 购买积分产品
request.get('/recycle-service/point-product/buy/point-product/' + item.id).then(res => {
util.showToast('兑换成功')
app.globalData.userInfo.isVIP = 1
events.emit('EventMessage', { what: 200, desc: 'Vip' })
request.get('/recycle-service/point-product/get/point-product-list').then(result => {
this.setData({ pointList: result.data })
wx.hideLoading()
app.globalData.userInfo.memberRewardPoint -= parseInt(item.price)
this.countUp.update(app.globalData.userInfo.memberRewardPoint)
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
}).catch((e) => {
wx.hideLoading()
})
},
toBottom: function(){
this.setData({toViewId: 'exchangeId'})
}
})