<template>
  <view class="container container-secret">
    <view class="collect-ul" v-if="haveData">
      <view class="collect-ltem" v-for="(item, index) in collectList" :key="index" @click="goDetail(item, index)">
        <view class="item-left">
          <text class="title text_twoLine"
            >{{ item.Title }}
            <text class="reg-text" v-if="item.IsRed"></text>
          </text>
          <view class="abstract">{{ item.Abstract }}</view>
          <view class="desc">
            <text class="publishDate">{{ item.PublishDate }}</text>
          </view>
        </view>
        <u-icon name="arrow-right" color="#BDBDBD" size="34"></u-icon>
      </view>
      <u-loadmore :status="status" icon-type="flower" :load-text="loadText" margin-top="20" v-if="totalPage > 1" />
    </view>
    <view class="nodata" v-else>
      <image src="@/static/img/nodata.png" mode="" class="nodata_ico"></image>
      <text>暂时没有报告的内容</text>
    </view>
   <freeCharge class="free-charge" :isShowFreeBtn="isShowFree"/>
  </view>
</template>

<script>
import { Reports } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import freeCharge  from '@/components/freeCharge'
let app = getApp({allowDefault: true});
export default {
  data() {
    return {
      isType: "",
      refresh: false, //正在下拉
      page_no: 1,
      pageSize: 10,
      collectList: [],
      haveData: true,
      totalPage: "",
      status: "loadmore",
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
    };
  },
  components: {
    freeCharge
  },
  methods: {
    async getList() {
      const res = await Reports.reportListByType({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
        ReportType: this.isType,
      });
      if (res.Ret == 200) {
        this.status = this.page_no < res.Data.Paging.Pages ? "loadmore" : "nomore";
        this.totalPage = res.Data.Paging.Pages; //总页数
        if (this.page_no === 1) {
          this.collectList = res.Data.List || [];
          this.haveData = this.collectList.length ? true : false;
          if (this.refresh) {
            uni.stopPullDownRefresh();
            this.refresh = false;
          }
        } else {
          this.collectList = this.collectList.concat(res.Data.List);
        }
      }
    },
    goDetail(item, index) {
      /* 无需授权且已绑定 检验是或否有权限 */
      this.collectList[index].IsRed = false;
      this.$store.dispatch("checkHandle","/reportPages/reportSecretDetail/reportSecretDetail?type=" + this.isType + "&id=" + item.ArticleId)
    },
  },
  onLoad(option) {
        this.isType = option.type;
        this.isType == 1 ? uni.hideShareMenu() : "";
        uni.setNavigationBarTitle({
          title: this.isType == 1 ? "报告精选" : this.isType == 2 ? "本周研究汇总" : "上周纪要汇总",
        });

        this.getList();
  },
  /* 触底 */
  onReachBottom: Throttle(function () {
    if (this.status === "nomore") return;
    this.status = "loading";
    this.page_no++;
    this.getList();
  }),
  /* 下拉刷新 */
  onPullDownRefresh: Throttle(function () {
    this.page_no = 1;
    this.refresh = true;
    this.getList();
  }),
  onShareAppMessage(res) {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费月卡！" :  this.isType == 2 ? "本周研究汇总" : "上周纪要汇总",
      path: "/reportPages/secretDetails/secretDetails?type=" + this.isType,
    };
  },
};
</script>

<style lang="scss" scoped>
@import "../index.scss";
.container-secret {
  background-color: #f6f6f6;
  .title {
    color: #333333 !important;
    font-size: 30rpx !important;
    font-weight: 400 !important;
  }
  .abstract {
    margin: 20rpx 0 0 30rpx;
    color: #666666;
    font-size: 28rpx;
    font-weight: 400 !important;
  }
}
</style>
