personziliao.js 2.7 KB
// pages/personziliao/personziliao.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:'',
    avatar:'',
    nickname:'',
    brief:''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getuserinfo()
  },
  // 获取用户信息
  getuserinfo() {
    let that = this;
    var url = 'member/index';
    var params = {


    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        userinfo: res,
        avatar: res.avatar,
        nickname: res.nickname,
        brief: res.brief==null?'':res.brief
      })

    }).catch((err) => {

    })
  },
  // 头像
  chooseImage() {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      success: function (res) {
        console.log(res.tempFilePaths[0])
        app.upload('image', res.tempFilePaths[0], "post").then((res) => {
          console.log('上传文件', res);
          let url = app.globalData.baseurl + res.url;
          // that.data.image.push(url)
          // that.data.cimage.push(res.url)
          that.setData({
            avatar: url,
            // cimage: that.data.cimage
          })

          // console.log(that.data.image);
          // console.log(that.data.cimage)


        }).catch((err) => {
          console.log(err)
        })
      },
      fail: function (res) { }
    })
  },
  // 输入昵称
  entername(e){
    this.setData({
      nickname:e.detail.value
    })
  },
// 输入用户简介
  entermark(e){
    this.setData({
      brief:e.detail.value
    })
  },

  // 确定提交
  sub(){
    let that = this;
    var url = 'member/editUserInfo';
    var params = {
      avatar: that.data.avatar,
      nickname: that.data.nickname,
      brief: that.data.brief

    }
    app.post(url, params,"post").then((res) => {
      console.log(res);
      wx.showToast({
        title: '提交成功',
        icon:"none"
      })

      setTimeout(function(){
        wx.navigateBack({
          checked:true
        })
      },1500)



    }).catch((err) => {

    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})