122 lines
3.4 KiB
JavaScript
122 lines
3.4 KiB
JavaScript
let util = require('../../../utils/util')
|
|
let apiArr = require('../../../api/water_filter')
|
|
|
|
Page({
|
|
data: {
|
|
avatarUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_309.png',
|
|
userInfo: {
|
|
name: '张三',
|
|
phone: '13800138000'
|
|
},
|
|
stats: {
|
|
newInstall: 12,
|
|
filterReplace: 8,
|
|
repair: 5
|
|
},
|
|
fileList: [],
|
|
sexOptions: ['男', '女'],
|
|
avatarUrl2:""
|
|
},
|
|
changeSex(e) {
|
|
const sexIndex = e.detail.value;
|
|
this.setData({
|
|
sexIndex,
|
|
'userInfo.sex': sexIndex + 1 // 更新性别值
|
|
});
|
|
// 这里可以添加保存性别到服务器的逻辑
|
|
},
|
|
|
|
getMasterInfo() {
|
|
let that = this
|
|
util.postUrl(apiArr.masterInfo, {
|
|
user_id: wx.getStorageSync('userId')
|
|
}, res => {
|
|
wx.setStorageSync('master', res)
|
|
that.setData({
|
|
userInfo: res,
|
|
sexIndex:res.sex - 1
|
|
})
|
|
|
|
if (res.avatar) {
|
|
that.setData({
|
|
avatarUrl: util.img_url + res.avatar
|
|
})
|
|
}
|
|
|
|
})
|
|
},
|
|
updateName(e){
|
|
let that = this
|
|
that.setData({
|
|
"userInfo.name":e.detail.value
|
|
})
|
|
},
|
|
updatePhone(e){
|
|
let that = this
|
|
that.setData({
|
|
"userInfo.phone":e.detail.value
|
|
})
|
|
},
|
|
saveUserInfo(){
|
|
let that = this
|
|
util.postUrl(apiArr.editMasterInfo,{
|
|
info_id:that.data.userInfo.info_id,
|
|
name:that.data.userInfo.name,
|
|
sex:that.data.userInfo.sex,
|
|
region:that.data.userInfo.region,
|
|
address:that.data.userInfo.address,
|
|
avatar:that.data.avatarUrl2,
|
|
phone:that.data.userInfo.phone
|
|
},res=>{
|
|
console.log(res);
|
|
if(res.msg == '操作成功'){
|
|
wx.showToast({
|
|
title: '修改成功!',
|
|
})
|
|
}else{
|
|
wx.showToast({
|
|
title: res.msg,
|
|
icon:"none"
|
|
})
|
|
}
|
|
})
|
|
},
|
|
onLoad(e) {
|
|
// 这里可以添加获取用户信息和统计数据的逻辑
|
|
let that = this
|
|
|
|
that.getMasterInfo()
|
|
|
|
},
|
|
|
|
// 选择头像
|
|
chooseAvatar() {
|
|
let that = this
|
|
wx.chooseMedia({
|
|
count: 1,
|
|
mediaType: ['image'],
|
|
sourceType: ['album', 'camera'],
|
|
success: (res) => {
|
|
const tempFilePath = res.tempFiles[0].tempFilePath;
|
|
// 这里可以添加上传头像到服务器的逻辑
|
|
util.uploadFileUrl(tempFilePath, (res) => {
|
|
let datas = JSON.parse(res)
|
|
console.log(datas.data);
|
|
let url = util.img_url + datas.data.path
|
|
let url2 = datas.data.path
|
|
let fileList = that.data.fileList
|
|
let obj = {
|
|
url: url,
|
|
name: 'avatar'
|
|
}
|
|
fileList.push(obj)
|
|
that.setData({
|
|
fileList,
|
|
avatarUrl: url,
|
|
avatarUrl2:url2
|
|
})
|
|
})
|
|
}
|
|
});
|
|
}
|
|
}); |