submit.js 3.06 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,
    detail: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,
          detail:{
            ddate:options.ddate,
            pnum:options.pnum,
          }
        })
      }
    })
  },
  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.SetReserveInfo({
      sid:this.options.sid,
      pnum:this.options.pnum,
      ddate:this.options.ddate,
      rdate:this.getRdate(),
      rname:this.user.name,
      sex:this.user.sex,
      phone:this.user.phone,
      cusdem:this.user.remark||'',
    }).then(res=>{
      if(res.ret!=200){
        return util.toast(res.msg,'none');
      }
      if(res.data.hasSetUserInfo){
        App.Customer.GetCustomerInfo({},'clear')
      }
      wx.redirectTo({
        url:util.http_build_query({
          id:res.data.rid,
          hasFirstShow:1,
        },'/pages/customer/detail_owner')
      })
    })
  },
  getRdate(){
    let daily=this.data.seller.daily;
    let ddate=util.unixtoTime(this.options.ddate,'YYYY-MM-DD,HH:II').split(',');
    let rd=['00:00','00:00'];
    Object.keys(daily).forEach((k)=>{
      let t=daily[k].split('-')
      if(t[0]<=ddate[1] && ddate[1]<=t[1]){
        rd=t;
      }
    })
    return util.timetouUnix(ddate[0]+' '+rd[0]+':00')+'-'+util.timetouUnix(ddate[0]+' '+rd[1]+':00')
  },
  editorReserve(){
    wx.navigateBack()
  },
  getphoneNumber(e){
    console.log('getphoneNumber',e);
  },
})