123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- // pages/user/user.js
- const api = require('../../config/api.js');
- const util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- birthday: '',
- region: [],
- customItem: '全部',
- gender: 0,
- mobile: null
- },
- updateNickName(ev) {
- this.setData({nickname: ev.detail.value})
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getUserInfo()
- let userInfo = wx.getStorageSync('userInfo') || {}
- userInfo.avatar = userInfo.avatarUrl
- this.sessionKey = userInfo.sessionKey
- delete userInfo.avatarUrl
- delete userInfo.sessionKey
- this.setData({ ...userInfo })
- },
- loginSuccess() {
- this.onLoad()
- },
- async getUserInfo() {
- const {data} = await util.request(api.UserInfo)
- data.region = data.city ? data.city.split(',') : []
- data.birthday = data.birthday || '1990-01-01'
- this.setData({
- ...data
- })
- },
- async getPhoneNumber(e) {
- let {encryptedData,iv} = e.detail
- console.log(e)
- if (!encryptedData) return;
- let res = await util.request(api.decryptedPhoneNum, { encryptedData, iv, sessionKey: this.sessionKey })
- console.log(res)
- this.setData({
- mobile: res.phoneNum
- })
- },
- updateSex(e) {
- this.setData({gender: e.currentTarget.dataset.sex})
- },
- bindDateChange(e) {
- this.setData({ birthday: e.detail.value })
- },
- bindRegionChange (e) {
- this.setData({ region: e.detail.value })
- },
- selectPhoto() {
- wx.chooseImage({
- count: 1,
- sizeType: 'compressed',
- success: (res) => {
- const src = res.tempFilePaths[0]
- // this.file = res.tempFiles[0]
- wx.navigateTo({
- url: './imageCropper?image=' + src,
- })
- // this.setData({ avatar: src })
- }
- })
- },
- changPhone(e){
- this.setData({
- 'mobile': e.detail.value,
- });
- },
- async save(e) {
- let type = e.currentTarget.dataset.type
- console.log(e)
- if (this.file) {
- let avatar = await (new Promise(r => {
- wx.uploadFile({
- filePath: this.data.avatar,
- name: 'file',
- url: api.UploadFile,
- header: {'X-Nideshop-Token': wx.getStorageSync('token')},
- success: (res) => {
- this.file = null
- r(JSON.parse(res.data).data)
- }
- })
- }));
- this.data.avatar = avatar
- }
- this.data.city = this.data.region && this.data.region.join(',')
- const body = {...this.data}
- delete body.region
- const {data} = await util.request(api.UpdateUserInfo, body, 'POST', 'application/json')
- if(type=='1'){
- wx.navigateBack()
- }else{
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|