|
|
|
// 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: 0,
|
|
|
|
streetsID: String,
|
|
|
|
age: String,
|
|
|
|
gender: ['', '男', '女'],
|
|
|
|
genderIndex: Number,
|
|
|
|
educationIndex: Number,
|
|
|
|
education: ['', '高中', '专科', '本科', '硕士', '博士'],
|
|
|
|
professionalTitle: String,
|
|
|
|
talentTitle: String,
|
|
|
|
prize: String,
|
|
|
|
show: false,
|
|
|
|
tempData: String,
|
|
|
|
realData: String,
|
|
|
|
temp: String,
|
|
|
|
type: String,
|
|
|
|
value: String,
|
|
|
|
defaultValue: '请输入',
|
|
|
|
inputConfirm: false
|
|
|
|
},
|
|
|
|
|
|
|
|
getUserInfo(event) {
|
|
|
|
console.log("getUserInfo");
|
|
|
|
console.log(event);
|
|
|
|
},
|
|
|
|
onClose() {
|
|
|
|
this.setData({
|
|
|
|
close: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
vantConfirm() {
|
|
|
|
this.setData({
|
|
|
|
realData: this.data.tempData
|
|
|
|
})
|
|
|
|
//判断名字长度,限制名字长度10个字之内,姓名不能为空
|
|
|
|
if (this.data.type === 'userName') {
|
|
|
|
console.log("username");
|
|
|
|
if (this.data.realData.length > 10) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '姓名长度应小于10',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000,
|
|
|
|
})
|
|
|
|
} else if (this.data.realData.length == 0 || this.data.realData.name == "String") {
|
|
|
|
wx.showToast({
|
|
|
|
title: '姓名不能为空',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log("nickName修改了");
|
|
|
|
this.setData({
|
|
|
|
nickName: this.data.realData
|
|
|
|
})
|
|
|
|
console.log(this.data.nickName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'userAge') {
|
|
|
|
console.log("confirm userAge");
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
age: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
age: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'workUnit') {
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
company: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
company: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'position') {
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
position: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
position: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'userProfessionalTitle') {
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
professionalTitle: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
professionalTitle: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'userTalentTitle') {
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
talentTitle: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
talentTitle: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.type === 'userPrize') {
|
|
|
|
if ((this.data.realData.length == 0 || this.data.realData.name == "String") && !this.data.inputConfirm) {
|
|
|
|
this.setData({
|
|
|
|
prize: this.data.value
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
prize: this.data.realData
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
value: '',
|
|
|
|
realData: '',
|
|
|
|
tempData: '',
|
|
|
|
defaultValue: '请输入',
|
|
|
|
inputConfirm: false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
tempData: function (e) {
|
|
|
|
this.setData({
|
|
|
|
tempData: e.detail.value,
|
|
|
|
inputConfirm: true
|
|
|
|
})
|
|
|
|
console.log('temp');
|
|
|
|
console.log(this.data.tempData)
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
console.log(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: this.getTalentTitle(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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getTalentTitle(item) {
|
|
|
|
switch (item) {
|
|
|
|
case '0':
|
|
|
|
return '普通人才';
|
|
|
|
case '1':
|
|
|
|
return '高层次人才'
|
|
|
|
case '2':
|
|
|
|
return '企业人才'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTapItem(e) {
|
|
|
|
const {
|
|
|
|
type
|
|
|
|
} = e.currentTarget.dataset
|
|
|
|
console.log('onTapItem');
|
|
|
|
console.log(type);
|
|
|
|
console.log(e);
|
|
|
|
this.setData({
|
|
|
|
type: type
|
|
|
|
})
|
|
|
|
if (type === 'userIcon') {
|
|
|
|
this.upload()
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
show: true
|
|
|
|
})
|
|
|
|
//姓名
|
|
|
|
if (type == 'userName' && this.data.nickName != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.nickName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//年龄
|
|
|
|
if (type == 'userAge' && this.data.age != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.age
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//工作单位
|
|
|
|
if (type == 'workUnit' && this.data.company != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.company
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//职务
|
|
|
|
if (type == 'position' && this.data.position != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.position
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//职称
|
|
|
|
if (type == 'userProfessionalTitle' && this.data.professionalTitle != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.professionalTitle
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//人才称号
|
|
|
|
if (type == 'userTalentTitle' && this.data.talentTitle != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.talentTitle
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//荣誉
|
|
|
|
if (type == 'userPrize' && this.data.prize != '') {
|
|
|
|
this.setData({
|
|
|
|
value: this.data.prize
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
defaultValue: '请输入修改后的内容'
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
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.nickName.length);
|
|
|
|
// console.log(this.data.nickName);
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|