detail.js 8.69 KB
// pages/reserve/detail.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
import PubSub from '../../utils/PubSub'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seller:{},
    IsCollectionSeller:false,
    pagesHeight:'auto',
    current:0,
    currentView:1,
    hasOnlineReserve:false,
    activeTab:'detail',
    hasFullHouse:false,//满房
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('onLoad', options)
		console.log('初次进入详情页---小米8测试',this.data.reserveDate ? this.data.reserveDate : '没有日期','openid:',getApp().openid)
    this.options=options
    if(options.activeTab && options.activeTab!='detail'){
      this.setData({
        activeTab:options.activeTab||'detail',
      })
    }

    App.Customer.IsCollectionSeller({
      sid:options.id,
      openid:getApp().openid
    }).then(res=>{
      this.setData({
        IsCollectionSeller:res.data,
      })
    })
    this.SetRelaOpenid();
  },
  GetSellerDetail(){
    let options=this.options
    App.Customer.GetSellerDetail({
      sid:options.id,
      lat:this.location.latitude,
      lng:this.location.longitude,
    }).then(res=>{
      if(res.ret==200){
        let seller=res.data
        let seller_tel=[]
        if(seller.seller_tel){
          seller_tel=seller.seller_tel.split(',')
        }else{
          seller_tel=[seller.phone];
        }
        seller.seller_tel=seller_tel
        if(seller.distance || seller.distance!==''){
          seller.distance=parseInt(seller.distance);
          if(seller.distance>1000){
            seller.distanceStr=(seller.distance/1000).toFixed(2)+'公里'
          }else{
            seller.distanceStr=seller.distance+'米';
          }
        }
        if(seller.envi_image.length<1){
          seller.envi_image=['http://qn.colorcun.com/custom/lite-online/image/def-banner.png']
        }
        if(seller.label_c.length>0) {
          let label_cstr=[];
          seller.label_c.forEach(l=>{
            label_cstr.push(l.name)
          })
          seller.label_cstr=label_cstr.join(' | ')
        }
        this.setData({
          seller:seller,
          hasOnlineReserve:seller.is_online_reserve==1,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let path=util.http_build_query({id:this.data.seller.id,fromid:getApp().openid},'/pages/reserve/detail')
    return {
      title:'请客订包间,就上周到安排',
      imageUrl:'https://xt04.colorcun.com/sellerShare/Share_'+this.options.id+'.png?'+Math.random(),
      path:path,
    }
  },
  reserveEvent(e){
    if(this.data.hasOnlineReserve && util.attr(e,'act')!='phone'){
      return this.setData({
        activeTab:'reserve'
      })
    }
    let seller_tel=this.data.seller.seller_tel
    if(seller_tel.length<1) return util.toast('商家电话错误','none')
    if(seller_tel.length==1){//只有一个电话
      let phone=seller_tel[0].replace(/[^\d]/,'')
      wx.makePhoneCall({
        phoneNumber:phone
      })
    }else{
      this.selectComponent('#as').show();
    }
  },
  reservePhone(e){
    if(e.detail.value){
      let phone=e.detail.value.replace(/[^\d]/,'')
      wx.makePhoneCall({
        phoneNumber:phone
      })
    }
    
  },
  follow(){
    let param={
      sid:this.options.id,
      openid:getApp().openid,
    }
    if(this.data.IsCollectionSeller){//已收藏
      param.cancel=1
    }
    let hasFollow=!this.data.IsCollectionSeller
    this.setData({
      IsCollectionSeller:hasFollow
    })
    App.Customer.SetCollectionRel(param);
    PubSub.emit(
      'follow',
      {
        sid:this.options.id,
        hasFollow:hasFollow,
      }
    )
  },
  lookLocation:function(){
    //console.log(this.data.seller.lat,this.data.seller.long,this.data.detail.map_address)
    wx.openLocation({
      latitude:Number(this.data.seller.lat),
      longitude:Number(this.data.seller.long),
      scale:17,
      address:this.data.seller.map_address,
      success:function (res) {
        console.log(res)
      }
    })
  },
  onpos(e){
    console.log(e);
    this.location=e.detail
    this.GetSellerDetail();
  },
  reviweBanner(){
    wx.previewImage({
      current:this.data.seller.envi_image[this.data.current],
      urls:this.data.seller.envi_image
    })
  },
  reviweRoomImage(e){
    wx.previewImage({
      current:util.attr(e,'current'),
      urls:this.data.seller.room_image
    })
  },
  reviweDishesImage(e){
    let urls=[];
    this.data.seller.dishes.forEach(d=>{
      if(d.image){
        urls.push(d.image)
      }
    })
    wx.previewImage({
      current:util.attr(e,'current'),
      urls:urls
    })
  },
  showDiscount(){
    this.selectComponent('#discount').show()
  },
  discountHide(){
    this.setData({
      pagesHeight:'auto'
    })
  },
  discountShow(){
    this.setData({
      pagesHeight:'500rpx'
    })
  },
  shareUserinfo(){
    //util.toast('授权成功,请继续分享','none');
    this.selectComponent('#share').show()
  },
  bindtransition(e){
    this.setData({
      currentView:e.detail.current+1
    })
  },
  async SetRelaOpenid(){
    if(!this.options.fromid) return;
    let openid=await getApp().getOpenid()
    App.Reserve.SetRelaOpenid({
      openid:openid,
      fromid:this.options.fromid,
      sid:this.options.id,
      sub:this.options.hasSellerShare?2:3,//关系类型:1/2/3 邀请关系/商户端分享关系/C端分享关系
    })
  },
  switchTabs(e){
    this.setData({
      activeTab:util.attr(e,'act'),
    })
  },
  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)
		wx.navigateTo({
		  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:'今日所有包间已订满',
    })
  }
})