setting.js 1.43 KB
// pages/me/setting.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
const _u={
    name:'',
    sex:1,
    phone:'',
    cusdem:'',
}
Page({

  /**
   * 页面的初始数据
   */
  user:_u,
  data: {
    user:_u
  },
  cache_key:'me-setting',
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      wx.getStorage({
          key:this.cache_key,
          success:(res)=>{
            if(res.data){
              this.user=res.data
              this.setData({
                  user:res.data,
              })
            }
          }
      })
  },

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

  },

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

  },

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

  },

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

  },

    saved(){

        wx.setStorage({
            key:this.cache_key,
            data:this.user,
        })
        wx.navigateBack()
    },
    changeInput(e){
      let key=util.attr(e,'key');
        let val=''
      if(key=='sex'){
          val=util.attr(e,'val');
      }else{
          val=util.val(e);
      }
      this.user[key]=val;
      if(key=='sex'){
        this.setData({
            user:this.user
        })
      }
    }
})