// pages/heritage/heritage.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    libraryUrl: app.libraryUrl,
    libraryList: [],
    currentPage: 1,
    rows: 20
  },
  goDetail: function (event) {
    wx.navigateTo({
      url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId,
    })
  },
  goLive: function() {
    wx.navigateTo({
      url: '../broadcast/broadcast',
    })
  },
  goFriendCircle: function() {
    wx.navigateTo({
      url: '../friendCircle/friendCircle',
    })
  },
  goCultureMap: function () {
    wx.navigateTo({
      url: '../cultureMap/cultureMap',
    })
  },
  doGetLibraryList: function(page) {
    var self = this;
    app.dialog.loading('正在加载');
    app.restAjax.get(app.restAjax.path('{libraryUrl}/app/intangiblelibrary/listpageintangiblelibraryrelease', [self.data.libraryUrl]), {
      page: page,
      rows: self.data.rows
    }, null, function(code, data) {
      if(data.rows.length == 0) {
        app.dialog.msg('暂无数据');
        return;
      }
      for(var i = 0, item; item = data.rows[i++];) {
        item.libraryApplyTime = item.libraryApplyTime.substring(0, item.libraryApplyTime.length - 10);
      }
      var libraryArray;
      if(page <= 1) {
        libraryArray = data.rows;
      } else {
        libraryArray = self.data.news.newsList;
        libraryArray = libraryArray.concat(data.rows);
      }
      self.setData({
        currentPage: page,
        libraryList: libraryArray
      })
    }, function(code, data) {
      app.dialog.msg(data.msg);
    }, function() {
      wx.stopPullDownRefresh();
      wx.hideLoading();
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.doGetLibraryList(1);
  },

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

  },

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

  },

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

  },

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

  },

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.doGetLibraryList(this.data.currentPage + 1);
  },

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

  }
})