var app = getApp();
var that;
Page({
  data: {
    list:[],
    page:1,
    objectArray: [
      {
        id: 0,
        name: '全部',
      },
      {
        id: 1,
        name: '版本更新',
      },
      {
        id: 2,
        name: '系统公告',
      },
    ],
    arrIndex: 0,
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "系统公告" });
    this.getList();
  },
  bindObjPickerChange(e) {
    this.setData({
      arrIndex: e.detail.value,
      page:1,
      isData: false
    });
    that.getList();
  },
    //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getList(true);
    }
  },
  getList(is){
    app.$get("api/announcement/list",{page:this.data.page,page_size:20,type:that.data.arrIndex}).then((res) => {
      var data=res.data.data.list;
      if (is) {
        if (data.length == 0) {
          this.setData({
            isData: true
          })
          return;
        }
        var list = that.data.list;
        this.setData({
          list: list.concat(data)
        })
      } else {
        this.setData({ list: [] });
        this.setData({
          list: data,
          isData: false
        })
      }
    })
  },  
  //跳转
  openDetail(e) {
    var id = e.target.dataset.id;
    dd.navigateTo({
      url: '../upgradeDetail/upgradeDetail?id='+id
    })
  },

});
