const app = getApp(); const api = require("../../../request/api"); const http = require("../../../request/http"); const utils = require("../../../utils/util.js"); const storeKeys = require("../../../utils/storageKeys.js"); Page({ data: { showModal: false, //是否显示奖励金说明弹窗 showWithdrawalModal: false, //是否显示提现提示 showNicknameModal: false, isLoading: true, //是否处于加载 sHome: false, isLogOn: false, //是否已登录 info: {}, todoCounts: {}, //待处理订单数 updatingNickname: "", }, onLoad: function (options) {}, onShow() { if (!utils.getStorageSync(storeKeys.TOKEN)) { this.setData({ isLogOn: false, isLoading: false, }); } else { this.setData({ isLogOn: true, }); this.getUserInfo(); this.getTodoCounts(); } this.changePageHaed(); app.changeTabBarBadge(utils.getStorageSync(storeKeys.CARETOTAl)); }, changePageHaed() { let token = utils.getStorageSync(storeKeys.TOKEN); if (token) { if (this.data.info.chara) { wx.setNavigationBarColor({ frontColor: "#ffffff", backgroundColor: "#DF3120", }); } else { wx.setNavigationBarColor({ frontColor: "#000000", backgroundColor: "#F7F7F7", }); } } else { wx.setNavigationBarColor({ frontColor: "#000000", backgroundColor: "#F7F7F7", }); } }, //获取用户信息 getUserInfo() { http.request({ url: api.URL + "/api/user/info", method: "GET", token: utils.getStorageSync(storeKeys.TOKEN), success: res => { let info = res.data.data.userInfo; // 开发专用 if (info.mobile == "17573207179") { // info.show_cash_box = true; // info.role = 1; // info.seller_grade = 3; info.grade_id = 10001; info.is_pickup = 1; } //是否为特殊身份 let chara = false; if ((info.role && info.role != 1) || info.show_cash_box) { chara = true; } info.chara = chara; utils.setStorageSync(storeKeys.USERINFO, info); this.setData({ info, }); this.changePageHaed(); setTimeout(() => { this.setData({ isLoading: false, }); }, 300); }, error: res => { utils.toast(res.data.message); }, }); }, //获取用户待处理订单数 getTodoCounts() { http.request({ url: api.URL + "/api/order/todoCounts", method: "GET", token: utils.getStorageSync(storeKeys.TOKEN), success: res => { this.setData({ todoCounts: res.data.data.counts || {}, }); }, error: res => { utils.toast(res.data.message); }, }); }, navigateTo(e) { app.navigateTo(e); }, //需要登陆进入的页面 navigateToToken: utils.throttle(function (e) { if (utils.getStorageSync(storeKeys.TOKEN)) { app.navigateTo(e); } else { wx.navigateTo({ url: "/pages/tabBar/login/login", }); } }), //提现 withdrawal: utils.throttle(function (e) { if (utils.getStorageSync(storeKeys.TOKEN)) { let ktxyj_amount = parseFloat(this.data.info.ktxyj_amount); if (!ktxyj_amount || ktxyj_amount <= 0) { utils.toast("暂无可提现金额"); return; } wx.navigateTo({ url: "/pages/user/pages/withdrawal/withdrawal", }); } else { wx.navigateTo({ url: "/pages/tabBar/login/login", }); } }), //前往分销中心 goTopPomotionCenter: utils.throttle(function (e) { let role = this.data.info.role; //1 :普通用户 let url = "/pages/user/pages/store/promotionCenter/promotionCenter?role=" + role; if (role == 1) { url = "/pages/user/pages/store/applyRetail/applyRetail"; } wx.navigateTo({ url: url, }); }), //显示奖励金说明弹窗 showModal() { this.setData({ showModal: true, }); }, //隐藏奖励金说明弹窗 hideModal() { this.setData({ showModal: false, }); }, //显示提现提示 showWithdrawalModal() { this.setData({ showWithdrawalModal: true, }); }, //隐藏提现提示 hideWithdrawalModal() { this.setData({ showWithdrawalModal: false, }); }, //前往我的分享码 goToPoster: utils.throttle(function (e) { let url = "/pages/user/pages/appletIncomePoster/appletIncomePoster"; wx.navigateTo({ url: url, }); }), //授权获取微信信息 getUserProfile: utils.throttle(function (e) { wx.getUserProfile({ desc: "用于头像展示", success: res => { this.updateUserInfo(res.userInfo.avatarUrl, res.userInfo.nickName); }, }); }), updateUserInfo(avatarUrl, nickName, updateType = "") { let data = { avatarUrl, nickName, ...(updateType ? { type: updateType } : {}), }; wx.showLoading({ title: "加载中", mask: true, }); http.request({ url: api.URL + "/api/user/upd", method: "POST", token: utils.getStorageSync(storeKeys.TOKEN), data, success: res => { wx.hideLoading(); this.getUserInfo(); }, error: res => { wx.hideLoading(); utils.toast(res.data.message); }, }); }, //开通会员、前往会员中心 memberClick: utils.throttle(function (e) { //is_member 是否为会员 1是 0否 if (this.data.info.is_member == 1) { wx.navigateTo({ url: "/pages/member/pages/memberCenter/memberCenter", }); } else { wx.navigateTo({ url: "/pages/member/pages/buyMember/buyMember", }); } }), // 福利核销 clickScanCode: utils.throttle(function (e) { console.log("福利核销"); let _this = this; wx.scanCode({ success(res) { console.log(res); let result = res.result; try { wx.navigateTo({ url: "/pages/member/pages/writeOff/writeOff?hxCode=" + result, }); } catch (e) { utils.toast("二维码错误"); } }, fail() {}, }); }), showNicknameInputModal() { this.setData({ updatingNickname: this.data.info.nickName || "", showNicknameModal: true, }); }, hideNicknameModal() { this.setData({ showNicknameModal: false, }); }, updateNickName() { this.updateUserInfo("", this.data.updatingNickname, "1"); this.hideNicknameModal(); }, onChooseAvatar(e) { const { avatarUrl } = e.detail; const _this = this; wx.showLoading({ title: "上传中", mask: true, }); wx.uploadFile({ url: api.URL + "/api/upload/image", filePath: avatarUrl, name: "file", header: { "Access-Token": utils.getStorageSync(storeKeys.TOKEN), }, success: function (res) { let data = JSON.parse(res.data); //重新上传 wx.showToast({ title: "上传成功", icon: "success", duration: 1500, }); _this.updateUserInfo(data.data.fileInfo.preview_url, "", "2"); wx.hideLoading(); }, error: function (error) { wx.showToast({ title: "上传失败", icon: "error", duration: 1500, }); wx.hideLoading(); }, }); }, });