reserve.js 6.86 KB
// pages/reserve/detail.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
const zdmask='-zdmask?v=1.2'
import PubSub from '../../utils/PubSub'
const slots={'morning':1,'noon':2,'night':3}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:0,
    seller:null,
    hasFullHouse:false,//满房
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(wx.getStorageSync('remark')){
      wx.removeStorageSync('remark')
    }
    console.log('onLoad', options)
    console.log('初次进入详情页---小米8测试',this.data.reserveDate ? this.data.reserveDate : '没有日期','openid:',getApp().openid)
    this.options=options
    this.downloadImages()
    if(options.activeTab && options.activeTab!='detail'){
      this.setData({
        activeTab:options.activeTab||'detail',
      })
    }
    this.setData({
      reserveDate: options.date ? options.date : util.unixtoTime(new Date() / 1000, 'YYYY-MM-DD'),
    })
    if(options.act=='update'){//修改预订
      //act=update&section=night&time=16:00&date=2020-12-27&sid=1&ddate=1609056000&room_demand=[{"id":"30","name":"6人间"},{"id":"31","name":"10人间"},{"id":"32","name":"12人间"}]
      this.setData({
        reserveDate: options.date,
        seletroomlist:JSON.parse(options.room_demand),
        reserveSection:options.section
      })
      this.reserve.section=options.section;
      this.reserve.time=options.time;
    }
  },
  GetSellerDetail(){
    let options=this.options
    App.Customer.GetSellerDetail({
      sid:options.id,
    }).then(res=>{
      if(res.ret==200){
        let seller=res.data
        let obj={
          seller:seller,
          loading:1,
        }
        if(this.options.classID){
          obj.seletroomlist=[{
            id:this.options.classID,
            name:this.options.className,
          }]
          delete this.options.classID
          delete this.options.className
        }
        this.setData(obj)
      }
    }).catch(e=>{
      util.toast('网络出错,请尝试重新进入',none)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.GetSellerDetail();
    if (this.data.reserveDate && this.data.seletroomlist){//后退进入等情况刷新时段
      this.setData({
        reserveDate:this.data.reserveDate
      })
    }
    //已经完成预订的情况---清除日期、时段、选中包间
    if(wx.getStorageSync('order')){
      this.setData({
        seletroomlist:[],
      })
      wx.removeStorageSync('order')
    }

  },

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

  },

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

  },

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

  },

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

  },
  shareImageTmp:'',
  downloadImages(){
    wx.downloadFile({
      url:'https://xt04.colorcun.com/sellerShare/Share_'+this.options.id+'.png?'+Math.random(),
      success:res=>{
        this.shareImageTmp=res.tempFilePath
      },
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let path=util.http_build_query({id:this.data.seller.id,fromid:getApp().openid},'/pages/reserve/detail')
    //let imageUrl='http://sellershare.colorcun.com/Share_'+this.options.id+'.png?imageView2/2/w/180/interlace/0'
    let shareParams={
      title:'请客订包间,就上周到安排',
      path:path,
    }
    if(this.shareImageTmp){
      shareParams.imageUrl=this.shareImageTmp
    }
    console.log('shareParams==>',shareParams)
    return shareParams
  },


  reserve:{},
  selectpeople(e){//人数改变
    console.log(e);
    this.reserve.pnum=e.detail.people;
    if(e.detail.action=='click'){

    }
  },
  //时段改变
  selectsection(e){
    console.log(e);
    setTimeout(()=>{
      this.setData({
        reserveSection:e.detail.section!='' ? e.detail.section : null,
        seletroomlist:e.detail.action=='click' ? [] : this.data.seletroomlist,
      })
    },0)

    this.reserve.section=e.detail.section;
    this.reserve.time=e.detail.time;
  },
  //包间类型改变
  selectroom(e){
    console.log(e)
    this.setData({
      seletroomlist:e.detail.selectroom
    })
  },
  complete(){
    if(!this.data.reserveSection){
      return util.toast('请选择可预订的时段','none');
    }
    if(!this.data.seletroomlist || (this.data.seletroomlist && this.data.seletroomlist.length==0)){
      return util.toast('请选择包间类型','none');
    }
    this.reserve.sid=this.options.id
    this.reserve.ddate=util.timetouUnix(this.reserve.date+' '+this.reserve.time+':00');
    this.reserve.room_demand=JSON.stringify(this.data.seletroomlist)
    if(this.options.pnum){
      this.reserve.pnum = this.options.pnum;
    }
	
	App.Reserve.GetReserveIsExits({sid:this.reserve.sid,ddate_solt:slots[this.reserve.section],ddate:this.reserve.ddate}).then((json)=>{
		console.log(json)
		if(json.ret==200){
			if(json.data==1){
				wx.showModal({
					content:'您在该店铺已有一个订单待处理,是否加订一间?',
					confirmText:'是',
					concelText:'否',
					cancelColor:'#999999',
					success:(res)=>{
						if(res.confirm){
							wx.redirectTo({
							  url:util.http_build_query(this.reserve,'./submit')
							})
						}
					}
					
				})
			}else{
				wx.redirectTo({
				  url:util.http_build_query(this.reserve,'./submit')
				})
			}
		}
	})
    // wx.redirectTo({
    //   url:util.http_build_query(this.reserve,'./submit')
    // })
  },
  selecttime(e){//时间改变
    console.log(e);
    if(!e.detail.time){//满房
      this.setData({
        hasFullHouse:true,
      })
      return;
    }
    this.reserve.time=e.detail.time;
    if(e.detail.action=='click'){
      this.reserve.sid=this.options.id
      this.reserve.ddate=util.timetouUnix(this.reserve.date+' '+this.reserve.time+':00')
      //date=2019-07-25&pnum=6&time=20%3A00&sid=154&ddate=1564056000
      wx.navigateTo({
        url:util.http_build_query(this.reserve,'./submit')
      })
    }
  },
  selectdate(e){//日期改变
    if(e.detail.action==401){//无可用桌位
      return;
    }
    console.log('selectdate',e);
    if(e.detail.overdate==1){//今天之前
      return this.setData({
        hasFullHouse:true,
        fullHouseMsg:'请选择今天之后的日期',
      })
    }
    this.reserve.date=e.detail.date;
    this.setData({
      reserveDate:e.detail.date,
      seletroomlist:e.detail.action=='click' ? [] : this.data.seletroomlist,
      hasFullHouse:false,
      reserveSection:e.detail.action=='click' ? null : this.data.reserveSection,
      fullHouseMsg:'今日所有包间已订满',
    })
  }
})