<template>
  <view class="container container-secret">
    <view class="tabs-content">
      <view :class="['item-li', isType == item.value && 'item-active']" v-for="item in tabsList" :key="item.value" @click="tabsHandler(item)">
        {{ item.name }}
        <image v-if="isType == item.value" class="border_act" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/border_act.png"></image>
      </view>
    </view>
    <view class="collect-ul" v-if="haveData">
      <view class="collect-ltem" v-for="(item, index) in collectList" :key="index" @click="goDetail(item)">
        <text class="title text_twoLine"
          >{{ item.Title }}
          <text class="reg-text" v-if="item.IsRed"></text>
        </text>
        <view class="content">
          <view class="item-left">
            <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>
      </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="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.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: 2,
      refresh: false, //正在下拉
      page_no: 1,
      pageSize: 10,
      collectList: [],
      haveData: true,
      totalPage: "",
      status: "loadmore",
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
      tabsList: [
        { name: "本周研究汇总", value: 2 },
        { name: "上周纪要汇总", value: 3 },
        // { name: "报告精选", value: 1 },
      ],
    };
  },
  components: {
    freeCharge,
  },
  computed: {},
  methods: {
    //点击头部的tabs
    tabsHandler(item) {
      this.isType = item.value;
      this.page_no = 1;
      this.getList();
    },
    //获取数据
    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) {
      /* 无需授权且已绑定 检验是或否有权限 */
      item.IsRed = false;
      this.$store.dispatch("checkHandle", "/reportPages/reportSecretDetail/reportSecretDetail?type=" + this.isType + "&id=" + item.ArticleId);
    },
  },
  onLoad(option) {
    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: function (res) {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容,上传名片享查研观向免费月卡!" : "周度汇总",
      path: "/reportPages/secretDetails/secretDetails?type=" + this.isType,
      success: (res) => {},
      fail: (err) => {},
    };
  },
};
</script>

<style lang="scss" scoped>
.container-secret {
  background: #f7f7f7;
  padding-bottom: 30rpx;
  .tabs-content {
    position: sticky;
    top: -1rpx;
    left: 0;
    background-color: #fff;
    height: 81rpx;
    display: flex;
    font-size: 30rpx;
    font-weight: 400;
    padding: 21rpx 35rpx 0;
    color: #999999;
    z-index: 99;
    .item-li {
      position: relative;
      margin-right: 60rpx;
      .border_act {
        width: 60%;
        height: 6rpx;
        position: absolute;
        bottom: 0rpx;
        left: 50%;
        transform: translateX(-50%);
      }
    }
    .item-active {
      color: #333333;
      font-weight: 500;
    }
  }
  .collect-ul {
    padding-top: 4rpx;
    .collect-ltem {
      padding: 30rpx 20rpx 30rpx 34rpx;
      background: #fff;
      margin-bottom: 4rpx;
      width: 682rpx;
      margin: 20rpx auto 0;
      .title {
        position: relative;
        color: #4a4a4a;
        font-size: 34rpx;
        padding-left: 28rpx;

        .reg-text {
          position: absolute;
          top: 15rpx;
          left: 0rpx;
          width: 14rpx;
          height: 14rpx;
          background-color: #ff0000;
          border-radius: 50%;
          z-index: 9;
        }
      }

      .content {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .desc {
        display: flex;
        align-items: center;
        margin-top: 17rpx;
        padding-left: 28rpx;
        color: #999;
      }

      .publishDate {
        margin-right: 30rpx;
        white-space: nowrap;
      }

      .text-name {
        color: #2c83ff;
        font-size: 26rpx;
      }
    }
  }
  .title {
    color: #333333;
    font-size: 30rpx;
    font-weight: 400;
    width: 100%;
    padding-bottom: 15rpx;
    border-bottom: 1px dashed #ccc;
  }
  .abstract {
    margin: 20rpx 0 0 30rpx;
    color: #666666;
    font-size: 28rpx;
    font-weight: 400;
    padding-right: 10rpx;
  }
}
</style>