detail.js 8.69 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'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:0,
    currentView:1,
    meTop:20,
    hasBack:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.options=options
    this.downloadImages()
    App.Customer.IsCollectionSeller({
      sid:options.id,
      openid:getApp().openid
    }).then(res=>{
      this.setData({
        IsCollectionSeller:res.data,
      })
    })
    this.SetRelaOpenid();
    App.Customer.BindClicks({sid:options.id})
    App.Task.GetTaskInfo({pos:'home'}).then(res=>{
      if(res.data.activity){
        this.setData({
          hasPTactivity:true,
        })
      }
    });
    App.Customer.GetCountCommentLabel({sid:options.id}).then(res=>{
      this.setData({
        commentLabel:res.data,
      })
    })
    if(getCurrentPages().length==1){
      this.setData({
        hasBack:false,
      })
    }
  },
  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://nosqn.colorcun.com/custom/lite-online/image/def-banner.png']
        }else{
          seller.envi_image.some((url,i)=>{
            seller.envi_image[i]=url.replace('//qn.colorcun','//nosqn.colorcun')
          })
        }
        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(' | ')
        }
        if(seller.room_image.length>0){
          seller.room_image.some((url,i)=>{
            seller.room_image[i]=url.replace('//qn.colorcun','//nosqn.colorcun')
          })
        }
        let hasDishesImage=false;
        let hasDishesText=false;
        if(seller.dishes.length>0){
          seller.dishes.some((dishes)=>{
            if(dishes.image){
              hasDishesImage=true
              dishes.image=dishes.image.replace('//qn.colorcun','//nosqn.colorcun')
            }else{
              hasDishesText=true
            }
          })
        }
        if(seller.card_info){
          let xff=[]
          seller.card_info.forEach(card=>{
            seller['receive_condition_'+card.receive_condition]=true
            if(card.receive_condition==2){
              xff.push(`满${card.order_price}元返${card.price}元`)
            }
          })
          if(xff.length>0){
            seller.receive_condition_str=xff.join('/')
          }
        }
        seller.activityStr=[];
        if(seller.activity.length>0){
          seller.activity.forEach(a=>{
            seller.activityStr.push(a.title)
          })
        }
        seller.activityStr=seller.activityStr.join(';')
        //seller.isopen_md=0;
        //seller.card_info=[]
        let obj={
          seller:seller,
          hasDishesImage:hasDishesImage,
          hasDishesText:hasDishesText,
          hasOnlineReserve:seller.is_online_reserve==1,
          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.selectComponent('#getpos').getPos();
    if(wx.getMenuButtonBoundingClientRect){
      let rect=wx.getMenuButtonBoundingClientRect()
      this.setData({
        meTop:rect.top-5,
      })
    }
    if(wx.createIntersectionObserver){
      this._observer = wx.createIntersectionObserver(this)
      this._observer
        .relativeTo('.me')
        .observe('.swiper-view', (res) => {
          if(res.intersectionRatio > 0){
            wx.setNavigationBarColor({
              frontColor:'#ffffff',
              backgroundColor:'#ffffff',
            })
          }else{
            wx.setNavigationBarColor({
              frontColor:'#000000',
              backgroundColor:'#ffffff',
            })
          }
          this.setData({
            hasNav: res.intersectionRatio == 0
          })
        })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  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
  },
  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端分享关系
    })
  },
  onpos(e){
    console.log(e);
    this.location=e.detail
    this.GetSellerDetail();
  },
  bindtransition(e){
    this.setData({
      currentView:e.detail.current+1
    })
  },
  reviweBanner(){
    let urls=[];
    this.data.seller.envi_image.forEach(url=>{
      if(url){
        urls.push(url+zdmask)
      }
    })
    wx.previewImage({
      current:this.data.seller.envi_image[this.data.current]+zdmask,
      urls:urls
    })
  },
  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)
      }
    })
  },
  sellerPhone(e){
    this.selectComponent('#as').show(this.data.seller);
  },

  showDiscount(){
    this.selectComponent('#discount').show()
  },
  discountHide(){
    this.setData({
      hasDisplayDiscount:false
    })
  },
  discountShow(){
    this.setData({
      hasDisplayDiscount:true
    })
  },
  reviweRoomImage(e){
    let urls=[];
    this.data.seller.room_image.forEach(url=>{
      if(url){
        urls.push(url+zdmask)
      }
    })
    wx.previewImage({
      current:util.attr(e,'current')+zdmask,
      urls:urls
    })
  },
  reviweDishesImage(e){
    let urls=[];
    this.data.seller.dishes.forEach(d=>{
      if(d.image){
        urls.push(d.image+zdmask)
      }
    })
    wx.previewImage({
      current:util.attr(e,'current')+zdmask,
      urls:urls
    })
  },
  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,
      }
    )
  },
  shareDisplay(){
    this.selectComponent('#share').show()
  },
})