yiming
2024-04-11 a9bd2df4da1cf7b198db7bf2d67ce8adbbe89b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
const app = getApp();
import {
  loginInfo
} from '../../assets/js/login';
const menuData = [{
    title: '我的订单',
    icon: '/static/images/personal/order.png',
    url: '/packagePersonal/pages/myOrder/index',
    type: 'order',
  },
  {
    title: '激活商品',
    icon: '/static/images/personal/jihuo.png',
    url: '/packagePersonal/pages/activateProduct/index',
    type: 'activateProduct',
  },
  {
    title: '我的证书',
    icon: '/static/images/personal/certificate.png',
    url: '',
    type: 'certificate',
  },
  {
    title: '我的收藏',
    icon: '/static/images/personal/wodeshoucang.png',
    url: '/packagePersonal/pages/myCollection/index',
    type: 'collection',
  },
  {
    title: '我的下载',
    icon: '/static/images/personal/download.png',
    url: '/packagePersonal/pages/downloads/index',
    type: 'download',
  },
  {
    title: '样书申请',
    icon: '/static/images/personal/yangshushenqing.png',
    url: '/packagePersonal/pages/sampleBooks/index',
    type: 'sampleBook',
  },
  {
    title: '我的上传',
    icon: '/static/images/personal/upload.png',
    url: '',
    type: 'upload',
  },
  {
    title: '出书申请',
    icon: '/static/images/personal/chushu.png',
    url: '',
    type: 'publishBooks',
  }
];
const moreMenu = [{
    title: '我的消息',
    icon: '/static/images/personal/notification.png',
    url: '/packagePersonal/pages/myMassage/index',
    type: 'message',
  },
  {
    title: '建议与反馈',
    icon: '/static/images/personal/feedback.png',
    url: '/packagePersonal/pages/feedBack/index',
    type: 'feedback',
  }
];
const moreMenu1 = [{
    title: '关于我们',
    icon: '/static/images/personal/about.png',
    url: '/packagePersonal/pages/aboutUs/index?types=jsek_aboutUs',
    type: 'aboutUs',
  },
  {
    title: '联系我们',
    icon: '/static/images/personal/contact.png',
    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({
 
  /**
   * 页面的初始数据
   */
  data: {
    barHeight: '',
    navBarHeight: '',
    scoll: false,
    isWhite: false,
    userInfo: {},
    currAuthStep: 1,
    userTypeActive: '',
    userTypeList,
    teacherState: {
      state: '',
      reasonTxt: '',
    },
    integral: 0,
    menuData,
    moreMenu,
    moreMenu1,
    visible: false,
    baseRefresh: {
      value: false
    },
    loadingProps: {
      size: '50rpx',
    },
    scrollTop: 0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      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: 3,
      });
      this.getUserInfo()
    }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      'baseRefresh.value': true,
    })
    this.getUserInfo()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  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
        })
        this.getTeacherInfo()
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
        setTimeout(() => {
          this.setData({
            'baseRefresh.value': false,
          })
        }, 500);
      }
    });
  },
  //教师信息
  getTeacherInfo() {
    const data = {
      start: 0,
      size: 10,
      topicIdOrRefCode: 'teacherRoleApproval',
      appRefCode: app.config.appRefCode,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      const resData = res.datas.find((i) => i.appUserCreator.userId == this.data.userInfo.userId)
      if (resData) {
        this.setData({
          teacherState: {
            state: resData.state,
            reasonTxt: resData.feedBack != null ? JSON.parse(resData.feedBack).reason : ''
          }
        })
      }
    })
  },
  //教师认证
  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) {
    let info = item.currentTarget.dataset.info
    if (info.url) {
      wx.navigateTo({
        url: info.url
      })
    } else {
      wx.showToast({
        title: "建设中",
        icon: 'none',
        duration: 2000
      })
    }
  },
 
  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
    })
  },
 
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  },
})