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.
 

158 lines
2.9 KiB

// pages/mine/mine.js
const axios = require('../../api/index')
const utils = require('../../utils/util')
Page({
/**
* 页面的初始数据
*/
data: {
userinfo: {},
userName: '',
phone: '',
img:''
},
phone_input_fn(e) {
let phone = e.detail.value
this.setData({
phone
})
},
name_input_fn(e) {
let userName = e.detail.value;
this.setData({
userName
})
},
// 上传图片
check_head_img() {
const that = this
// uploadFile
utils.upLoadAvatarImageCos(((err, res) => {
if (err) {
wx.showToast({
title: message || '上传失败',
icon: 'none'
})
return
}
console.log(res)
that.setData({
[`userinfo.avatarUrl`]: res.headers.Location.replace('http://znyc-images-1304677865.cos.ap-guangzhou.myqcloud.com', 'https://zhongnengyunche.com')
});
}))
},
checkPhone(phone) {
if (!(/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/.test(phone))) {
return false;
} else {
return true
}
},
update_user_name() {
let {
userName,
userinfo,
phone
} = this.data;
if (userName.trim().length == 0) {
wx.showToast({
title: '请输入姓名',
icon: 'none'
});
return
}
if (phone=='' || !this.checkPhone(phone)) {
wx.showToast({
title: '手机号码格式错误',
icon: 'none'
});
return
};
let data = {
userName,
avatarUrl: userinfo.avatarUrl,
phone: phone,
}
console.log(data)
axios.userUpdate(data).then(res => {
console.log(res)
if (res.code == 0) {
wx.showToast({
title: res.msg || '修改失败',
icon: 'none'
})
return
}
let userInfo=res.data
wx.setStorageSync('userInfo', userInfo)
this.setData({
userinfo: userInfo
});
wx.showToast({
title: '修改成功',
});
wx.navigateBack()
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let userinfo = wx.getStorageSync('userInfo')
console.log(userinfo)
this.setData({
userinfo,
userName: userinfo.userName,
phone: userinfo.phone
})
console.log(this.data.userName)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
})