123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // 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)
- }
- },
- }
- })
|