<template>
  <view class="page">
    <u-tabs
        lineWidth="336rpx"
        :list="tabsList"
        itemStyle="height:80rpx;padding-bottom:10rpx;background-color: #fff;"
        @click="tabsClick"
    ></u-tabs>
    <view class="message_list">
      <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
        <u-list-item v-for="(item, index) in list" :key="index">
          <view class="message_item arrow" @click="fnNavigator(item)">
            <view class="message_flex">
              <view>
                <view class="fontstyle u-line-1">{{ item.SYNOPSIS }}</view>
                <view class="message_time">提醒时间：{{ item.CREATTIME }}</view>
              </view>
              <view class="font0">{{ item.noticeUserType == '0' ? '待阅' : '已阅' }}</view>
            </view>
          </view>
        </u-list-item>
      </u-list>
      <empty v-else></empty>
    </view>
  </view>
</template>

<script>
import {getAnnouncementNoticeList, getPlatformReminderList} from "../../../api";

export default {
  data() {
    return {
      tabsList: [
        {name: '公告通知', id: '1'},
        {name: '平台提醒', id: '2'}
      ],
      TYPE: '1',
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onShow(event) {
    this.resetList()
  },
  methods: {
    async fnGetAnnouncementNoticeList() {
      let resData = await getAnnouncementNoticeList({
        loginUserId: this.userInfo.USER_ID,
        showCount: this.pageSize,
        currentPage: this.currentPage,
      })
      this.list = [...this.list, ...resData.varList]
    },
    async fnGetPlatformReminderList() {
      let resData = await getPlatformReminderList({
        loginUserId: this.userInfo.USER_ID,
        showCount: this.pageSize,
        currentPage: this.currentPage,
      })
      this.list = [...this.list, ...resData.varList]
    },
    resetList() {
      this.pageSize = 10
      this.currentPage = 1
      this.list = []
      this.getData();
    },
    getData() {
      if (this.TYPE === '1') this.fnGetAnnouncementNoticeList()
      if (this.TYPE === '2') this.fnGetPlatformReminderList()
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
    tabsClick(e) {
      this.TYPE = e.id
      this.resetList()
    },
    fnNavigator(item) {
      uni.$u.route({
        url: 'pages/information/index/detail',
        params: {
          ID: this.TYPE === '1' ? item.NOTICEREGULATORY_ID : item.NOTICE_ID,
          TYPE: this.TYPE
        }
      })
    }
  }
}
</script>

<style scoped>
.page {
  background-color: #f7f9ff;
  height: 100vh;
}
</style>
