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

115 lines
2.5 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,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options)
this.setData({
avatarUrl: options.userIcon,
nickName: options.userName,
phone: options.userPhone || '',
company: options.company || '',
position: options.position || '',
})
},
onTapItem(e) {
const { type } = e.currentTarget.dataset
console.log(type)
if(type === 'userIcon'){
this.upload()
}
},
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
})
},
submit(){
userModel.updateUserInfo(this.data, res => {
if(res.code === 200){
store.saveUserInfo({
nickName: this.data.nickName,
avatarUrl: this.data.avatarUrl,
phone: this.data.phone || ''
})
wx.showToast({
title: '修改成功',
icon: 'none',
duration: 2000,
success(res) {
setTimeout(function () {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
}
})
}
})