let app = getApp();
const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
var WxParse = require('../../wxParse/wxParse.js');
const config = require("../../config/config");
const Http = require("../../utils/HttpBasics");
const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
let configUrls = extConfig.attr.configUrl;
console.log(configUrls)

Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigationBarHeight,
    url: config.url,
    token: app.globalData.token,
    id: '',
    date: new Date()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.globalData.token) {
      const that = this;
      that.setData({
        url: config.url,
        id: options.id,
        token: app.globalData.token
      })
      if (options && options.id) {
        wx.request({
          url: configUrls + config.api.printHtmlById,
          data: {
            token: app.globalData.token,
            id: options.id,
            date: new Date()
          },
          header: {
            'content-type': 'application/html'
          },
          success: function (res) {
            var temp = WxParse.wxParse('article', 'html', res.data, that, 5);
          }
        })
      }
    } else {
      app.tokenCallback = token => {
        const that = this;
        that.setData({
          url: config.url,
          id: options.id,
          token: app.globalData.token
        })
        if (options && options.id) {
          wx.request({
            url: configUrls + config.api.printHtmlById,
            data: {
              token: app.globalData.token,
              id: options.id,
              date: new Date()
            },
            header: {
              'content-type': 'application/html'
            },
            success: function (res) {
              var temp = WxParse.wxParse('article', 'html', res.data, that, 5);
            }
          })
        }
      }
    }

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      date: new Date()
    })
  },
  onShareAppMessage: function (options) {
    var that = this;
    console.log(`/pages/freeBannerDetail/index?id=${that.data.data.id}`)
    var shareObj = {
      title: that.data.title,
      path: `/pages/freeBannerDetail/index?id=${that.data.data.id}`,
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') { }
      },
      fail: function (error) {
        if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
      }
    };


    console.log(shareObj)

    return shareObj;
  },
})