| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- // pages/user/user.js
- const api = require('../../config/api.js');
- const util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- birthday: '',
- region: [],
- customItem: '全部',
- gender: 0
- },
- updateNickName(ev) {
- this.setData({
- nickname: ev.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getUserInfo()
- let userInfo = wx.getStorageSync('userInfo')
- userInfo.avatar = userInfo.avatarUrl || 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
- delete userInfo.avatarUrl
- 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'
- if (!data.avatar) {
- data.avatar = 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
- }
- this.setData({
- ...data
- })
- },
- 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(e) {
- const {
- avatarUrl
- } = e.detail
- console.error(e)
- console.log(avatarUrl)
- wx.navigateTo({
- url: './imageCropper?image=' + avatarUrl,
- })
- // console.log( e)
- // console.log( e.detail)
- // 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 })
- // }
- // })
- },
- async save() {
- console.log(this.file)
- 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')
- wx.navigateBack()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|