detail_invitation.js 8.72 KB
// pages/customer/detail_owner.js
var mta = require('mta-wechat-analysis')
import util from '../../utils/util';
import App from '../../utils/api';
import TP from '../../utils/tpls';
import RS from '../../utils/reserveStatus'
const {regeneratorRuntime} = global
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: null,
    height: 667,
    current: 0,
    tpls: [],
    seller: {
      name: '',
      room: '',
      date: '',
      addr: ''
    },
    options: {tplid: ''},
    hasOwner: false,//是否为发起人
    animation: 'animation',
  },
  id: null,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.id = options.id;
    let param={
      options:options,
      hasOwner:options.hasSellerShare==1,//是否为发起人
    }
    param.tpls=[TP.tpls(options.tplid)]
    this.setData(param)
    mta.Page.init({
      "appID": "500667280",
      "eventID": "500667287",
      "statPullDownFresh": true,
      "statShareApp": true,
      "statReachBottom": true,
      "lauchOpts": options, //渠道分析
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //导航栏自适应
    let systemInfo = wx.getSystemInfoSync();
    let reg = /ios/i;
    let pt = 20;//导航状态栏上内边距
    let h = 44;//导航状态栏高度
    if (reg.test(systemInfo.system)) {
      pt = systemInfo.statusBarHeight;
      h = 44;
    } else {
      pt = systemInfo.statusBarHeight;
      h = 48;
    }
    this.setData({
      statusBarHeight: pt,
      titleBarHeight: h,
      height: systemInfo.windowHeight
    })
    this.getDetail();
  },
  call(){
  	wx.makePhoneCall({
  	  phoneNumber: this.data.staffinfo.phone //仅为示例,并非真实的电话号码
  	})  
  },
  test(e){
  	console.log('ttttttttttttttt');
  	  App.Contact.UploadCustomerMedia({url:this.data.staffinfo.qrcode}).then((json)=>{
  		if(json.ret==200) {
  			console.log('json')
  		} 
  	  })
  },
  addwechat(){
  	wx.previewImage({
  	  current: this.data.staffinfo.qrcode, // 当前显示图片的http链接
  	  urls: [this.data.staffinfo.qrcode] // 需要预览的图片http链接列表
  	})  
  	// util.cache('staffinfo',this.data.staffinfo);
  	// wx.navigateTo({
  	// 	url:'./care'
  	// })
  },
  getstaffinfo(){
  	App.Activity.GetCustomerActivityBaseinfo({sellerid:this.data.detail.seller.id,uid:this.data.options.uid}).then((json)=>{
  		if(json.ret==200){
  			console.log(json)
  			this.setData({
  				staffinfo:json.data
  			})
  		}
  	})  
  },
  getroomimage(){
  	  App.Photo.getSellerPhotoById({sellerid:this.data.detail.seller.id,type:2}).then((json)=>{
  		if(json.ret==200){
  			this.setData({
  				roomimage:json.data
  			})
  			let urls=[];
  			json.data.forEach((v,i)=>{
  				urls.push(v.image);
  			})
  			this.urls=urls;
  			console.log(urls,'lllllll')
  		}  
  	  })
  },
  lookroom(){
  	wx.previewImage({
  	  current: '', // 当前显示图片的http链接
  	  urls: this.urls, // 需要预览的图片http链接列表
  	})   
  },
  secondbook(){
  	wx.redirectTo({
  		url:'../reserve/detail?id='+this.data.detail.seller.id
  	})  
  },
  getactivity(){
  	    App.Activity.GetActivityByRid({rid:this.id}).then((json)=>{
  		  if(json.ret==200){
  			  console.log(json.data);
  			  this.setData({
  				  list:json.data
  			  })
  		  }
  	    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return this.shareSetting();
  },
  getDetail(fouce = false){
    App.Reserve.Detail({
      openid: getApp().openid,
      rid: this.id
    }, fouce).then(res => {
      let tables=[];
      res.data.tables.forEach(t=>{
        tables.push(t.name);
      })
      let reserev=RS.reserve(res.data)
      console.log('reserev',reserev)
      let dateSmart
      if(res.data.type==1){
        dateSmart=util.unixtoTime(reserev.ddate,this.data.tpls[this.data.current].timeStrSmart[0])
        if(res.data.is_set_ddate==1){
          dateSmart+=' '+util.unixtoTime(reserev.ddate,this.data.tpls[this.data.current].timeStrSmart[1])
        }else{
          dateSmart+=' '+reserev.soltName
        }
      }else{
        dateSmart=util.unixtoTime(reserev.ddate,this.data.tpls[this.data.current].timeStr)
      }
      this.setData({
        detail: this.formatDatail(res.data,dateSmart),
        seller:{
          name:res.data.seller.sellername,
          room:tables.join('、'),
          date:dateSmart,
          addr:res.data.seller.real_address||res.data.seller.map_address,
          image:res.data.image_url,
        }
      })
	  if(this.data.detail.type==0){
	  		this.getstaffinfo();
	  		this.getroomimage(); 
	  		this.getactivity();
	  }
    })
  },
  formatDatail(detail,dateSmart){
    detail.rdateStr = dateSmart;
    detail.tableFirst = detail.tables[0].name;
    if (detail.tables.length > 1) {
      detail.tableSubInfo = '等' + (detail.tables.length) + '个'
        + (detail.tables[0].tid == 2 ? '包间' : '');
    }
    if (detail.sex != 3) {
      detail.rnameStr = detail.rname.substr(0, 1) + (detail.sex == 1 ? '先生' : '女士')
    } else {
      detail.rnameStr = detail.rname
    }
    detail.eatStr = '邀请您共进晚餐';
    let hi = util.unixtoTime(detail.ddate, 'HHII');
    if (hi < '10:00') {
      detail.eatStr = '邀请您共进早餐';
    } else if (hi < '15:00') {
      detail.eatStr = '邀请您共进午餐';
    }

    // if(!detail.cusman){
    //     detail.cusman='vking';
    //     detail.cusman_phone='15877556369';
    //     detail.cusman_account='wx:vking';
    // }
    detail.hasCanSuccess = false;
    if (detail.customers.length > 0) {
      let openid = getApp().openid;
      detail.customers.forEach(item => {
        if (openid == item.openid) {
          detail.hasCanSuccess = true;
          detail.remindtime = item.remind_date;
          return true;
        }
      })
    }
    return detail;
  },
  showManager(){
    if (this.data.detail.cusman_phone || this.data.detail.cusman_account) {
      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)
      }
    })
  },
  confirmed(){
    if (!this.data.detail.hasCanSuccess) {
      let userInfo = util.cache('userInfo');
      if (userInfo) {
        userInfo = JSON.stringify({
          openid: getApp().openid,
          avatar: userInfo.avatarUrl,
          nickname: userInfo.nickName,
          gender: userInfo.gender
        })
      }
      App.Reserve.SetRelaSuccess({
        rid: this.id,
        openid: getApp().openid,
        is_agree: 1,
        userinfo: userInfo
      }).then(res => {
        this.setData({
          [`detail.hasCanSuccess`]: true
        })
        App.Reserve.Detail({
          openid: getApp().openid,
          rid: this.id
        }, 'clear')
        util.toast('赴约成功', 'none')
        let url='/pages/customer/list'
        if(parseInt(this.data.detail.ddate)-(new Date()/1000)>3600){
          if(this.data.detail.type==1){
            if(this.data.detail.is_set_ddate==1){
              url='/pages/customer/list?hasRelaTip=1'
            }
          }else{
            url='/pages/customer/list?hasRelaTip=1'
          }
        }
        wx.reLaunch({
          url: url
        })
      })
    } else {
      util.toast('赴约成功', 'none')
    }
  },
  setUserInfoSuccess(){
    util.toast('授权成功,可以继续转发', 'none');
  },
  reserveCancel(){
    let userInfo = util.cache('userInfo');
    if (userInfo) {
      userInfo = JSON.stringify({
        openid: getApp().openid,
        avatar: userInfo.avatarUrl,
        nickname: userInfo.nickName,
        gender: userInfo.gender
      })
    }
    App.Reserve.SetRelaSuccess({
      rid: this.id,
      openid: getApp().openid,
      cancel: 'cancel',
      is_agree: 0,
      userinfo: userInfo
    }).then(res => {
      this.getDetail(true);
    })
  },
  shareSetting(){
    return {
      //title: (nickname||'')+'给你发了一个邀请,点击查看',
      title: this.data.tpls[0].shareTitle,
      path: util.http_build_query({
        id:this.id,
        fromid:getApp().openid,
        hasInvitation:1,
        tplid:this.data.options.tplid,
      },'/pages/customer/index'),
      imageUrl: this.data.tpls[0].shareImage,
    }
  },
  gotoHome(){
    wx.switchTab({
      url: '/pages/reserve/index'
    })
  },
})