123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- import {
- get,
- post
- } from '../../utils/http'
- import {
- formatActivity
- } from '../../utils/time'
- Page({
-
- data: {
- userInfo: {},
- agree: false,
- visible: false,
- sum: 0,
- activity: {},
- needReqActivity: true,
- inserllAmount: 0,
- inserllAmountLittle: '00',
- CardDiscount: '',
- goods_discount: '',
- level: '',
- levelList: {
- 1: '0.98',
- 4: '0.95',
- 7: '0.90',
- },
- levelImage: ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%205%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%202%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%207%402x.png']
- },
-
- onLoad: function (options) {
- },
-
- onReady: function () {},
-
- onShow: function () {
-
- this.getLevel()
- this.getUser()
- this.getAmount()
- this.getCoin()
- if (wx.getStorageSync('token') && this.data.needReqActivity) {
- this.getUserActivity()
- }
- this.setData({
- agree: wx.getStorageSync('agree') || false
- })
- },
-
- onHide: function () {},
-
- onUnload: function () {
- if (this.timer_) {
- clearInterval(this.timer_)
- }
- },
-
- onPullDownRefresh: function () {},
-
- onReachBottom: function () {},
-
- onShareAppMessage: function () {},
-
- onAvatar() {
- this.data.sum++
- if (this.data.sum >= 10) {
- this.setData({
- visible: true,
- sum: 0
- })
- }
- },
-
- getLevel() {
- get('/v2/api/user/discount_level', {}, (res) => {
- let arr = [1,4,7]
- let index = arr.findIndex(item=>{
- return item==res.data
- })
- this.setData({
- imageIndex:index
- })
- if (res.code == 200) {
- if (res.data == 0) {
- this.setData({
- level: 0
- })
- return
- }
- let getValue = (item, val) => {
- return item[val]
- }
- this.setData({
- level: Number(getValue(this.data.levelList, res.data))
- })
- }
- })
- },
-
- getUser() {
- get('api/user', {}, (res) => {
- if (res.data) {
- this.setData({
- userInfo: res.data,
- goods_discount: res.data.goods_discount
- }, )
- wx.setStorageSync('userInfo', res.data)
- }
- })
- },
-
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount.split('.')[0],
- inserllAmountLittle: res.data.amount.split('.')[1],
- })
- }
- })
- },
-
- getCoin() {
- get('api/user/coin', {}, (res) => {
- if (res.data) {
- this.setData({
- coin: res.data.coin_num
- })
- }
- })
- },
-
- goToVip() {
- console.log(this.data.userInfo)
- let nextDatas = JSON.stringify(this.data.userInfo)
- wx.navigateTo({
- url: `/pages/vip/vip?userInfo=${encodeURIComponent(nextDatas)}`
-
-
- })
- },
-
- getUserActivity() {
- if (this.timer) {
- clearInterval(this.timer_)
- }
- get('api/user/activity', {}, (res) => {
- this.data.needReqActivity = false
- if (res.data) {
- res.data.currentTime = formatActivity(res.data.expire_time_seconds)
- this.setData({
- activity: res.data
- })
- this.timer_ = setInterval(() => {
- if (res.data.expire_time_seconds <= 0) {
- clearInterval(this.timer_)
- }
- res.data.expire_time_seconds--
- res.data.currentTime = formatActivity(res.data.expire_time_seconds)
- this.setData({
- activity: res.data
- })
- }, 1000)
- }
- })
- },
-
- getCardDiscount() {
- get('', {}, (res) => {
- this.setData({
- CardDiscount: ''
- })
- })
- }
- })
|