display.js 4.61 KB
// pages/manager-invitation/review.js
import util from '../../utils/util';
import App from '../../utils/api';
import TP from '../../utils/tpls';
const {regeneratorRuntime} = global
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: 667,
    current: 0,
    tpls: [],
    seller:{
      name:'',
      room:'',
      date:'',
      addr:''
    },
    options:{tplid:1},
    hasOwner:true,//是否为发起人
    animation:'animation',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  openid:'',
  onLoad: async function (options) {
    this.openid=await getApp().openid;
    if(options.fromid==this.openid && options.hasSellerShare==1){//商家分享自己点跳到商家预览页
      wx.redirectTo({
        url:util.http_build_query({rid:options.rid,tplid:options.tplid},'./review')
      })
      return;
    }
    App.Invitation.SetInvitationRel({
      id:options.rid,
      initiator:options.fromid,
      inviting:this.openid,
    })
    let param={
      options:options,
      hasOwner:options.hasSellerShare==1,//是否为发起人
    }
    if(options.rid){
      param.tpls=[TP.tpls(options.tplid)]
    }
    this.setData(param)
    this.initData(options);
  },
  initData(options){
    App.Invitation.Detail({id:options.rid}).then(res=>{
      let hasOwner=false;
      let hasCanSuccess=false;
      if(res.data.customers && res.data.customers.length>0){
        res.data.customers.forEach((u,i)=>{
          if(u.openid==this.openid){
            if(i==0){hasOwner=true;}
            hasCanSuccess=true;
          }
        })
      }
      let obj={
        seller:{
          name:res.data.seller_name,
          room:res.data.room_name,
          date:util.unixtoTime(res.data.arrival_time,this.data.tpls[this.data.current].timeStr),
          addr:res.data.seller_address,
          image:res.data.image_url,
          hasCanSuccess:hasCanSuccess,
          lat:res.data.lat,
          long:res.data.long,
        }
      }
      obj.hasOwner=hasOwner
      this.setData(obj)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  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
    })
  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    this.setData({
      animation:'',
    })
    let path=util.http_build_query({
      ...this.data.options,
      fromid:this.openid,
      hasSellerShare:'',
    },'/pages/manager-invitation/display')
    return {
      title: '你收到一个邀请函,点击查看',
      path: path,
      imageUrl:this.data.tpls[this.data.current].shareImage,
      //imageUrl:util.cgi('App.Reserve.MakePic&rid='+this.data.options.rid),
    }
  },
  setUserInfoSuccess(){
    util.toast('授权成功,可以继续转发','none');
  },
  confirmed(){
    if(!this.data.seller.hasCanSuccess){
      let userInfo=util.cache('userInfo');
      if(userInfo){
        userInfo=JSON.stringify({
          openid: this.openid,
          avatar: userInfo.avatarUrl,
          nickname: userInfo.nickName,
          gender: userInfo.gender
        })
      }
      App.Invitation.SetInvitationConfirm({
        lid:this.data.options.rid,
        openid:this.openid,
        is_agree:1,
        userinfo:userInfo
      }).then(res=>{
        this.setData({
          [`seller.hasCanSuccess`]:true
        })
        util.toast('赴约成功','none')
      })
    }else{
      util.toast('赴约成功','none')
    }
  },
  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.addr,
      success:function (res) {
        console.log(res)
      }
    })
  },
})