detail_owner.js 10.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
// pages/customer/detail_owner.js
import util from '../../utils/util';
import App from '../../utils/api';
import RS from '../../utils/reserveStatus';
import PubSub from '../../utils/PubSub'
const {regeneratorRuntime} = global
import TP from '../../utils/tpls';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: null,
    hasOnlineReserve: false,
    firstShowMsg:'',
    rsl:[],//推荐商家
    hasCancel:false, //取消预定效果
    hasLoadedCheckout:false,
    subscribeHide:false,//顶部提示
    subscribeYDHide:true,//顶部订阅引导
    loading:0,
  },
  id: null,
  tpls: TP.tpls(),
  hasGetSellerDetail:false,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.id = options.id;
    if(!options.firstShowMsg){
      this.hasGetSellerDetail=true
    }
    let obj={
      firstShowMsg:options.firstShowMsg,
      hasSubscribeFail:options.hasSubscribeFail,
    }
    if(options.firstShowMsg){//从提交预订页进入
      obj.reserveSubmitInfo='预订提交成功,等待餐厅确认'
    }
    this.setData(obj)
    PubSub.on('detailPub',(res)=>{
      console.log(res)
      if(res.type=='cancel'){
        this.setData({
          hasCancel:true,
        })
        setTimeout(()=>{
          wx.pageScrollTo({
            scrollTop:0,
            success:()=>{
              setTimeout(()=>{
                this.setData({
                  hasCancel:false,
                })
              },3000)
            },
          })
        }, 800)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.selectComponent('#getpos').getPos();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDetail()
    App.Customer.CheckIsComment({rid:this.id}).then(res => {
      this.setData({
        hasComment:res.data!=1,//已评论
      })
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    PubSub.off('detailPub')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log('onShareAppMessage', arguments)
    return this.shareSetting(e);
  },
  getDetail(){
    App.Reserve.Detail({
      openid: getApp().openid,
      rid: this.id
    }).then(async res => {
      console.log('App.Reserve.Detail',res.data)
      this.detail=this.formatDatail(res.data)
      this.detail.ddate_solt=Number(this.detail.ddate_solt);
      let Obj={
        detail: this.detail,
        hasOnlineReserve:res.data.type==1,
        loading:1,
      }
      if(this.detail.status==6){
        let room=[]
        this.detail.room_demand.forEach(x=>{
          room.push(x.name)
        })
        Obj.chatbotParams={
          act:'reserveFail',
          room:room.toString(),
          sid:this.detail.seller.id,
          seller:this.detail.seller.sellername,
          soltName:this.detail.soltName,
          rdateStr:util.unixtoTime(this.detail.rdate,'YYYY-MM-DD'),
          id:this.detail.id,
        }
      }
      this.setData(Obj)
      if(this.hasGetSellerDetail){
        let sellerRes=await App.Customer.GetSellerDetail({sid:this.detail.sid})
        let seller=sellerRes.data
        let flag=false,stime='',etime='',time=parseInt(new Date()/1000)
        let today=util.unixtoTime(time,"YYYY-MM-DD")
        stime=util.timetouUnix(today+' '+seller.rec_stime+':00')
        etime=util.timetouUnix(today+' '+seller.rec_etime+':00')
        if(etime<=stime){
          if(time<=etime){
            flag=true
          }
          etime+=86400
        }
        if(!flag){
          if(time>=stime && time<=etime){
            flag=true;
          }
        }
        let firstShowMsg='预计10分钟左右餐厅将告知您结果(请留意短息或微信通知)'
        if(!flag){
          firstShowMsg=seller.rec_stime
        }
        this.setData({
          firstShowMsg:firstShowMsg,
        })
      }
      //this.GetBalance()//余额
      this.GetCheckout()//账单
      //清理预订消息
      setTimeout(()=>{this.setData({reserveSubmitInfo:''})},3000)
    })
  },
  formatDatail(detail) {
    detail.rdateStr = util.unixtoTime(detail.ddate, 'MM月DD日 WW HH:II');
    detail=RS.reserve(detail);
    if(typeof detail.seller.seller_tel=='string'){
      detail.seller.seller_tel=detail.seller.seller_tel.split(',');
    }
    return detail;
  },
  showManager() {
    this.selectComponent('#manager').show();
  },
  lookLocation: function () {
    wx.openLocation({
      latitude: Number(this.data.detail.seller.lat),
      longitude: Number(this.data.detail.seller.long),
      scale: 17,
      address: this.data.detail.seller.map_address,
      success: function (res) {
        console.log(res)
      }
    })
  },
  userinfo(e) {
    console.log('userinfo', e)
    util.toast('授权成功,可以继续转发', 'none');
    // wx.navigateTo({
    //     url:'invite?id='+this.id,
    // });
  },
  shareSetting(e) {
    console.log('shareSetting', e.target.dataset);
    let hasInvitation = e.target.dataset.act == 'invitation';
    if (this.topicVal && this.data.detail.openid == getApp().openid) {
      App.Reserve.SetTopicFromShare({
        rid: this.id,
        topic: this.topicVal
      })
    }
    let nickname = "";
    try {
      nickname = util.cache('userInfo').nickName;
    } catch (e) {
    }
    let obj = {
      //title: (nickname || '') + '给你发了一个邀请,点击查看',
      title: this.tpls[0].shareTitle,
      path: '/pages/customer/index?id=' + this.id + '&fromid=' + getApp().openid + '&invite_name=' + nickname + '&hasInvitation=1&tplid=1',
      imageUrl: this.tpls[0].shareImage,
    }
    if (hasInvitation) {
      //obj.title=(nickname || '') + '给你发了一个邀请函,点击查看';
      obj.path = obj.path + '&hasInvitation=1';
    }
    return obj;
  },
  cookbook() {
    if (this.data.detail.order && this.data.detail.order.cookbooklist.length > 0) {
      wx.navigateTo({
        url: util.http_build_query({
          rid: this.id,
          oid: this.data.detail.order.id,
          identity: 1
        }, '/pack-cookbook/pages/success')
      });
    } else {
      App.Advance.CreateOrder({
        rid: this.id,
        openid: getApp().openid,
      }).then(res => {
        if (res.ret != 200) {
          return util.toast(res.msg, 'none')
        }
        wx.navigateTo({
          url: util.http_build_query({
            rid: this.id,
            oid: res.data.id,
            identity: 1,
            sid: res.data.sellerid
          }, '/pack-cookbook/pages/index')
        });
      })
    }

  },
  wineGo() {
    util.toast('本区域暂无配送人员', 'none');
  },
  callSeller(){
    if(this.data.detail.seller.is_online_reserve==1 && this.data.detail.seller.is_tele==0){
      //在线预定没有话机
      return wx.makePhoneCall({
        phoneNumber:'400-000-9690'
      })
    }
    let seller_tel=this.data.detail.seller.seller_tel
    console.log('seller_tel',seller_tel,typeof 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();
    }
  },
  callSellerPhone(e){
    if(e.detail.value){
      let phone=e.detail.value.replace(/[^\d]/,'')
      wx.makePhoneCall({
        phoneNumber:phone
      })
    }
  },
  cardEvent(e){
    console.log(e)
  },
  GetRecommendSellerList(sid){
    let param={
      sid:sid,
    }
    if(this.location){
      param.lat=this.location.latitude
      param.lng=this.location.longitude
    }
    App.Customer.GetRecommendSellerList(param).then(res=>{
        this.setData({
          rsl:res.data
        })
    })
  },
  hasGoto:false,
  bindtransition(e){
    if('change'==e.type){
      this.hasGoto=false
    }
    if('animationfinish'==e.type){
      if(this.hasGoto){
        wx.switchTab({
          url: '/pages/reserve/index'
        })
        return;
      }else{
        this.hasGoto=true
      }
    }
  },
  location:null,
  onpos(e){
    console.log('onpos',e);
    this.location=e.detail
    if(!this.detail){
      return setTimeout(()=>{
        this.onpos(e)
      },500)
    }
    /*
    if(this.detail.type==1 && this.detail.status==6){
      this.GetRecommendSellerList(this.detail.seller.id)
    }
    */
  },
  gotoSellerDetail(e){
    console.log(e)
    let url='/pages/reserve/detail?id='+e.currentTarget.id
    wx.navigateTo({
      url:url,
    })
  },
	onUnload(){
		let pages = getCurrentPages();
		if(pages.length>2 && pages[pages.length-2].route=='pages/reserve/detail'){
			wx.setStorageSync('order', 'complete')
		}
		console.log(pages)
	},
  GetBalance(){//获得余额
    App.User.GetBalance().then(res=>{
      this.setData({
        user:res.data
      })
    })
  },
  GetCheckout(){
    App.Customer.GetOrderInfo({rid:this.options.id}).then(res=>{
      this.setData({
        checkout:res.data,
        hasLoadedCheckout:true,
      })
    })
  },
  checkout(){
	  if(this.data.detail.status==0){
      this.selectComponent('#showModal').options({
        header: '您点早啦!',
        body: '商家分配包间后,您可以通过在线买单支付,无需到前台结账排队等发票。'
      }).show();
    }else{
      wx.navigateTo({
        url:util.http_build_query({
          rid:this.data.detail.id,
          sid:this.data.detail.sid
        },'/pack-checkout/pages/index')
      })
    }
  },
  subscribeHide(){
    this.setData({
      subscribeHide:true,
    })
  },
  subscribeYDHide(){
    this.setData({
      subscribeYDHide:true,
    })
  },
  subscribeFailHide(){
    this.setData({
      hasSubscribeFail:false,
    })
  },
  subscribeEvent(e){
    this.setData({
      subscribeYDHide:e.detail.type=='success',
    })
  },
  sbtrEvent(e){
    console.log(e);
    if(e.detail.act=='oncall'){
      this.selectComponent('#as-phone').show(e.detail.seller);
    }
  },
  gotoList(){
    //lat=39.65273&lng=118.15813&map={"errMsg":"getMapRegion:ok","southwest":{"longitude":118.1345633729553,"latitude":39.60932290660337},"northeast":{"longitude":118.15065662704465,"latitude":39.6213565704009},"scale":15}&multiIndex=0&centre_pos=39.615340,118.142610&hasSuggestion=1&keyword=西电路10号
    wx.navigateTo({
      url:util.http_build_query({
        hasSuggestion:1,
        keyword:this.detail.seller.sellername,
        lat:this.detail.seller.lat,
        lng:this.detail.seller.long,
        centre_pos:`${this.detail.seller.lat},${this.detail.seller.long}`,
        multiIndex:0,
      },'/pages/reserve/indexList')
    })
  },
})