setting.js 1.38 KB
// pages/me/setting.js
import util from '../../utils/util';
import App from '../../utils/api';

const {regeneratorRuntime} = global
const _u = {
  name: '',
  sex: 1,
  phone: '',
  remark: '',
}
Page({

  /**
   * 页面的初始数据
   */
  user: _u,
  data: {
    user: _u
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    App.Customer.GetCustomerInfo().then(res=>{
      this.user = res.data
      this.setData({
        user: res.data,
      })
    })
  },

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

  },

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

  },

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

  },

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

  },

  saved() {
    if(!this.user.name){
      return util.toast('请填写预定人','none')
    }
    App.Customer.SetCustomerInfo({
      ...this.user
    }).then(res=>{
      App.Customer.GetCustomerInfo({},'clear')
      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
      })
    }
  },
})