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: '', //教师协议
|
protocolShow: false,
|
editState: true,
|
reasonTxt: ""
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad() {
|
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() {
|
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({
|
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,
|
});
|
},
|
onChange() {
|
|
},
|
//查看教师认证服务
|
viewContent() {
|
this.setData({
|
protocolShow: true,
|
});
|
},
|
onVisibleChange(e) {
|
this.setData({
|
protocolShow: e.detail.visible,
|
});
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh() {
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom() {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage() {
|
|
}
|
})
|