// pages/Information/information_seemore/information_seemore.js
const app = getApp(),
  { hostname, business_id } = app.globalData
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    more:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
   that.seeMore(that);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

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

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

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

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

  /**
    * 用户点击右上角分享
    */
  onShareAppMessage: function (res) {
    var userid = wx.getStorageSync('openId')
    // var userid = 1

    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: app.globalData.share_title,
      path: '/pages/index/index?u_openid=' + userid,
      success: function (res) {
        var pages = getCurrentPages()    //获取加载的页面
        var currentPage = pages[pages.length - 1]    //获取当前页面的对象
        //点击分享传进userid 截取userid 从onload拿到
        var url = currentPage.route + '?u_openid=' + userid;  //当前页面url
        console.log(url, '/pages/index/index?u_openid=' + userid);
      },
      fail: function (res) {
        // 转发失败
      },
    }
  },
  // 获取查看更多列表
  seeMore(that) {
    wx.request({
      url: app.globalData.hostname + 'Zixun/get_list',
      data: { business_id, page: that.data.page},
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'POST',
      dataType: '',
      success: function (res) {
        console.log(res, "查看更多");
        if (res.statusCode == 200) {
          var more = [];
          var moreData = res.data.data;
          // console.log(imgUrlsData);
          if (moreData.length != undefined) {
            for (var i = 0; i < moreData.length; i++) {
              more.push(moreData[i]);
            }
          }
        //   // console.log(imgUrls,11);
          that.setData({
            more: more
          })
        } else {
          that.setData({
            more: []
          })
        }
      },
      fail: function (res) { },
      complete: function (res) {
      }
    })
  },

  // 点击跳转图文详情
  goInformationListDetails(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../information_article/information_article?id=' + e.currentTarget.dataset.id,
    })
  },

})