// pages/ArticleList/ArticleList.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    article_data: [],
    title: "",
    page_id: '',
    aid: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        page_id: options.id
      });
    } else {
      this.setData({
        page_id: ''
      });
      let that = this;
      wx.getStorage({
        key: 'headline',
        success: function (res) {
          // success
          that.setData({
            article_data: res.data
          });
        }
      });

      wx.setNavigationBarTitle({
        title: '头条列表'
      });
    }
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onShareTimeline:function(){},
  toNoticeInfo(e) {
    let item = e.currentTarget.dataset.item;
    console.log(item);
    if (item.has_one_article_pay) {
      if (item.has_one_record) {
        wx.navigateTo({
          url: `/packageA/member/article/articleContent/articleContent?article_id=${item.articleid ? item.articleid : item.id}`
        });
      } else {
        wx.navigateTo({
          url: `/packageD/article/articleList/articleList?article_id=${item.articleid ? item.articleid : item.id}`
        });
      }
    } else {
      wx.navigateTo({
        url: `/packageA/member/article/articleContent/articleContent?article_id=${item.articleid ? item.articleid : item.id}`
      });
    }
  },
  tempInfo() {
    var that = this;
    if (!this.data.page_id) {
      return;
    }
    var urlStr = app.getNetAddresss("home-page.wxapp");
    urlStr += '&page_id=' + this.data.page_id;
    app._getNetWork({
      showToastIn: false,
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let obj = res.data.item.data;
          obj.forEach(e => {
            if (e.temp == "headline" && e.id == that.data.aid) {
              console.log(e, that.data.aid);

              that.setData({
                article_data: e.data,
                title: e.params.toptitle
              });
            }
          });
          if (that.data.title) {
            wx.setNavigationBarTitle({
              title: that.data.title
            });
          }
        }
      },
      fail: function (res) {

      }
    });
  }
});
