ASEMiniProgram/pages/account-doc-info/account-doc-info.js

144 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

// pages/account-doc-info/account-doc-info.js
2021-04-02 16:35:01 +00:00
import {getUserProfileSupervisor} from '../../api/document'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
hasUserInfo: false,
hasUserDocument: false,
userInfo: null,
userDocuement: null,
2021-04-02 16:35:01 +00:00
admin: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
2021-04-02 16:35:01 +00:00
console.log(options)
if(options.admin === "true") {
const eventChannel = this.getOpenerEventChannel()
let that = this
eventChannel.on('acceptDataFromOpenerPage', function(data) {
console.log(data)
that.setData({
hasUserInfo: false,
userInfo: {}
})
that.setUserDocument(data.userDocument)
if(data.userDocument.connected) {
getUserProfileSupervisor(data.userDocument.id).then(res => {
console.log(res)
that.setData({
hasUserInfo: true,
userInfo: res
})
})
}
})
} else {
if(app.globalData.userInfo){
2021-04-02 16:35:01 +00:00
this.setData({
hasUserInfo: true,
userInfo: app.globalData.userInfo
})
}
if(app.globalData.userDocument){
this.setUserDocument(app.globalData.userDocument)
}
}
},
2021-04-02 16:35:01 +00:00
setUserDocument(document) {
2021-04-02 16:35:01 +00:00
let userDocument = document
switch(userDocument.gender) {
case 'F':
userDocument.gender = '女'
break;
case 'M':
userDocument.gender = '男'
break;
case 'U':
userDocument.gender = '未知'
break;
}
switch(userDocument.role) {
case 'ROLE_STUDENT':
userDocument.role = '学生'
break;
case 'ROLE_PARENT':
userDocument.role = '家长'
break;
case 'ROLE_SUPERVISOR':
userDocument.role = '辅导员'
break;
}
this.setData({
hasUserDocument: true,
userDocument: userDocument
})
2021-04-02 16:35:01 +00:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onClickQuestion() {
// 跳转
wx.navigateTo({
url: '/pages/question/question'
})
}
})