// component/profilePatch.js const api = require('../../config/api') const util = require('../../utils/util.js'); const services = require('../../services/user.js'); Component({ /** * 组件的属性列表 */ properties: { show: { // 属性名 type: Boolean, value: false, }, }, /** * 组件的初始数据 */ observers: { show: function (val) { // 在 numberA 或者 numberB 被设置时,执行这个函数 console.log('gemer', val) this.setData({ ifShow: val }) } }, data: { ifShow: true, bottom: 0, defaultAvatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png', avatar: '', nickname: '', mobile: '', }, attached() { // this.setData({ // bottom: 0 // }) // debugger }, /** * 组件的方法列表 */ methods: { updateNickName(ev) { this.setData({ nickname: ev.detail.value }) }, quitHandle: function () { getApp().setLoginProps(true) }, async onChooseAvatar(e) { const { avatarUrl } = e.detail const dataURL = await (new Promise(r => { wx.uploadFile({ filePath: avatarUrl, name: 'file', url: api.UploadFile, header: { 'X-Nideshop-Token': wx.getStorageSync('token') }, success: (res) => { const data = JSON.parse(res.data) r(data.message || defaultAvatarUrl) } }) })); console.log('upload-file', dataURL) this.setData({ avatar: dataURL, }) }, async updateUserInfo() { const { avatar, nickname, mobile, } = this.data if (avatar == '' || nickname == '' || mobile =='') { return } const { data: getUserData } = await util.request(api.UserInfo) const body = { userId: getUserData.userId, avatar: this.data.avatar, nickname: this.data.nickname, mobile:this.data.mobile } console.error('userInfo', body) const { data } = await util.request(api.UpdateUserInfo, body, 'POST', 'application/json') console.log('data', data) // wx.setStorageSync('token', data.token); const lastUpdate = { ...getUserData, ...body } console.error('userInfo-lastUpdate', lastUpdate) wx.setStorageSync('userInfo', lastUpdate); this.setData({ ifShow: false }) this.triggerEvent('save', lastUpdate) }, async getPhoneNumber(e) { try { const isLogin = await services.checkLogin(); let userInfo = wx.getStorageSync('userInfo') if (!isLogin) { await services.loginByWeixin(userInfo) } let { encryptedData, iv, code } = e.detail console.log(e) if (!encryptedData) return; let res = await util.request(api.decryptedPhoneNum, { encryptedData, iv, code, sessionKey: userInfo.sessionKey }) console.log(res) this.setData({ mobile: res.phoneNum }) } catch (error) { console.log('error', error) } }, } })