From 00993a660c1c79c37b59a811b9c940dbe604a7bb Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期五, 15 三月 2024 18:53:46 +0800
Subject: [PATCH] 教师认证

---
 pages/teacherCertification/index.js |  322 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 320 insertions(+), 2 deletions(-)

diff --git a/pages/teacherCertification/index.js b/pages/teacherCertification/index.js
index 358d636..af25488 100644
--- a/pages/teacherCertification/index.js
+++ b/pages/teacherCertification/index.js
@@ -1,17 +1,51 @@
+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);
+    console.log(options, 111);
+    this.getpositionalTitle();
+    this.getAgreement();
+    if (wx.getStorageSync(app.config.tokenKey)) {
+      this.getUserRole()
+    }
   },
 
   /**
@@ -41,6 +75,290 @@
   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,
+    });
+  },
 
   /**
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔

--
Gitblit v1.9.1