detail_owner_invitation.js 7.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
import ST from '../../utils/sms_tpls';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: null,
    height: 667,
    current: 0,
    tpls: [],
    seller: {
      name: '',
      room: '',
      date: '',
      addr: ''
    },
    options: {tplid: ''},
    hasOwner: true,//是否为发起人
    animation: 'animation',
  },
  id: null,
  msgTpl:'',
  /**
   * 生命周期函数--监听页面加载
   */
  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(getCurrentPages().length==1);
  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return this.shareSetting();
  },
  getDetail(fouce = false){
    App.Reserve.Detail({
      openid: getApp().openid,
      rid: this.data.options.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(reserev,dateSmart),
        seller:{
          name:reserev.seller.sellername,
          room:tables.join('、'),
          date:dateSmart,
          addr:reserev.seller.real_address||reserev.seller.map_address,
          image:reserev.image_url,
          hasOwner:true,
          type:reserev.type,
          is_set_ddate:reserev.is_set_ddate,
          hasUpTime:reserev.type==1 && reserev.hasRunning && reserev.status!=2,
        }
      })
      App.Reserve.SellerInfo({seller_id:reserev.seller.id}).then(async sc=>{
        this.msgTpl=await ST.getTplMsg(reserev,sc.data.setting.template_code,sc.data)
        console.log('this.msgTpl',this.msgTpl);
      })
    })
  },
  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=RS.reserve(detail);
    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)
      }
    })
  },
  userinfo(){
    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 => {
        App.Reserve.Detail({
          openid: getApp().openid,
          rid: this.id
        }, 'clear')
        wx.navigateTo({
          //id={{detail.id}}&rdate={{detail.rdate}}
          url: 'remind?id=' + this.id + '&rdate=' + this.data.detail.rdate,
        });
      })
    } else {
      // wx.navigateTo({
      //     url:'invite?id='+this.id,
      // });
    }
  },
  setUserInfoSuccess(){
    util.toast('授权成功,可以继续转发', 'none');
  },
  toast(){
    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: 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,
    }
  },
  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')
        });
      })
    }
  },
  sendmsg(){
    wx.setClipboardData({
      data: this.msgTpl
    })
  },
  upTime(){
    this.selectComponent('#ddate').show();
  },
  ddateEvent(e){
    console.log(e.detail.ddate)
    this.getDetail(true)
  },
  gotoHome(){
    wx.switchTab({
      url: '/pages/reserve/index'
    })
  },
})