123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import {BASE_URL} from '../../utils/request';
- import { uploadImage } from '../../utils/upload.js';
- import { MAKE_PHONE_CALL } from '../../utils/util.js';
- import { userModify } from '../../api/user';
- import { isLoggedIn, doLogin } from '../../utils/auth';
- const app = getApp();
- Page({
- data: {
- menuList: [
- { icon: '/static/image/me-1.png', title: '活动规则' },
- { icon: '/static/image/me-2.png', title: '免责声明' },
- { icon: '/static/image/me-3.png', title: '报名记录' },
- { icon: '/static/image/me-4.png', title: '优惠券' },
- { icon: '/static/image/me-5.png', title: '设置' },
- // { icon: '/static/image/me-5.png', title: '参赛管理' },
- { icon: '/static/image/me-6.png', title: '联系客服' }
- ],
- userInfo: {},
- programConfig:{},
- baseUrl:BASE_URL,
- loggedIn: isLoggedIn()
- },
- onLoad(options) {
- this.setData({
- userInfo: app.globalData.userInfo,
- programConfig: app.globalData.programConfig
- });
- },
- onShow() {
- if (typeof this.getTabBar === 'function' && this.getTabBar()) {
- this.getTabBar().setData({ selected: 2 })
- }
- this.setData({
- userInfo: app.globalData.userInfo,
- loggedIn: isLoggedIn()
- });
- },
- goPage(e){
- const index = e.currentTarget.dataset.index;
- const pageMap = {
- 0: `/pages/rules/rules?type=${index}`,
- 1: `/pages/rules/rules?type=${index}`,
- 2: `/pages/registrationRecords/registrationRecords`,
- 3: `/pages/coupon/coupon`,
- 4: `/pages/setting/setting`
- };
- if (pageMap[index]) {
- wx.navigateTo({ url: pageMap[index] });
- } else if (index === 5) {
- const tabbar = this.getTabBar && this.getTabBar();
- if (tabbar && tabbar.openShowAgreementModal) {
- tabbar.openShowAgreementModal()
- }
- }
- },
- // 头像选择
- async onChooseAvatar(e) {
- const { avatarUrl } = e.detail;
- const res = await uploadImage(avatarUrl);
- this.setData({ "userInfo.avatar": avatarUrl });
- this.onSave(res.path);
- },
- async onSave(pathUrl) {
- const res = await userModify({ avatar: pathUrl });
- if(res.code == 200){
- app.globalData.userInfo = res.data;
- } else {
- wx.showToast({
- title: res.message || '更新失败',
- icon: 'none',
- duration: 2000
- });
- }
- },
- onPhone() {
- MAKE_PHONE_CALL(this.data.programConfig.customer_phone);
- },
- handleActionWithLogin(e) {
- const index = e.currentTarget.dataset.index;
- if (index >= 2 && index <= 4 && !isLoggedIn()) {
- return;
- }
- this.doAction(index);
- },
- async onGetPhoneNumber(e) {
- const index = e.currentTarget.dataset.index;
- if (e.detail.errMsg !== 'getPhoneNumber:ok') {
- wx.showToast({ title: '授权失败', icon: 'none' });
- return;
- }
- const { encryptedData, iv } = e.detail;
- try {
- wx.login({
- success: async loginRes => {
- await doLogin({
- code: loginRes.code,
- phone: { encryptedData, iv }
- });
- this.setData({ loggedIn: true });
- this.doAction(index);
- }
- });
- } catch (err) {
- wx.showToast({ title: '登录失败,请重试', icon: 'none' });
- console.error(err);
- }
- },
- doAction(index) {
- this.goPage({ currentTarget: { dataset: { index } } });
- },
- })
|