// pages/wv_page/index.js
const { encodeParam, decodeParam, recordAccess } = require('../../utils/util.js');
const { serverName, request } = require('../../utils/services');

const app = getApp();

Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    forwardImg:'https://4dscene.4dage.com/cgaii/images/join/forwardImg.jpg'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = (options.scene && decodeURIComponent(options.scene))|| options.id
    recordAccess({
      id
    })

    if (id){
      this.getExhibitionDetail(id)
    }
  },

  forward: function(url){
    this.setData({
      url: url.detail.data.pop()
    })
  },
  
  getExhibitionDetail: function (sceneId) {
    let exhibitionId = sceneId
    request["getExhibitionDetail"]({
      exhibitionId: exhibitionId
    }, "", res => {
      let { data: exhibitionDetail } = res.data;
      let { product } = exhibitionDetail
      this.setData({
        url: product.showLink,
        imageUrl: exhibitionDetail.imageUrl,
        relayUrl: exhibitionDetail.relayUrl,
        sceneId: exhibitionDetail.id
      })
      if (exhibitionDetail.name) {
        wx.setNavigationBarTitle({
          title: exhibitionDetail.name
        })
      }
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let {sceneId, imageUrl, relayUrl, forwardImg} = this.data;
    console.log(imageUrl || forwardImg)
    return {
      path: `/pages/wv_page/index?&id=${sceneId}`,
      imageUrl: relayUrl || imageUrl || forwardImg
    }
  }
})
