const app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight:wx.getSystemInfoSync().windowHeight,
    pageSize:10
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getNewsList(10);
  },
  setKeyword(e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  searchList(){
    this.getNewsList(40);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  getNewsList(pageSize) {
    var that = this;
    app.requestP({
      url: '/query/news',
      method: 'post',
      needToken: false,
      data: {
        keyword: that.data.keyword || '',
        pageNum: '1',
        pageSize,
      }
    }).then(res => {
      console.log(res.data.data);
      that.setData({
        newsList: res.data.data.map(item => {
          return {
            ...item,
            createTime: item.createTime.substring(item.createTime.length - 8)
          }
        })
      })
      if(pageSize>10){
        that.setData({
          scrollHeight:scrollHeight+900
        })
      }
    }).catch(err => {
      app.showToptip(that, 'error', err.data.msg)
    })
  },
  goNewsInfo(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/newsInfo/newsInfo?id=' + id,
    })
  },
  bindscrolltolower(){
    var pageSize = this.data.pageSize;
    this.getNewsList(pageSize+10)
    this.setData({
      pageSize:pageSize+10
    })
  }
})