submit.js 1.98 KB
// pages/reserve/submit.js
import util from '../../utils/util';
import App from '../../utils/api';
const _u = {
  name: '',
  sex: 1,
  phone: '',
  remark: '',
}
Page({
  user: _u,
  /**
   * 页面的初始数据
   */
  data: {
    seller:null,
    user:_u,
  },

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

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  GetSellerDetail() {
    let options = this.options
    App.Customer.GetSellerDetail({
      sid: options.sid,
    }).then(res => {
      if (res.ret == 200) {
        let seller = res.data
        this.setData({
          seller: seller,
        })
      }
    })
  },
  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
      })
    }
  },
  saved() {
    if(!this.user.name){
      return util.toast('请填写姓名','none')
    }
    if(!this.user.phone){
      return util.toast('请填写手机','none')
    }
    App.Customer.SetCustomerInfo({
      ...this.user
    }).then(res=>{
      App.Customer.GetCustomerInfo({},'clear')
      wx.navigateBack()
    })
  },
})