findCar.js 4.13 KB
const WXRequest = require('../../utils/wxrequest.js');
const moment = require('./../../utils/moment.min.js'); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    carInfo: null,
    loginUserId: '',
    ifUpdate: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('test:'+options.test)
   /* wx.showShareMenu({
        withShareTicket: true
    });*/

    const sessionid = /^JSESSIONID=(.+);Path=\/otmini$/g.exec(wx.getStorageSync('sessionid'))[1];
    this.setData({
      url: encodeURI(`${WXRequest.domain}h5/dist/index.html?sessionid=${sessionid}`),
      loginUserId: wx.getStorageSync('loginUserId'),
      ifUpdate: true
    });
    console.log(encodeURI(`${WXRequest.domain}h5/dist/index.html?sessionid=${sessionid}`))
  },
  onShow(options){
    const carShareInfo = wx.getStorageSync('carShareInfo');
    const carInfo = wx.getStorageSync('carInfo'); 
    const sessionid = /^JSESSIONID=(.+);Path=\/otmini$/g.exec(wx.getStorageSync('sessionid'))[1];
    
    /* this.setData({
      ifUpdate: false
    }) */
    if(wx.getStorageSync('initFindCar')){
       
      let _url = `${WXRequest.domain}h5/dist/index.html?sessionid=${sessionid}&sns=${carInfo.sns}&standno=${carInfo.standno}&name=${carInfo.name}&vehicleid=${carInfo.vehicleid}`;
      if(carInfo.loginUserId){
        _url += `&loginUserId=${carInfo.loginUserId}`;
        this.setData({
          loginUserId: carInfo.loginUserId
        });
      }
      console.log(sessionid)
      console.log(_url);
      this.setData({
        url: encodeURI(_url),
        ifUpdate: true
      });
      wx.setStorageSync('initFindCar', false);
      this.setData({
        carInfo: carInfo
      });
      console.log(encodeURI(_url))
    }else if(carShareInfo){
      
      const _url = `${WXRequest.domain}h5/dist/index.html?sessionid=${sessionid}&sns=${carShareInfo.sns}&standno=${carShareInfo.standno}&name=${carShareInfo.name}&vehicleid=${carShareInfo.vehicleid}&loginUserId=${this.data.loginUserId}`;
      this.setData({
        url: encodeURI(_url),
        ifUpdate: true
      });
      this.setData({
        carShareInfo: null,
        carInfo: carShareInfo
      });
      console.log(encodeURI(_url))
    }
  },
  receiveMsg(){
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },


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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(options) {
    var that = this;
    
    var return_url = options.webViewUrl;
    /*await new Promise((resolve, reject)=>{
      setTimeout(()=>{
        resolve()
      },1000)
    })*/
    const startTime = moment().format('YYYY-MM-DD HH:mm:ss');

    WXRequest.get('vehicleshare/savevehicleshare', {
      loginUserId: that.data.loginUserId,
      vehicleId: that.data.carInfo.vehicleid,
      source: 0,
      status: 0,
      startTime: startTime,
      endTime: moment(startTime).add(3, 'days').format('YYYY-MM-DD HH:mm:ss')
    }).then((res)=>{
      
    });
    var opts = {
      title: that.data.title,
      path: '/pages/loading/loading',
      success: function (res) {
        console.log(arguments)
        /*var shareTickets = res.shareTickets;
        if (shareTickets.length == 0) {
            return false;
        }
        wx.getShareInfo({
           shareTicket: shareTickets[0],
           success: function(res){
               var encryptedData = res.encryptedData;
               var iv = res.iv;
           }
        })*/
        
      },
      fail: function (res) {
        // 转发失败
      }
    }
    
    if(that.data.carInfo){
      opts.path = opts.path + '?carShareInfo='+encodeURIComponent(JSON.stringify(that.data.carInfo))+'&loginUserId='+that.data.loginUserId;
    }
    return opts;
  }
})