import {
  getBannerList
} from '~/api/global'
import {
  createStoreBindings
} from 'mobx-miniprogram-bindings'
import {
  store
} from '~/store/index'
Page({
  data: {
    activityList: true,
    bannerList: []
  },
  onShow() {
    if (typeof this.getTabBar === 'function') {
      this.getTabBar().setData({
        selected: 1
      })
      this.storeBindings = createStoreBindings(this, {
        store,
        fields: {
          userInfo: 'userInfo'
        },
      })
      this.storeBindings.updateStoreBindings()
      this.setData({
        activityList: true
      })
      this.getBannerList()
    }
  },
  onHide() {
    this.setData({
      activityList: false
    })
  },
  async getBannerList() {
    let bannerList = await getBannerList({
      grade: this.data.userInfo.grade,
    })
    this.setData({
      bannerList,
    })
  },
  resetData() {
    this.selectComponent('#activityList').getActivities()
    this.getBannerList()
  },
  onUnload() {
    this.storeBindings.destroyStoreBindings()
  },
})