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

135 lines
3.1 KiB

// pages/user/myInfo/index.js
6 years ago
import { store } from '../../../utils/store.js'
import { config } from '../../../config.js'
import { UserModel } from '../../../models/user.js'
let userModel = new UserModel()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
6 years ago
avatarUrl:String,
nikeName: String,
phone: String,
company: String,
position: String,
6 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
6 years ago
console.log(options)
this.setData({
avatarUrl: options.userIcon,
nikeName: options.userName,
phone: options.userPhone || '',
company: options.company || '',
position: options.position || '',
})
6 years ago
},
6 years ago
onTapItem(e) {
const { type } = e.currentTarget.dataset
console.log(type)
// if(type === 'userIcon'){
// this.upload()
// }
6 years ago
},
6 years ago
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()
})
}
})
}
})
6 years ago
},
6 years ago
getUserInfo(){
userModel.getUserInfo(res => {
let nickName = res.result.nickName
let avatarUrl = res.result.avatarUrl
this.setData({
avatarUrl: res.result.avatarUrl,
nikeName: res.result.nickName,
phone: res.result.phone || '',
company: res.result.company || '',
position: res.result.position || '',
})
store.saveUserInfo({
nickName: res.result.nickName,
avatarUrl: res.result.avatarUrl,
phone: res.result.phone || ''
})
})
6 years ago
},
6 years ago
bindNikeNameInput(e){
this.setData({
nikeName:e.detail.value
})
6 years ago
},
6 years ago
bindPhoneInput(e) {
this.setData({
phone: e.detail.value
})
6 years ago
},
6 years ago
bindCompanyInput(e) {
this.setData({
company: e.detail.value
})
6 years ago
},
6 years ago
bindPositionInput(e) {
this.setData({
position: e.detail.value
})
},
submit(){
let avatarUrl = this.data.avatarUrl
let nikeName = this.data.nikeName
let phone = this.data.phone
let company = this.data.company
let position = this.data.position
userModel.updateUserInfo(avatarUrl, nikeName, phone, company, position, res => {
// that.getUserInfo()
if(res.code === 200){
wx.showToast({
title: '修改成功',
icon: 'none',
duration: 2000,
success(res) {
setTimeout(function () {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
}
})
6 years ago
}
})