litian
2024-03-29 4b5f1f7ed3460df9465e5071a59b8105cbc9146e
pages/personalCenter/index.js
@@ -1,80 +1,97 @@
const app = getApp()
const menuData = [
  {
const app = getApp();
import {
  loginInfo
} from '../../assets/js/login';
const menuData = [{
    title: '我的订单',
    icon: '/static/images/personal/order.png',
    url: '/pages/personalCenter/myOrder/index',
    url: '/packagePersonal/pages/myOrder/index',
    type: 'order',
  },
  {
    title: '激活商品',
    icon: '/static/images/personal/jihuo.png',
    url: '/pages/personalCenter/activateProduct/index',
    url: '/packagePersonal/pages/activateProduct/index',
    type: 'activateProduct',
  },
  {
    title: '我的证书',
    icon: '/static/images/personal/certificate.png',
    url: '/pages/personalCenter/certificate/index',
    url: '',
    type: 'certificate',
  },
  {
    title: '我的收藏',
    icon: '/static/images/personal/wodeshoucang.png',
    url: '/pages/personalCenter/myCollection/index',
    url: '/packagePersonal/pages/myCollection/index',
    type: 'collection',
  },
  {
    title: '我的下载',
    icon: '/static/images/personal/download.png',
    url: '/pages/personalCenter/downloads/index',
    url: '/packagePersonal/pages/downloads/index',
    type: 'download',
  },
  {
    title: '样书申请',
    icon: '/static/images/personal/yangshushenqing.png',
    url: '/pages/personalCenter/sampleBooks/index',
    url: '/packagePersonal/pages/sampleBooks/index',
    type: 'sampleBook',
  },
  {
    title: '出书申请',
    icon: '/static/images/personal/chushu.png',
    url: '/pages/personalCenter/publishBooks/index',
    type: 'publishBooks',
  },
  {
    title: '我的上传',
    icon: '/static/images/personal/upload.png',
    url: '',
    type: 'upload',
  },
  {
    title: '出书申请',
    icon: '/static/images/personal/chushu.png',
    url: '/packagePersonal/pages/publishBooks/index',
    type: 'publishBooks',
  }
];
const moreMenu = [
  {
const moreMenu = [{
    title: '我的消息',
    icon: '/static/images/personal/notification.png',
    url: '/pages/personalCenter/myMassage/index',
    url: '/packagePersonal/pages/myMassage/index',
    type: 'message',
  },
  {
    title: '建议与反馈',
    icon: '/static/images/personal/feedback.png',
    url: '/pages/personalCenter/feedback/index',
    url: '/packagePersonal/pages/feedBack/index',
    type: 'feedback',
  }
];
const moreMenu1 = [
  {
const moreMenu1 = [{
    title: '关于我们',
    icon: '/static/images/personal/about.png',
    url: '',
    url: '/packagePersonal/pages/aboutUs/index?types=jsek_aboutUs',
    type: 'aboutUs',
  },
  {
    title: '联系我们',
    icon: '/static/images/personal/contact.png',
    url: '',
    url: '/packagePersonal/pages/aboutUs/index?types=jsek_contactUs',
    type: 'contact',
  }
];
const userTypeList = [{
    lable: '中职教师',
    value: 'vocSchoolTeachers'
  },
  {
    lable: '高职教师',
    value: 'vocCollegeTeachers'
  },
  {
    lable: '普通高校教师',
    value: 'ordUniversityTeachers'
  },
  {
    lable: '其他读者',
    value: 'otherReaders'
  }
];
Page({
@@ -83,14 +100,13 @@
   * 页面的初始数据
   */
  data: {
    show: false,
    userInfo: {
      avatarUrl:
        'https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/avatar/avatar-1.jpg',
      nickName: 'TDesign',
      phoneNumber: '13438358888',
    },
    barHeight: '',
    navBarHeight: '',
    isWhite: false,
    userInfo: {},
    currAuthStep: 1,
    userTypeActive: '',
    userTypeList,
    teacherState: {
      state: '',
      reasonTxt: '',
@@ -98,53 +114,126 @@
    integral: 0,
    menuData,
    moreMenu,
    moreMenu1
    moreMenu1,
    visible: false,
    baseRefresh: {
      value: false
    },
    loadingProps: {
      size: '50rpx',
    },
    scrollTop: 0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (wx.getStorageSync(app.config.userInfoKey)) {
      this.setData({
        show: true,
        userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
      })
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          selected: 4 //这个数字是当前页面在tabBar中list数组的索引
        })
      }
      if (this.data.userInfo) {
        this.getTeacherInfo()
      }
    }
  },
  /**
 * 生命周期函数--监听页面隐藏
 */
  onHide() {
  onLoad() {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      show: false
    })
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
  },
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        active: 4
      })
    }
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          this.setData({
            currAuthStep: 2,
          });
          this.getUserInfo()
        }
      })
    } else {
      this.setData({
        currAuthStep: 1,
      });
      this.getUserInfo()
    }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.init();
    this.setData({
      'baseRefresh.value': true,
    })
    this.getUserInfo()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  onReachBottom() {},
  // 获取登录用户身份
  getUserInfo() {
    app.MG.identity.getCurrentAppUser().then(res => {
      // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
      if (res) {
        //获取用户类型
        let userTypeData = res.infoList.find((item) => item.type == 'userType')
        let type = "";
        if (userTypeData) {
          this.setData({
            userTypeActive: JSON.parse(userTypeData.data).userType,
          });
          type = userTypeList.find((item) => item.value === this.data.userTypeActive)?.lable;
        } else {
          type = ''
        }
        let defaultUser = {};
        let nickNameData = res.infoList.find((item) => item.type == 'nickName')
        let teacherRole = res.roleLinks.find((item) => item.role.refCode == 'teacher')
        let teacherInfos = res.infoList.find((item) => item.type == 'teacherInfo')
        let WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
        if (teacherRole && teacherInfos) {
          defaultUser = {
            ...teacherInfos,
            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name,
            icon: nickNameData && JSON.parse(nickNameData.data).icon ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon,
            userId: res.userId,
            role: 'Teacher',
            roleId: teacherRole.role.id,
            userType: type
          }
          this.setData({
            currAuthStep: 2,
          });
        } else if (WeChatInfo) {
          defaultUser = {
            ...WeChatInfo,
            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name,
            icon: nickNameData && JSON.parse(nickNameData.data).icon ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon,
            userId: res.userId,
            userType: type,
            role: 'Student',
          }
          this.setData({
            currAuthStep: 3,
          });
        }
        this.setData({
          userInfo: defaultUser
        })
        this.getTeacherInfo()
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
        setTimeout(() => {
          this.setData({
            'baseRefresh.value': false,
          })
        }, 500);
      }
    });
  },
  //教师信息
  getTeacherInfo() {
@@ -159,7 +248,7 @@
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      const resData = res.datas.find((i) => i.appUserCreator.userId == userId.value)
      const resData = res.datas.find((i) => i.appUserCreator.userId == this.data.userInfo.userId)
      if (resData) {
        this.setData({
          teacherState: {
@@ -170,11 +259,67 @@
      }
    })
  },
  //教师认证
  toCertification() {
    wx.navigateTo({
      url: "/packageDomain/pages/teacherCertification/index",
    });
  },
  //修改用户类型
  editUserType() {
    if (!this.data.visible) {
      this.setData({
        visible: true,
      });
    }
  },
  onVisibleChange(e) {
    this.setData({
      visible: e.detail.visible,
    });
  },
  tabUserTypeClick(e) {
    let {
      info
    } = e.currentTarget.dataset;
    this.setData({
      userTypeActive: info.value,
    });
  },
  submit() {
    let userTypeInfo = {
      requests: [{
        data: JSON.stringify({
          userType: this.data.userTypeActive
        }),
        name: '用户类型',
        type: 'userType'
      }]
    }
    app.MG.identity.setAppUserInfo(userTypeInfo).then((res) => {
      if (res) {
        wx.showToast({
          title: "修改成功",
          icon: 'success',
          duration: 1000,
        })
        this.getUserInfo()
        this.setData({
          visible: false,
        });
      }
    })
  },
  //设置
  gotoUserEditPage() {
    wx.navigateTo({
      url: "/packagePersonal/pages/userSetting/index",
    });
  },
  //点击目录
  toPages(item) {
    console.log(item)
    let info = item.target.dataset.info
    let info = item.currentTarget.dataset.info
    if (info.url) {
      wx.navigateTo({
        url: info.url
@@ -188,10 +333,23 @@
    }
  },
  onScroll(e) {
    this.setData({
      isWhite: e.detail.scrollTop > 10 ? true : false
    })
    const {
      scrollTop
    } = e.detail;
    this.setData({
      scrollTop
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }
  },
})