|
|
|
// pages/user/myInfo/index.js
|
|
|
|
import { store } from '../../../utils/store.js'
|
|
|
|
import { config } from '../../../config.js'
|
|
|
|
import { UserModel } from '../../../models/user.js'
|
|
|
|
import { TopicModel } from '../../../models/topic.js'
|
|
|
|
|
|
|
|
let topicModel = new TopicModel()
|
|
|
|
let userModel = new UserModel()
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
avatarUrl:String,
|
|
|
|
nickName: String,
|
|
|
|
phone: String,
|
|
|
|
company: String,
|
|
|
|
position: String,
|
|
|
|
streets:[],
|
|
|
|
streetsIndex:Number,
|
|
|
|
streetsID: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) {
|
|
|
|
|
|
|
|
},
|
|
|
|
onClose() {
|
|
|
|
this.setData({ close: false });
|
|
|
|
},
|
|
|
|
vantConfirm(){
|
|
|
|
this.setData({
|
|
|
|
realData:this.data.tempData
|
|
|
|
})
|
|
|
|
|
|
|
|
if(this.data.type === 'userName'){
|
|
|
|
this.setData({
|
|
|
|
nickName: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) {
|
|
|
|
this.setData({
|
|
|
|
avatarUrl: options.userIcon,
|
|
|
|
nickName: options.userName,
|
|
|
|
phone: options.userPhone || '',
|
|
|
|
company: options.company || '',
|
|
|
|
position: options.position || '',
|
|
|
|
streetsID:options.street || '',//得到streetsID的值
|
|
|
|
age:options.age || '',
|
|
|
|
genderIndex:options.genderIndex || '',
|
|
|
|
educationIndex:options.education || '',
|
|
|
|
professionalTitle:options.professionalTitle || '',
|
|
|
|
talentTitle:options.talentTitle || '',
|
|
|
|
prize:options.prize || '',
|
|
|
|
})
|
|
|
|
topicModel.getStreetList(res=>{
|
|
|
|
var resultss = res.result
|
|
|
|
var streett = []
|
|
|
|
resultss.forEach((value,index)=>{
|
|
|
|
streett[index] = value.departName
|
|
|
|
})
|
|
|
|
streett.unshift('')
|
|
|
|
this.setData({
|
|
|
|
streets: streett//得到street列表
|
|
|
|
})
|
|
|
|
resultss.forEach((value,index)=>{
|
|
|
|
if(value.id == this.data.streetsID){
|
|
|
|
return this.setData({streetsIndex: index+1})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
onTapItem(e) {
|
|
|
|
const { type } = e.currentTarget.dataset
|
|
|
|
this.setData({
|
|
|
|
type:type
|
|
|
|
})
|
|
|
|
|
|
|
|
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) {
|
|
|
|
this.setData({
|
|
|
|
genderIndex:e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
bindEducationChange:function(e){
|
|
|
|
this.setData({
|
|
|
|
educationIndex:e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
bindstreetChange:function(e){
|
|
|
|
// console.log("bindstreetChange");
|
|
|
|
// console.log(e.detail.value);
|
|
|
|
var i = e.detail.value-1
|
|
|
|
topicModel.getStreetList(res=>{
|
|
|
|
this.setData({
|
|
|
|
streetsIndex:e.detail.value,
|
|
|
|
streetsID:res.result[i].id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onTapPhone:function(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url:'../myInfo/register/index'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
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.streetsID,
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|