From cb15c57d0ff984f5a100cf25d560fb0a69c00984 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期二, 16 四月 2024 18:21:05 +0800
Subject: [PATCH] 音频bug4

---
 packageDomain/pages/teacherCertification/index.js |  613 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 489 insertions(+), 124 deletions(-)

diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js
index c1b9a7e..fc9de73 100644
--- a/packageDomain/pages/teacherCertification/index.js
+++ b/packageDomain/pages/teacherCertification/index.js
@@ -1,6 +1,13 @@
 const app = getApp();
+import SparkMD5 from 'spark-md5'
 import tool from "../../../assets/js/toolClass.js";
-import { getTopicMsgCmsItemFile } from '../../../assets/js/middleGround/tool.js'
+import {
+  getTopicMsgCmsItemFile
+} from '../../../assets/js/middleGround/tool.js';
+import FormData from '../../../utils/formdata/index.js';
+import {
+  loginInfo
+} from '../../../assets/js/login';
 Page({
 
   /**
@@ -30,21 +37,35 @@
     topicId: "",
     worksInfo: [],
     userId: '',
-    fileList: [],
+    imgPics: [],
+    file: "",
+    imgs: [],
     protocolTxt: '', //鏁欏笀鍗忚
     protocolShow: false,
     editState: true,
-    reasonTxt: ""
+    reasonTxt: "",
+    reasonTxtShow: false,
+    skeletonLoding: true,
+    isIos: wx.getSystemInfoSync().platform === 'ios',
+    keyboardHeight: 0
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad() {
+    //鑾峰彇鑱岀О
     this.getpositionalTitle();
     this.getAgreement();
-
-    if (wx.getStorageSync(app.config.tokenKey)) {
+    // 妫�鏌ョ櫥褰曠姸鎬�
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {
+          this.getUserRole()
+        }
+      })
+    } else {
       this.getUserRole()
     }
   },
@@ -81,64 +102,51 @@
       if (res) {
         this.getType()
         this.setData({
-          userId: res.userId
+          userId: res.userId,
+          skeletonLoding: true,
         })
+        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 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 WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
         let defaultUser = {};
         if (teacherRole && teacherInfos) {
           defaultUser = {
             ...teacherInfos,
-            nickName: teacherInfos.fullName,
-            avatarUrl: teacherInfos.icon,
+            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,
-            phoneNumber: phoneInfo?.credential,
-            Email: emailInfo ? emailInfo.credential : JSON.parse(teacherInfos.data).email,
             role: 'Teacher',
-            roleId: teacherRole.role.id
+            roleId: teacherRole.role.id,
           }
 
-        } else if (wechatInfo) {
+        } else if (WeChatInfo) {
           defaultUser = {
-            ...wechatInfo,
-            nickName: wechatInfo.name,
-            avatarUrl: wechatInfo.icon,
+            ...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,
-            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));
+        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser));
       }
     })
   },
+  //鑾峰彇瀛楁
   getType() {
     app.MG.resource.getCmsTypeByRefCode({
       refCodes: ['jsek_teacherCertification']
     }).then((res) => {
-      console.log(res)
       this.setData({
         worksInfo: res[0].cmsTypeLinks[0].children,
       })
       this.newGetTeacherInfo()
     })
+
   },
+  //鑾峰彇鏁欏笀鐘舵��
   newGetTeacherInfo() {
+    let that = this;
     const data = {
       start: 0,
       size: 10,
@@ -151,24 +159,24 @@
     }
     app.MG.ugc.getTopicMessageList(data).then((res) => {
       try {
-        this.setData({
-          fileList: [],
+        that.setData({
+          imgPics: [],
         })
-        const resData = res.datas.find((i) => i.appUserCreator.userId === this.data.userId)
+        const resData = res.datas.find((i) => i.appUserCreator.userId === that.data.userId)
         if (resData) {
           if (resData.state == 'WaitAudit') {
-            this.setData({
+            that.setData({
               editState: false,
             })
           } else {
-            this.setData({
+            that.setData({
               editState: true,
             })
           }
-          let info = getTopicMsgCmsItemFile(this.data.worksInfo, resData.cmsItemDataList)
-          this.setData({
+          let info = getTopicMsgCmsItemFile(that.data.worksInfo, resData.cmsItemDataList)
+          that.setData({
             'teacherInfo.fullName': info.fullName,
-            'teacherInfo.schoolName ': info.schoolName,
+            'teacherInfo.schoolName': info.schoolName,
             'teacherInfo.positionalTitle': info.positionalTitle,
             'teacherInfo.courseName': info.courseName,
             'teacherInfo.phone': info.phone,
@@ -179,41 +187,55 @@
             'teacherInfo.agree': true,
             'teacherInfo.state': resData.state,
             topicId: resData.id,
-            topicMessageList: resData.cmsItemDataList
+            topicMessageList: resData.cmsItemDataList,
+            teachText: info.positionalTitle,
+            skeletonLoding: false,
           })
           if (resData.feedBack != null) {
-            this.setData({
+            that.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) => {
+          if (that.data.teacherInfo.relevantCertificates.length > 0) {
+            let arr = [];
+            if (typeof that.data.teacherInfo.relevantCertificates == 'object') {
+              that.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
+                  url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.md5,
+                  imgUrl: ele.file.imgUrl
                 }
-                this.data.fileList.push(imgObj)
+                arr.push(imgObj);
+                that.setData({
+                  imgPics: arr,
+                });
               })
             } else {
               let imgObj = {
-                md5: this.data.teacherInfo.relevantCertificates,
+                md5: that.data.teacherInfo.relevantCertificates,
                 linkType: 'LinkFile',
                 linkProtectType: 'Public',
-                url:
-                  app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates
+                url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + that.data.teacherInfo.relevantCertificates,
+                imgUrl: app.config.requestCtx + `/file/GetPreViewImage?md5=` + that.data.teacherInfo.relevantCertificates,
               }
-              this.data.fileList.push(imgObj)
+              arr.push(imgObj);
+              that.setData({
+                imgPics: arr,
+              });
             }
           }
+
+        } else {
+          that.setData({
+            skeletonLoding: false,
+          });
         }
-      } catch (error) {
-      }
+      } catch (error) {}
     })
   },
-
+  //鑾峰彇鑱岀О
   getpositionalTitle() {
     const data = {
       refCodes: ['positionalTitle']
@@ -253,17 +275,46 @@
       }
     })
   },
+  //瀛︽牎鍚嶇О
+  onSchoolNameInput(e) {
+    this.setData({
+      "teacherInfo.schoolName": e.detail.value,
+    });
+  },
+  //濮撳悕
+  onFullNameInput(e) {
+    this.setData({
+      "teacherInfo.fullName": e.detail.value,
+    });
+  },
+  // 浠绘暀璇剧▼
+  onCourseNameInput(e) {
+    this.setData({
+      "teacherInfo.courseName": e.detail.value,
+    });
+  },
+  //璇︾粏鍦板潃
+  onAddressInput(e) {
+    this.setData({
+      "teacherInfo.detailedAddress": e.detail.value,
+    });
+  },
+
 
   //閫夋嫨鑱岀О
   onTeachPicker() {
-    this.setData({ teachVisible: true });
+    this.setData({
+      teachVisible: true
+    });
   },
   onPickerChange(e) {
-    const { value, label } = e.detail;
+    const {
+      label
+    } = e.detail;
     this.setData({
       teachVisible: false,
       teachText: label[0],
-      'teacherInfo.positionalTitle': value.join[0],
+      'teacherInfo.positionalTitle': label[0],
     });
   },
   onPickerCancel(e) {
@@ -274,93 +325,180 @@
   },
   //杈撳叆鎵嬫満鍙�
   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) {
+    const {
+      phoneError
+    } = this.data;
+    if (e.detail.value) {
+      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,
+          "teacherInfo.phone": e.detail.value,
+        });
+      }
+    } else {
       this.setData({
-        phoneError: !isPhoneNumber,
+        phoneError: false,
       });
     }
   },
   //杈撳叆搴ф満
   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) {
+    const {
+      telphoneError
+    } = this.data;
+    if (e.detail.value) {
+      const isPhoneNumber = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/.test(e.detail.value);
+      if (telphoneError === isPhoneNumber) {
+        this.setData({
+          telphoneError: !isPhoneNumber,
+          "teacherInfo.telphone": e.detail.value,
+        });
+      }
+    } else {
       this.setData({
-        telphoneError: !isPhoneNumber,
+        telphoneError: false,
       });
     }
   },
   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) {
+    const {
+      emailError
+    } = this.data;
+    if (e.detail.value) {
+      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,
+          "teacherInfo.email": e.detail.value,
+        });
+      }
+    } else {
       this.setData({
-        emailError: !isPhoneNumber,
+        emailError: false,
       });
     }
   },
-  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) {
+  // 涓婁紶鍥剧墖浜嬩欢
+  chooseImg(e) {
+    var that = this;
+    if (that.data.imgPics.length == 4) {
       wx.showToast({
-        title: "涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 500KB!",
+        title: "宸ヤ綔璇佹枃浠朵笉瓒呰繃5涓紒",
         icon: 'none',
         duration: 1000,
       })
-      return reject()
+      return
     }
-    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
-          })
+    wx.chooseMedia({
+      count: 1,
+      sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈�
+      sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈�
+      success: function (res) {
+        // 杩斿洖閫夊畾鐓х墖鐨勬湰鍦版枃浠惰矾寰勫垪琛紝tempFilePath涔熷彲浠ヤ綔涓篿mg鏍囩鐨剆rc灞炴�ф樉绀哄浘鐗�
+        wx.getFileSystemManager().readFile({
+          filePath: res.tempFiles[0].tempFilePath, //閫夋嫨鍥剧墖杩斿洖鐨勭浉瀵硅矾寰�
+          // encoding: 'binary', //缂栫爜鏍煎紡
+          success: ress => {
+            //鎴愬姛鐨勫洖璋�
+            let spark = new SparkMD5.ArrayBuffer();
+            spark.append(ress.data);
+            let md5 = spark.end(false);
+            if (!that.data.imgPics.find((item) => item.md5 == md5)) {
+              let formData = new FormData();
+              formData.append('Md5', md5);
+              formData.append('FileName', md5);
+              formData.append('FileType', res.tempFiles[0].fileType);
+              formData.appendFile("file", res.tempFiles[0].tempFilePath);
+              const data = formData.getData();
+              let _token = wx.getStorageSync(app.config.tokenKey);
+              let header = {};
+              if (_token == null) {
+                header["Authorization"] = `Basic ${Base64.encode(website.clientId + ":" + website.clientSecret)}`;
+              } else {
+                header["Authorization"] = `Bearer ` + _token;
+              }
+              new Promise((resolve, reject) => {
+                wx.request({
+                  url: app.config.requestCtx + '/file/api/ApiUpload',
+                  method: 'POST',
+                  header: {
+                    'content-type': data.contentType,
+                    ...header
+                  },
+                  data: data.buffer,
+                  success(res1) {
+                    if (res1.statusCode == 200) {
+                      resolve(res1.data);
+                      if (res1.data) {
+                        let arr = [];
+                        let imgObj = {
+                          md5: md5,
+                          linkType: 'LinkFile',
+                          linkProtectType: 'Public',
+                          url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + md5,
+                          imgUrl: res.tempFiles[0].tempFilePath
+                        }
+                        arr = [...that.data.imgPics, ...[imgObj]];
+
+                        that.setData({
+                          imgPics: arr,
+                        });
+                      }
+                    } else {
+                      reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�');
+                    }
+                  }
+                })
+              })
+            } else {
+              wx.showToast({
+                title: "褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�",
+                icon: 'none',
+                duration: 1000,
+              })
+            }
+          }
         })
-      } 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,
     });
   },
+  // 鍒犻櫎鍥剧墖 
+  deleteImg(e) {
+    var imgs = this.data.imgPics;
+    var index = e.currentTarget.dataset.index;
+    imgs.splice(index, 1);
+    this.setData({
+      imgPics: imgs
+    });
+  },
+  // 棰勮鐜板満鍥剧墖 
+  previewImg(e) {
+    //鑾峰彇褰撳墠鍥剧墖鐨勪笅鏍�
+    var index = e.currentTarget.dataset.index;
+    //鎵�鏈夊浘鐗�
+    let imgs = [];
+    this.data.imgPics.forEach(item => {
+      imgs.push(item.url)
+    })
+    wx.previewImage({
+      //褰撳墠鏄剧ず鍥剧墖
+      current: imgs[index],
+      //鎵�鏈夊浘鐗�
+      urls: imgs
+    })
+  },
   onChange() {
+    if (this.data.teacherInfo.agree) {
+      this.setData({
+        'teacherInfo.agree': false,
+      });
+    } else {
+      this.setData({
+        'teacherInfo.agree': true,
+      });
+    }
 
   },
   //鏌ョ湅鏁欏笀璁よ瘉鏈嶅姟
@@ -372,7 +510,168 @@
   onVisibleChange(e) {
     this.setData({
       protocolShow: e.detail.visible,
+      reasonTxtShow: e.detail.visible
     });
+  },
+  onCloseProtocol() {
+    this.setData({
+      protocolShow: false,
+    });
+  },
+
+  //鏌ョ湅涓洪�氳繃鍘熷洜
+  previewReason() {
+    this.setData({
+      reasonTxtShow: true,
+    });
+  },
+
+  onCloseReasonTxt() {
+    this.setData({
+      reasonTxtShow: false,
+    });
+  },
+
+  submit() {
+    let that = this;
+    if (!that.data.teacherInfo.schoolName) {
+      wx.showToast({
+        title: "璇峰~鍐欏鏍″悕绉帮紒",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (!that.data.teacherInfo.fullName) {
+      wx.showToast({
+        title: "璇峰~鍐欑湡瀹炲鍚嶏紒",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (!that.data.teacherInfo.courseName) {
+      wx.showToast({
+        title: "璇峰~鍐欎换鏁欒绋嬶紒",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (!that.data.teacherInfo.phone) {
+      wx.showToast({
+        title: "璇峰~鍐欒仈绯荤數璇濓紒",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (!that.data.teacherInfo.email) {
+      wx.showToast({
+        title: "璇峰~鍐欓偖绠憋紒",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (that.data.imgPics.length == 0) {
+      wx.showToast({
+        title: "璇蜂笂浼犲伐浣滆瘉锛�",
+        icon: 'none',
+        duration: 1000,
+      })
+      return
+    }
+    if (that.data.teacherInfo.agree) {
+      if (that.data.topicMessageList.length > 0) {
+        let dataRequests = tool.UpdateworksDataBytool(
+          that.data.worksInfo,
+          that.data.topicMessageList,
+          that.data.teacherInfo,
+          that.data.imgPics
+        );
+        const data = {
+          description: '',
+          icon: '',
+          id: that.data.topicId,
+          topicIdOrRefCode: 'teacherRoleApproval',
+          name: that.data.teacherInfo.fullName + '',
+          content: '',
+          state: 'WaitAudit',
+          type: 'teacherRegister',
+          newDataRequests: dataRequests.newData,
+          updateDataRequests: dataRequests.updateData,
+          delDataRequest: {
+            ids: []
+          }
+        }
+        let basicInfo = JSON.parse(JSON.stringify(that.data.teacherInfo))
+        delete basicInfo.worksInfo
+        delete basicInfo.state
+        const userInfo = {
+          requests: [{
+            data: JSON.stringify(basicInfo),
+            name: that.data.teacherInfo.fullName + '',
+            type: 'newTeacherInfo'
+          }]
+        }
+        app.MG.identity.setAppUserInfo(userInfo).then((res) => {
+          if (res) {
+            app.MG.ugc.updateTopicMessage(data).then(() => {
+              if (res !== false) {
+                wx.showToast({
+                  title: "鎻愪氦鎴愬姛锛佽绛夊緟瀹℃牳...",
+                  icon: 'none',
+                  duration: 1000,
+                })
+                that.getUserRole()
+                // that.newGetTeacherInfo()
+              }
+            })
+          }
+        })
+      } else {
+        const data = {
+          topicIdOrRefCode: 'teacherRoleApproval',
+          name: that.data.teacherInfo.fullName + '',
+          content: '',
+          state: 'WaitAudit',
+          type: 'teacherRegister',
+          cmsTypeRefCode: 'jsek_teacherCertification',
+          newDataListRequest: tool.worksDataBytool(that.data.worksInfo, that.data.teacherInfo, that.data.imgPics)
+        }
+
+        let basicInfo = JSON.parse(JSON.stringify(that.data.teacherInfo))
+        delete basicInfo.worksInfo
+        delete basicInfo.state
+        const userInfo = {
+          requests: [{
+            data: JSON.stringify(basicInfo),
+            name: that.data.teacherInfo.fullName + '',
+            type: 'teacherInfo'
+          }]
+        }
+        app.MG.identity.setAppUserInfo(userInfo).then((res) => {
+          app.MG.ugc.newTopicMessage(data).then(() => {
+            if (res !== false) {
+              wx.showToast({
+                title: "鎻愪氦鎴愬姛锛佽绛夊緟瀹℃牳...",
+                icon: 'none',
+                duration: 1000,
+              })
+              // that.newGetTeacherInfo()
+              that.getUserRole()
+            }
+          })
+        })
+      }
+    } else {
+      wx.showToast({
+        title: "璇峰悓鎰忋�婃暀甯堣璇佹湇鍔℃潯娆俱�嬶紒",
+        icon: 'none',
+        duration: 1000,
+      })
+    }
 
   },
 
@@ -380,14 +679,80 @@
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
    */
   onPullDownRefresh() {
+    if (wx.getStorageSync(app.config.tokenKey)) {
+      this.getUserRole()
+    }
+  },
+  // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈�
+  bindkeyboardheightchange(e) {
+    // 鍙ios 澶勭悊
+    if (!this.data.isIos === 'ios') {
+      return
+    }
+    // 閿洏楂樺害
+    const height = e.detail.height;
+    const className = e.target.dataset.class;
+    if (height === 0) {
+      this.scrollToInput(0);
+      return;
+    }
+    try {
+      this.createSelectorQuery()
+        .select(`.${className}`)
+        .boundingClientRect((res) => {
+          // 鍙娇鐢ㄧ獥鍙i珮搴�
+          const windowHeight = wx.getSystemInfoSync().windowHeight;
+          // 闄ゅ幓閿洏鐨勫墿浣欓珮搴�
+          let restHeight = windowHeight - height;
+          // 鍏冪礌宸︿笅瑙掑潗鏍�
+          let bottom = res.bottom;
+          // 鍙湁褰撳厓绱犺杞敭鐩樿鐩栫殑鏃跺�欐墠涓婃帹椤甸潰
+          if (bottom <= restHeight) return;
+          // 鐜伴樁娈甸渶瑕佹粴鍔ㄧ殑澶у皬
+          let scrollTop = bottom - restHeight;
+          this.scrollToInput(height, scrollTop);
+        })
+        .exec();
+    } catch (error) {}
   },
 
+  // 鑾峰彇椤甸潰婊氬姩鏉′綅缃�
+  getScrollOffset() {
+    return new Promise((resolve) => {
+      try {
+        wx.createSelectorQuery()
+          .selectViewport()
+          .scrollOffset((res) => {
+            resolve(res.scrollTop);
+          })
+          .exec();
+      } catch (error) {
+        resolve(0);
+      }
+    });
+  },
+
+  // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈�
+  scrollToInput(keyboardHeight, scrollTop) {
+    this.setData({
+      keyboardHeight,
+    });
+    if (scrollTop) {
+      try {
+        this.getScrollOffset().then((lastScrollTop) => {
+          wx.pageScrollTo({
+            // 濡傛灉宸茬粡瀛樺湪婊氬姩锛屽湪姝ゅ熀纭�涓婄户缁粴
+            scrollTop: lastScrollTop ? lastScrollTop + scrollTop : scrollTop,
+            duration: 300,
+          });
+        });
+      } catch (error) {}
+    }
+  },
   /**
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�

--
Gitblit v1.9.1