市北人才赋能平台 --小程序端
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.

397 lines
9.7 KiB

// pages/user/myInfo/index.js
4 years ago
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()
6 years ago
let userModel = new UserModel()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
4 years ago
avatarUrl: String,
nickName: String,
6 years ago
phone: String,
company: String,
4 years ago
position: String,
streets: [],
streetsIndex: 0,
streetsID: String,
age: String,
gender: ['', '男', '女'],
genderIndex: Number,
educationIndex: Number,
education: ['', '高中', '专科', '本科', '硕士', '博士'],
professionalTitle: String,
talentTitle: String,
prize: String,
5 years ago
show: false,
4 years ago
tempData: String,
realData: String,
temp: String,
type: String,
value: String,
defaultValue: '请输入',
inputConfirm: false
5 years ago
},
getUserInfo(event) {
console.log("getUserInfo");
console.log(event);
5 years ago
},
onClose() {
4 years ago
this.setData({
close: false
});
5 years ago
},
4 years ago
vantConfirm() {
5 years ago
this.setData({
4 years ago
realData: this.data.tempData
5 years ago
})
4 years ago
//判断名字长度,限制名字长度10个字之内,姓名不能为空
if (this.data.type === 'userName') {
console.log("username");
4 years ago
if (this.data.realData.length > 10) {
wx.showToast({
title: '姓名长度应小于10',
icon: 'none',
duration: 2000,
})
4 years ago
} else if (this.data.realData.length == 0 || this.data.realData.name == "String") {
wx.showToast({
title: '姓名不能为空',
icon: 'none',
duration: 2000,
})
4 years ago
} else {
console.log("nickName修改了");
4 years ago
this.setData({
nickName: this.data.realData
})
console.log(this.data.nickName);
}
4 years ago
}
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
})
4 years ago
} else {
this.setData({
age: this.data.realData
})
}
5 years ago
}
4 years ago
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
})
4 years ago
} else {
this.setData({
company: this.data.realData
})
4 years ago
}
5 years ago
}
4 years ago
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
})
4 years ago
}
5 years ago
}
4 years ago
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
})
4 years ago
}
5 years ago
}
4 years ago
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
})
4 years ago
} 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
})
}
5 years ago
}
this.setData({
4 years ago
value: '',
realData: '',
tempData: '',
defaultValue: '请输入',
inputConfirm: false
5 years ago
})
},
4 years ago
tempData: function (e) {
5 years ago
this.setData({
4 years ago
tempData: e.detail.value,
inputConfirm: true
5 years ago
})
console.log('temp');
console.log(this.data.tempData)
6 years ago
},
onLoad: function (options) {
4 years ago
console.log(options)
6 years ago
this.setData({
avatarUrl: options.userIcon,
nickName: options.userName,
6 years ago
phone: options.userPhone || '',
company: options.company || '',
position: options.position || '',
4 years ago
streetsID: options.street || '', //得到streetsID的值
age: options.age || '',
genderIndex: options.genderIndex || '',
educationIndex: options.education || '',
professionalTitle: options.professionalTitle || '',
talentTitle: this.getTalentTitle(options.talentTitle) || '',
prize: options.prize || '',
6 years ago
})
4 years ago
topicModel.getStreetList(res => {
var resultss = res.result
var streett = []
4 years ago
resultss.forEach((value, index) => {
streett[index] = value.departName
})
4 years ago
streett.unshift('')
this.setData({
4 years ago
streets: streett //得到street列表
})
4 years ago
resultss.forEach((value, index) => {
if (value.id == this.data.streetsID) {
return this.setData({
streetsIndex: index + 1
})
}
})
})
6 years ago
},
4 years ago
getTalentTitle(item) {
switch (item) {
case '0':
return '普通人才';
case '1':
return '高层次人才'
case '2':
return '企业人才'
}
},
6 years ago
onTapItem(e) {
4 years ago
const {
type
} = e.currentTarget.dataset
console.log('onTapItem');
console.log(type);
console.log(e);
5 years ago
this.setData({
4 years ago
type: type
5 years ago
})
4 years ago
if (type === 'userIcon') {
this.upload()
return
4 years ago
} else {
5 years ago
this.setData({
4 years ago
show: true
})
//姓名
4 years ago
if (type == 'userName' && this.data.nickName != '') {
this.setData({
4 years ago
value: this.data.nickName
})
}
//年龄
4 years ago
if (type == 'userAge' && this.data.age != '') {
this.setData({
4 years ago
value: this.data.age
})
}
//工作单位
4 years ago
if (type == 'workUnit' && this.data.company != '') {
this.setData({
4 years ago
value: this.data.company
})
}
//职务
4 years ago
if (type == 'position' && this.data.position != '') {
this.setData({
4 years ago
value: this.data.position
})
}
//职称
4 years ago
if (type == 'userProfessionalTitle' && this.data.professionalTitle != '') {
this.setData({
4 years ago
value: this.data.professionalTitle
})
}
//人才称号
4 years ago
if (type == 'userTalentTitle' && this.data.talentTitle != '') {
this.setData({
4 years ago
value: this.data.talentTitle
})
}
//荣誉
4 years ago
if (type == 'userPrize' && this.data.prize != '') {
this.setData({
4 years ago
value: this.data.prize
})
}
return
}
this.setData({
4 years ago
defaultValue: '请输入修改后的内容'
})
6 years ago
},
5 years ago
4 years ago
upload() {
let that = this
6 years ago
wx.chooseImage({
success(res) {
wx.showLoading()
const tempFilePaths = res.tempFilePaths
// console.log(res)
6 years ago
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);
6 years ago
const data = JSON.parse(res.data)
const image = {
url: config.api_url + '/' + data.result.imgUrl,
}
that.setData({
avatarUrl: image.url
4 years ago
}, () => {
6 years ago
wx.hideLoading()
})
}
})
}
})
6 years ago
},
// 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
// })
// },
4 years ago
bindGenderChange: function (e) {
5 years ago
this.setData({
4 years ago
genderIndex: e.detail.value
5 years ago
})
},
4 years ago
bindEducationChange: function (e) {
5 years ago
this.setData({
4 years ago
educationIndex: e.detail.value
5 years ago
})
4 years ago
},
bindstreetChange: function (e) {
// console.log("bindstreetChange");
// console.log(e.detail.value);
4 years ago
var i = e.detail.value - 1
topicModel.getStreetList(res => {
this.setData({
4 years ago
streetsIndex: e.detail.value,
streetsID: res.result[i].id
})
4 years ago
})
},
4 years ago
onTapPhone: function () {
wx.navigateTo({
4 years ago
url: '../myInfo/register/index'
})
5 years ago
},
4 years ago
submit() {
console.log("submit");
// console.log(this.data.nickName.length);
// console.log(this.data.nickName);
// console.log(this.data);
userModel.updateUserInfo(this.data, res => {
4 years ago
if (res.code === 200) {
store.saveUserInfo({
nickName: this.data.nickName,
avatarUrl: this.data.avatarUrl,
5 years ago
phone: this.data.phone || '',
4 years ago
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
})
6 years ago
wx.showToast({
title: '修改成功',
icon: 'none',
duration: 2000,
success(res) {
setTimeout(function () {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
}
})
4 years ago
6 years ago
}
})