From 04c7b0163caeae4ab1c5da62e301fa993101cfad Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 31 三月 2025 10:40:45 +0800
Subject: [PATCH] bug修改

---
 pages/personalCenter/index.js |  377 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 310 insertions(+), 67 deletions(-)

diff --git a/pages/personalCenter/index.js b/pages/personalCenter/index.js
index e086528..341ca0e 100644
--- a/pages/personalCenter/index.js
+++ b/pages/personalCenter/index.js
@@ -1,80 +1,113 @@
-const app = getApp()
-const menuData = [
-  {
+const app = getApp();
+import moment from 'moment'
+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: '',
     url: '/pages/personalCenter/certificate/index',
     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: '',
+    // url: '',
+    url: '/pages/personalCenter/myUpload/index',
     type: 'upload',
+  },
+  {
+    title: '鍑轰功鐢宠',
+    icon: '/static/images/personal/chushu.png',
+    // url: '',
+    url: '/packagePersonal/pages/publishBooks/index',
+    type: 'publishBooks',
+  },
+  {
+    title: '鎴戠殑璇剧▼',
+    icon: '/static/images/personal/course.png',
+    url: '/packageCourse/pages/course/index',
+    type: 'course',
+  },
+  {
+    title: '鎴戠殑鐝骇',
+    icon: '/static/images/personal/class.png',
+    url: '/packageCourse/pages/studentClass/index',
+    type: 'class',
   }
 ];
-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 +116,14 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   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: '',
+    scoll: false,
+    isWhite: false,
+    userInfo: {},
     currAuthStep: 1,
+    userTypeActive: '',
+    userTypeList,
     teacherState: {
       state: '',
       reasonTxt: '',
@@ -98,53 +131,159 @@
     integral: 0,
     menuData,
     moreMenu,
-    moreMenu1
+    moreMenu1,
+    visible: false,
+    baseRefresh: {
+      value: false
+    },
+    loadingProps: {
+      size: '10rpx',
+    },
+    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涓璴ist鏁扮粍鐨勭储寮�
-        })
-      }
-      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()
+          this.getIntegral()
+        } else {
+          wx.switchTab({
+            url: '/pages/home/home',
+          })
+        }
+      })
+    } else {
+      this.setData({
+        currAuthStep: 3,
+      });
+      this.getUserInfo()
+      this.getIntegral()
+    }
   },
   /**
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
    */
   onPullDownRefresh() {
-    this.init();
+    this.setData({
+      'baseRefresh.value': true,
+    })
+    this.getUserInfo()
+    this.getIntegral()
+    wx.stopPullDownRefresh()
   },
   /**
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
    */
-  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 = this.data.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");
+        let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword')
+        if (teacherRole && teacherInfos) {
+          defaultUser = {
+            ...teacherInfos,
+            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo ? WeChatInfo.name : '',
+            icon: nickNameData && JSON.parse(nickNameData.data).icon != "" ? JSON.parse(nickNameData.data).icon : WeChatInfo ? 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,
+          });
+        } else if (secretData) {
+          defaultUser = {
+            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : secretData.credential,
+            icon: nickNameData && JSON.parse(nickNameData.data).icon != "" ? JSON.parse(nickNameData.data).icon : "",
+            userId: res.userId,
+            role: "Student",
+            userType: type,
+          }
+          this.setData({
+            currAuthStep: 3,
+          });
+        }
+        this.setData({
+          userInfo: defaultUser
+        })
+        if (defaultUser?.role == 'Teacher') {
+          const data = [...this.data.menuData]
+          const list = data.filter(item => item.type != 'class')
+          this.setData({
+            menuData: list
+          })
+        } else {
+          const data = [...this.data.menuData]
+          const list = data.filter(item => item.type != 'course')
+          this.setData({
+            menuData: list
+          })
+        }
+        this.getTeacherInfo()
+        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
+        setTimeout(() => {
+          this.setData({
+            'baseRefresh.value': false,
+          })
+        }, 500);
+      }
+    });
   },
   //鏁欏笀淇℃伅
   getTeacherInfo() {
@@ -159,7 +298,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 +309,86 @@
       }
     })
   },
+  //鏁欏笀璁よ瘉
+  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",
+    });
+  },
+
+  getIntegral() {
+    app.MG.store
+      .getUserWallet({
+        type: 'integral'
+      })
+      .then((res) => {
+        this.setData({
+          integral: res.balance,
+        });
+      })
+  },
+  getIntegralList() {
+    wx.navigateTo({
+      url: `/pages/personalCenter/pointsRecord/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 +402,39 @@
     }
   },
 
+  onScroll(e) {
+    if (this.data.scoll) {
+      if (e.detail.scrollTop < 20) {
+        this.data.scoll = false
+        this.isChange(false);
+      }
+    } else {
+      if (e.detail.scrollTop > 20) {
+        this.data.scoll = true
+        this.isChange(true);
+      }
+    }
+  },
+
+  isChange(data) {
+    this.setData({
+      isWhite: data
+    })
+  },
+  // delectBtn() {
+  //   app.MG.ugc
+  //     .delTopicMessage({
+  //       messageIds: [2986, 1302, 1301, 3074, 1305, 1304]
+  //     })
+  //     .then((res) => {
+  //       console.log('鍒犻櫎鎴愬姛')
+  //     })
+  // },
+
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
   onShareAppMessage() {
 
-  }
+  },
 })
\ No newline at end of file

--
Gitblit v1.9.1