yiming
2024-03-15 2ddff89413a44ca11e26c2210096457a2b65acaa
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
377
378
379
380
381
382
383
const app = getApp();
import tool from "../../assets/js/toolClass.js";
import { getTopicMsgCmsItemFile } from '../../assets/js/middleGround/tool.js'
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    teacherInfo: {
      schoolName: '', //学校名称
      fullName: '', //姓名
      positionalTitle: '', //职称
      courseName: '', //任课教程
      phone: '', //联系电话
      telphone: '', //座机
      email: '', //联系邮箱
      detailedAddress: '', //通讯地址
      relevantCertificates: [], //相关证件
      state: '', //审核状态默认待审核
      agree: false
    },
    teachPosts: [],
    teachText: '',
    teachVisible: false,
    phoneError: false,
    telphoneError: false,
    emailError: false,
    topicMessageList: [],
    topicId: "",
    worksInfo: [],
    userId: '',
    fileList: [],
    protocolTxt: '', //教师协议
    editState: true,
    reasonTxt: ""
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, 111);
    this.getpositionalTitle();
    this.getAgreement();
    if (wx.getStorageSync(app.config.tokenKey)) {
      this.getUserRole()
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
  getUserRole() {
    app.MG.identity.getCurrentAppUser().then((res) => {
      if (res) {
 
        this.getType()
        this.setData({
          userId: res.userId
        })
        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 studentInfo = res.infoList.find((item) => item.type == 'Default')
        let phoneInfo = res.secretList.find((item) => item.type == 'MobilePhone')
        let emailInfo = res.secretList.find((item) => item.type == 'EMail')
        let defaultUser = {};
        if (teacherRole && teacherInfos) {
          defaultUser = {
            ...teacherInfos,
            nickName: teacherInfos.fullName,
            avatarUrl: teacherInfos.icon,
            userId: res.userId,
            phoneNumber: phoneInfo?.credential,
            Email: emailInfo ? emailInfo.credential : JSON.parse(teacherInfos.data).email,
            role: 'Teacher',
            roleId: teacherRole.role.id
          }
 
        } else if (wechatInfo) {
          defaultUser = {
            ...wechatInfo,
            nickName: wechatInfo.name,
            avatarUrl: wechatInfo.icon,
            userId: res.userId,
            phoneNumber: phoneInfo?.credential,
            Email: emailInfo?.credential,
            role: 'Student'
          }
        } else if (studentInfo) {
          defaultUser = {
            ...studentInfo,
            nickName: wechatInfo.name,
            avatarUrl: wechatInfo.icon,
            userId: res.userId,
            phoneNumber: phoneInfo?.credential,
            Email: emailInfo?.credential,
            role: 'Student'
          }
        }
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
      }
    })
  },
  getType() {
    const data = {
      refCodes: ['jsek_teacherCertification']
    }
    app.MG.resource.getCmsTypeByRefCode(data).then((res) => {
      this.setData({
        worksInfo: res[0].cmsTypeLinks[0].children,
      })
      this.newGetTeacherInfo()
    })
  },
  newGetTeacherInfo() {
    const data = {
      start: 0,
      size: 10,
      topicIdOrRefCode: 'teacherRoleApproval',
      appRefCode: app.config.appRefCode,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      try {
        this.setData({
          fileList: [],
        })
        const resData = res.datas.find((i) => i.appUserCreator.userId === this.data.userId)
        if (resData) {
          if (resData.state == 'WaitAudit') {
            this.setData({
              editState: false,
            })
          } else {
            this.setData({
              editState: true,
            })
          }
          let info = getTopicMsgCmsItemFile(this.data.worksInfo, resData.cmsItemDataList)
          this.setData({
            'teacherInfo.fullName': info.fullName,
            'teacherInfo.schoolName ': info.schoolName,
            'teacherInfo.positionalTitle': info.positionalTitle,
            'teacherInfo.courseName': info.courseName,
            'teacherInfo.phone': info.phone,
            'teacherInfo.telphone': info.telphone ? info.telphone : '',
            'teacherInfo.email': info.email,
            'teacherInfo.detailedAddress': info.detailedAddress ? info.detailedAddress : '',
            'teacherInfo.relevantCertificates': info.relevantCertificates,
            'teacherInfo.agree': true,
            'teacherInfo.state': resData.state,
            topicId: resData.id,
            topicMessageList: resData.cmsItemDataList
          })
          if (resData.feedBack != null) {
            this.setData({
              reasonTxt: JSON.parse(resData.feedBack).reason,
            })
          }
          if (this.data.teacherInfo.relevantCertificates.length > 0) {
            if (typeof this.data.teacherInfo.relevantCertificates == 'object') {
              this.data.teacherInfo.relevantCertificates.forEach((ele) => {
                let imgObj = {
                  md5: ele.file.md5,
                  linkType: 'LinkFile',
                  linkProtectType: 'Public',
                  url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.file.md5
                }
                this.data.fileList.push(imgObj)
              })
            } else {
              let imgObj = {
                md5: this.data.teacherInfo.relevantCertificates,
                linkType: 'LinkFile',
                linkProtectType: 'Public',
                url:
                  app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates
              }
              this.data.fileList.push(imgObj)
            }
          }
        }
      } catch (error) {
      }
    })
  },
 
  getpositionalTitle() {
    const data = {
      refCodes: ['positionalTitle']
    }
    app.MG.store.getProductTypeField(data).then((res) => {
      try {
        let list = res[0]
        let options = JSON.parse(list.config).option
        options.forEach((item) => {
          item.label = item.name;
        })
        this.setData({
          teachPosts: options,
        })
      } catch (error) {
 
      }
    })
  },
  getAgreement() {
    let query = {
      path: 'jsek_protocol',
      fields: {
        content: []
      }
    }
    app.MG.resource.getItem(query).then((res) => {
      try {
        const data = res.datas.find((e) => e.refCode == 'jsek_teacherCertificationAgreement')
        this.setData({
          protocolTxt: data ? data.content : '暂无协议',
        })
      } catch (error) {
        this.setData({
          protocolTxt: '暂无协议',
        })
      }
    })
  },
  //选择职称
  onTeachPicker() {
    this.setData({ teachVisible: true });
  },
  onPickerChange(e) {
    const { value, label } = e.detail;
    this.setData({
      teachVisible: false,
      teachText: label[0],
      'teacherInfo.positionalTitle': value.join[0],
    });
  },
  onPickerCancel(e) {
    this.setData({
      'teacherInfo.positionalTitle': '',
      teachVisible: false,
    });
  },
  //输入手机号
  onPhoneInput(e) {
    const { phoneError } = this.data;
    const isPhoneNumber = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(e.detail.value);
    if (phoneError === isPhoneNumber) {
      this.setData({
        phoneError: !isPhoneNumber,
      });
    }
  },
  //输入座机
  onTelphoneInput(e) {
    const { telphoneError } = this.data;
    const isPhoneNumber = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/.test(e.detail.value);
    if (telphoneError === isPhoneNumber) {
      this.setData({
        telphoneError: !isPhoneNumber,
      });
    }
  },
  onEmailInput(e) {
    const { emailError } = this.data;
    const isPhoneNumber = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(e.detail.value);
    if (emailError === isPhoneNumber) {
      this.setData({
        emailError: !isPhoneNumber,
      });
    }
  },
  handleAdd(e) {
    const { fileList } = this.data;
    console.log(e)
    const { files } = e.detail;
    // 方法2:每次选择图片都上传,展示每次上传图片的进度
    files.forEach(file => {
      this.onUpload(file)
    })
  },
  onUpload(file) {
    console.log(file, '123')
    const isLt2M = (0.5 * file.size) / 1024 / 1024 < 0.5
    if (!isLt2M) {
      wx.showToast({
        title: "上传文件大小不能超过 500KB!",
        icon: 'none',
        duration: 1000,
      })
      return reject()
    }
    const FileName = file.name.split('.')[0]
    const Extension = file.name.split('.')[1]
    const FileType = file.type
    let size = 1024
    tool.getFileMd5(file, size * 1024).then((e) => {
      if (!this.data.fileList.find((item) => item.md5 == e)) {
        const imgData = new FormData()
        imgData.append('Md5', e)
        imgData.append('FileName', FileName)
        imgData.append('Extension', Extension)
        imgData.append('FileType', FileType)
        imgData.append('MetaData', null)
        imgData.append('file', file)
        app.MG.file.upload(imgData).then(() => {
          this.data.fileList.push({
            md5: e,
            linkType: 'LinkFile',
            linkProtectType: 'Public',
            name: FileName,
            type: FileType,
            url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + e
          })
        })
      } else {
        ElMessage.error('当前文件已上传,请勿重复操作!')
      }
    })
      .catch((e) => {
        console.error(e)
      })
  },
  handleRemove(e) {
    const { index } = e.detail;
    const { fileList } = this.data;
    fileList.splice(index, 1);
    this.setData({
      fileList,
    });
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  }
})