市北人才赋能平台 --小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

242 lines
5.7 KiB

// pages/user/myInfo/index.js
import { store } from '../../../utils/store.js'
import { config } from '../../../config.js'
import { UserModel } from '../../../models/user.js'
let userModel = new UserModel()
Page({
/**
* 页面的初始数据
*/
data: {
avatarUrl:String,
nickName: String,
phone: String,
company: String,
position: String,
street:String,
age:String,
gender:['','男','女'],
genderIndex:Number,
educationIndex:Number,
education:['','高中','专科','本科','硕士','博士'],
professionalTitle:String,
talentTitle:String,
prize:String,
show: false,
tempData:String,
realData:String,
type:String,
value:String,
},
getUserInfo(event) {
console.log(event.detail);
},
onClose() {
this.setData({ close: false });
},
vantConfirm(){
console.log("vant confirm");
this.setData({
realData:this.data.tempData
})
console.log(this.data.realData);
if(this.data.type === 'userName'){
this.setData({
nickName:this.data.realData
})
}
if(this.data.type === 'userPhone'){
this.setData({
phone:this.data.realData
})
}
if(this.data.type === 'userStreet'){
this.setData({
street:this.data.realData
})
}
if(this.data.type === 'userAge'){
this.setData({
age:this.data.realData
})
}
if(this.data.type === 'workUnit'){
this.setData({
workUnit:this.data.realData
})
}
if(this.data.type === 'position'){
this.setData({
position:this.data.realData
})
}
if(this.data.type === 'workUnit'){
this.setData({
company:this.data.realData
})
}
if(this.data.type === 'userProfessionalTitle'){
this.setData({
professionalTitle:this.data.realData
})
}
if(this.data.type === 'userTalentTitle'){
this.setData({
talentTitle:this.data.realData
})
}
if(this.data.type === 'userPrize'){
this.setData({
prize:this.data.realData
})
}
this.setData({
value:''
})
},
tempData: function(e){
this.setData({
tempData:e.detail.value
})
},
onLoad: function (options) {
console.log("index.js");
console.log(options)
this.setData({
avatarUrl: options.userIcon,
nickName: options.userName,
phone: options.userPhone || '',
company: options.company || '',
position: options.position || '',
street:options.street || '',
age:options.age || '',
genderIndex:options.genderIndex || '',
educationIndex:options.education || '',
professionalTitle:options.professionalTitle || '',
talentTitle:options.talentTitle || '',
prize:options.prize || '',
})
},
//性别和学历有专门的bind方法。此方法修改年龄,工作单位,职务,职称等
onTapItem(e) {
const { type } = e.currentTarget.dataset
this.setData({
type:type
})
console.log(type)
//如果等于userIcon调用upload方法更新头像
if(type === 'userIcon'){
this.upload()
}else{
this.setData({
show:true
})
}
},
upload(){
let that = this
wx.chooseImage({
success(res) {
wx.showLoading()
const tempFilePaths = res.tempFilePaths
console.log(res)
const token = store.readToken()
wx.uploadFile({
url: config.api_url + "/api/common/upload",
filePath: tempFilePaths[0],
header: {
'token': token,
'content-type': 'application/json',
},
name: 'files',
success(res) {
console.log(res);
const data = JSON.parse(res.data)
const image = {
url: config.api_url + '/' + data.result.imgUrl,
}
that.setData({
avatarUrl: image.url
},()=>{
wx.hideLoading()
})
}
})
}
})
},
bindNickNameInput(e){
this.setData({
nickName:e.detail.value
})
},
// bindPhoneInput(e) {
// this.setData({
// phone: e.detail.value
// })
// },
// bindCompanyInput(e) {
// this.setData({
// company: e.detail.value
// })
// },
// bindPositionInput(e) {
// this.setData({
// position: e.detail.value
// })
// },
bindGenderChange: function(e) {
console.log("bindGenderChange");
console.log(e);
this.setData({
genderIndex:e.detail.value
})
console.log(this.data.genderIndex);
},
bindEducationChange:function(e){
this.setData({
educationIndex:e.detail.value
})
console.log(this.data.educationIndex);
},
submit(){
console.log("submit");
console.log(this.data);
userModel.updateUserInfo(this.data, res => {
if(res.code === 200){
store.saveUserInfo({
nickName: this.data.nickName,
avatarUrl: this.data.avatarUrl,
phone: this.data.phone || '',
departId:this.data.street,
age:this.data.age,
gender:this.data.genderIndex,//
company:this.data.company,
position:this.data.position,
education:this.data.educationIndex,//
title:this.data.professionalTitle,
designation:this.data.talentTitle,
honor:this.data.prize
})
wx.showToast({
title: '修改成功',
icon: 'none',
duration: 2000,
success(res) {
setTimeout(function () {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
}
})
}
})