123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- const util = require('../../utils/util.js');
- const app = getApp();
- Page({
- data: {
- userInfo: app.globalData.userInfo,
- config: util.config,
- isWallet: 0,
- isGrowup: 0,
- stat: {},
- levelName: '普通',
- flag: "",
- isShow: "1",
- tabbar: {}
- },
- onLoad(options) {
- app.editTabbar();
- let info = wx.getStorageSync('WXuserInfo')
- console.log(info);
- if (!info) {
- this.logion()
- }
- console.log(options);
- if (options.flags) {
- this.setData({
- flag: "false"
- })
- } else {
- this.setData({
- flag: ""
- })
- }
- // this.updateUserInfo();
- },
- onUnload(e) {
- console.log(e);
- this.setData({
- flag: "true"
- })
- },
- onShow() {
- this.setData({ userInfo: app.globalData.userInfo });
- if (this.data.isShow == "1") {
- this.updateUserInfo()
- }
- // this.updateUserInfo();
- },
- // 跳转至宝贝币中心
- jumpPage() {
- if (this.data.userInfo) {
- wx.navigateTo({
- url: '/pages/account/monetaryCenter/index',
- })
- }
- },
- isWallet: function () {
- let that = this, userInfo = app.globalData.userInfo;
- util.ajax({
- func: "v2/user/showCoin",
- data: { "rid": userInfo ? userInfo['rid'] : '' },
- load: false
- }, function (res) {
- if (res.code == 0) {
- that.setData({ isWallet: parseInt(res.data) });
- }
- }, false);
- },
- stat() {
- let that = this;
- util.stat().then(res => {
- let data = util.getCoinLevel(res.allCoin)
- that.setData({ stat: res, levelName: data.levelName });
- })
- },
- isGrowupCard: function () {
- let that = this, userInfo = app.globalData.userInfo;
- util.ajax({
- func: "v2/user/growthCard/center",
- data: { "rid": userInfo ? userInfo['rid'] : '' },
- load: false
- }, function (res) {
- if (res.code == 0) {
- that.setData({ isGrowup: res.data });
- }
- }, false);
- },
- updateUserInfo() {
- let that = this
- let self = this, userInfo = app.globalData.userInfo;
- console.log(userInfo);
- if (util.isObjEmpty(userInfo)) return false;
- util.ajax({
- func: "user/stat_info",
- load: false
- }, function (res) {
- console.log(res.data);
- if (res.code == 0 && res.data) {
- if (self.data.flag == "false") {
- if (res.data.roleType == "sharer") {
- wx.navigateTo({
- url: `/pages/sharingHome/index?organStatus=${2}`,
- })
- } else if (res.data.roleType == "organ") {
- wx.navigateTo({
- url: `/pages/sharingHome/index?organStatus=${1}`,
- })
- } else {
- wx.navigateTo({
- url: '/pages/public/swiper/web?url=https://mp.weixin.qq.com/s/H8WuXW_VeCeWtxQXFBGu2Q&title=宝贝走天下',
- })
- }
- that.setData({
- isShow: "2"
- })
- }
- self.isWallet();
- self.isGrowupCard();
- self.stat();
- res.data.score = Math.round(res.data.score);
- userInfo['role'] = util.userRole(res.data.score);
- userInfo['score'] = res.data.score;
- userInfo['coin'] = res.data.coin;
- userInfo['membered'] = res.data.membered;
- userInfo['roleType'] = res.data.roleType || 'normal';
- userInfo['roleTypeDisable'] = res.data.roleTypeDisable || 0;
- userInfo['babyCoin'] = util.toMoney(res.data.coin, ",");
- userInfo['weixin'] = res.data.weixin || 0;
- app.globalData.userInfo = userInfo;
- wx.setStorageSync("WXuserInfo", userInfo);
- self.setData({ userInfo });
- console.log(self.data.flag);
- }
- });
- },
- navigatorURl(e) {
- let self = this;
- // if (e.currentTarget.dataset.url == '/pages/account/growthCourse/index') {
- // util.ajax({
- // func: "v2/gwcourse/isAttended"
- // }, function (res) {
- // if (res.code == 0) {
- // if (res.data ==1) {
- // util.navigator(e.currentTarget.dataset.url);
- // }else{
- // wx.showModal({
- // content: '购买成长课活动后才可预约成长课',
- // showCancel:false,
- // success (res) {
- // if (res.confirm) {
- // console.log('用户点击确定')
- // }
- // }
- // })
- // }
- // } else{
- // util.showTips(res.reason);
- // }
- // });
- // }else{
- // util.navigator(e.currentTarget.dataset.url);
- // }
- util.navigator(e.currentTarget.dataset.url);
- },
- logion() {
- let that = this
- util.silentLogin().then(res => {
- that.setData({
- userInfo: app.globalData.userInfo
- })
- })
- },
- copy(e) {
- let code = e.currentTarget.dataset.code;
- wx.setClipboardData({
- data: code
- });
- },
- logout() {
- let self = this;
- wx.showModal({
- content: '确定登出吗?',
- success: function (res) {
- if (res.confirm) {
- util.ajax({
- func: "login_out"
- }, function (res) {
- if (res.code == 0) {
- wx.removeStorageSync("WXuserInfo");
- wx.removeStorageSync("nps");
- app.globalData.userInfo = null;
- self.setData({ userInfo: app.globalData.userInfo, isGrowup: 0, isWallet: 0, stat: {} });
- } else
- util.showTips(res.reason);
- });
- }
- }
- });
- },
- onShareAppMessage() {
- return {
- title: '个人中心-我的信息',
- path: '/pages/home/account'
- }
- }
- })
|