From 93463d63f0dd81c436aa3335506611aab8356b88 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期一, 25 三月 2024 23:39:40 +0800 Subject: [PATCH] 样式修改 --- packageDomain/pages/teacherCertification/index.js | 606 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 601 insertions(+), 5 deletions(-) diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js index 358d636..0979b20 100644 --- a/packageDomain/pages/teacherCertification/index.js +++ b/packageDomain/pages/teacherCertification/index.js @@ -1,17 +1,57 @@ +const app = getApp(); +import SparkMD5 from 'spark-md5' +import tool from "../../../assets/js/toolClass.js"; +import { getTopicMsgCmsItemFile } from '../../../assets/js/middleGround/tool.js'; +import FormData from '../../../utils/formdata/index.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: '', + imgPics: [], + file: "", + imgs: [], + protocolTxt: '', //鏁欏笀鍗忚 + protocolShow: false, + editState: true, + reasonTxt: "", + reasonTxtShow: false, }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ - onLoad(options) { - console.log(options); + onLoad() { + this.getpositionalTitle(); + this.getAgreement(); + + if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } }, /** @@ -41,19 +81,575 @@ onUnload() { }, + getUserRole() { + app.MG.identity.getCurrentAppUser().then((res) => { + if (res) { + this.getType() + this.setData({ + userId: res.userId + }) + 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 secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword') + let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); + let defaultUser = {}; + if (teacherRole && teacherInfos) { + defaultUser = { + ...teacherInfos, + nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : teacherInfos.name, + icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo ? WeChatInfo.icon : '', + userId: res.userId, + role: 'Teacher', + roleId: teacherRole.role.id, + } + this.setData({ + currAuthStep: 2, + }); + + } else if (WeChatInfo) { + defaultUser = { + ...WeChatInfo, + nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name, + icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon, + userId: res.userId, + } + this.setData({ + currAuthStep: 3, + }); + } else if (secretData) { + defaultUser = { + nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : secretData.credential, + icon: nickNameData ? JSON.parse(nickNameData.data).icon : "", + userId: res.userId, + } + } + 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() { + 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({ + imgPics: [], + }) + 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) + console.log(info) + 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, + teachText: info.positionalTitle, + }) + if (resData.feedBack != null) { + this.setData({ + reasonTxt: JSON.parse(resData.feedBack).reason, + }) + } + if (this.data.teacherInfo.relevantCertificates.length > 0) { + let arr = []; + 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.md5, + imgUrl: ele.file.imgUrl + } + arr.push(imgObj); + this.setData({ + imgPics: arr, + }); + }) + } else { + let imgObj = { + md5: this.data.teacherInfo.relevantCertificates, + linkType: 'LinkFile', + linkProtectType: 'Public', + url: + app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates, + imgUrl: app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates, + } + arr.push(imgObj); + this.setData({ + imgPics: arr, + }); + } + } + + } + } 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: '鏆傛棤鍗忚', + }) + } + }) + }, + //瀛︽牎鍚嶇О + 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 }); + }, + onPickerChange(e) { + const { label } = e.detail; + this.setData({ + teachVisible: false, + teachText: label[0], + 'teacherInfo.positionalTitle': label[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, + "teacherInfo.phone": e.detail.value, + }); + } + }, + //杈撳叆搴ф満 + 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, + "teacherInfo.telphone": e.detail.value, + }); + } + }, + 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, + "teacherInfo.email": e.detail.value, + }); + } + }, + // 涓婁紶鍥剧墖浜嬩欢 + chooseImg(e) { + var that = this; + wx.chooseMedia({ + // count: 1, // 榛樿9 + sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈� + sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈� + success: function (res) { + // 杩斿洖閫夊畾鐓х墖鐨勬湰鍦版枃浠惰矾寰勫垪琛紝tempFilePath涔熷彲浠ヤ綔涓篿mg鏍囩鐨剆rc灞炴�ф樉绀哄浘鐗� + console.log(res.tempFiles[0], 12); + 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, + }) + } + } + }) + + } + }); + }, + // 鍒犻櫎鍥剧墖 + 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() { + console.log(this.data.teacherInfo.agree, 12) + if (this.data.teacherInfo.agree) { + this.setData({ + 'teacherInfo.agree': false, + }); + } else { + this.setData({ + 'teacherInfo.agree': true, + }); + } + + }, + //鏌ョ湅鏁欏笀璁よ瘉鏈嶅姟 + viewContent() { + this.setData({ + protocolShow: true, + }); + }, + 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 + ); + console.log(dataRequests, 4) + 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, + }) + } + + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - + if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ onReachBottom() { - }, /** -- Gitblit v1.9.1