<template>
    <div id="category">
      <!--头部-->
      <!-- <Header/> -->
      <div class="header-title">
        <span class="header-title-return-back" @click="returnClick"><van-icon name="arrow-left" /></span>
        <span class="header-title-name-bold">年报信息</span>
      </div>
  
      <div class="manage-body">
        <div class="hg-4-rem">
            <div class="ft-left wt-15-per hg-100-per"><div class="mg-lt-5 hg-25-rem wt-2-rem firm-icon-body mg-tp-15"><van-icon class="firm-icon" color="#fff" size="1.5rem" name="hotel-o" /></div></div>
            <div class="ft-right wt-84-per" style="margin-top: 15px"><span class="ft-left fs-16 fw-bold">{{ companyName }}</span></div>
        </div>
      </div>
      <div>
        <van-cell v-for="(item, index) in annualList" :key="index" @click="jumpDetail(item)" class="fw-bold" :title="item.year" :label="'发布日期：'+item.publishDate" />
      </div>
    </div>

  </template>

  <script>
  import { Button, Col, Row, Icon, Field } from 'vant';

  // 3. 引入接口
  import {postQueryAnnualInfo} from "@/service/api/customerDashboard";


  export default {
    name: "AnnualReportInfo",
    data() {
      return {
        text: '',
        annualList: [],
        companyName: '',
        currentPage: 1,
        loading: false,
        isEndLoading: false,
      }
    },
    components: {
      VanButton: Button,
      VanRow: Row,
      VanCol: Col,
      VanIcon: Icon,
      VanField: Field,
    },
    created() {
      this.companyName = sessionStorage.getItem('companyName')
      this.postAnnualInfo();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取股东信息
      async postAnnualInfo(){
        let result = await postQueryAnnualInfo({companyId: sessionStorage.getItem('companyId'), pageNum: this.currentPage, pageSize: 10});
        // this.annualList = result.records;
        if (this.loading) {
          this.annualList = this.annualList.concat(result.records);
        } else {
          this.annualList = result.records;
        }
        if (this.annualList.length < result.total) {
          this.isEndLoading = false;
        } else {
          this.isEndLoading = true;
        }
        this.loading = false;
      },

      // 滚动到页面底部时，请求内容
      scrollBottom() {
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop  //页面滚动的高度
        let clientHeight = document.documentElement.clientHeight  //可视区域高度
        let scrollHeight = document.documentElement.scrollHeight  //可滚动内容的高度
        let bottomOfWindow = scrollTop + clientHeight + 1000 >= scrollHeight    //是否滚动到底部
        //loading 和 this.tableData.length和this.total是自己的判断条件
        if (scrollTop !== 0 && bottomOfWindow && !this.loading) {
          this.loading = true;
          this.currentPage += 1;
          this.postAnnualInfo();
        }
      },

      returnClick() {
        this.$router.go(-1)
      },

      jumpDetail(item) {
        this.$router.push({path: 'AnnualReportInfoDetail', query: {id: item.id}})
      },

    },
  }
  </script>
  
  <style lang="less" scoped>
  
  .header-title {
    height: 46px;
    width: 100%;
    background-color: #fff;
    text-align: center;
  }
  .header-title-name {
    font-weight: bold;
    line-height: 46px;
    align-items: center;
    justify-content: center;
    display: inline-flex;
  }
  .header-title-return {
    position: absolute;
    top: 13px;
    left: 20px;
    font-size: 15px;
  }
  .manage-body {
    margin-top: 10px;
    background-color: #fff;
    padding: 0px 10px 0px 10px;
  }
  /deep/ .van-nav-bar__text {
    color: gray !important;
    font-weight: bold;
  }
  .icon-mg {
    margin-left: 3px;
  }
  .firm-icon-body {
    background-color: #2372EB;
    border-radius: 5px;
}
.firm-icon {
    line-height: 2.5rem;
    margin-left: 0.5rem;
}
  </style>../../service/api/index