<template>
  <view class="container browseHistory-container">
    <view class="history-ul" v-if="haveData">
      <view class="history-ltem" v-for="(item, index) in historyList" :key="index" @click="goDetail(item.ArticleId)">
        <view class="item-left">
          <text class="title text_twoLine">{{ item.Title }}</text>
          <text class="text_twoLine desc">{{ item.Body }}</text>
        </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="10" margin-bottom="10" 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 { Mine } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import freeCharge from "@/components/freeCharge";
export default {
  data() {
    return {
      refresh: false, //正在下拉
      status: "loadmore",
      page_no: 1,
      pageSize: 10,
      historyList: [],
      haveData: null,
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
      totalPage: "",
    };
  },
  onLoad() {
    this.gethistoryList();
  },
  components: {
    freeCharge,
  },
  methods: {
    /* 获取列表 */
    gethistoryList() {
      Mine.getHistory({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
      }).then((res) => {
        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.historyList = res.Data.List || [];
            this.haveData = this.historyList.length ? true : false;
            if (this.refresh) {
              uni.stopPullDownRefresh();
              this.refresh = false;
            }
          } else {
            this.historyList = this.historyList.concat(res.Data.List);
          }
        }
      });
    },
    goDetail(id) {
      uni.navigateTo({
        url: "/pageMy/reportDetail/reportDetail?id=" + id,
      });
    },
  },
  /* 触底 */
  onReachBottom: Throttle(function () {
    if (this.status === "nomore") return;
    this.status = "loading";
    this.page_no++;
    this.gethistoryList();
  }),
  /* 下拉刷新 */
  onPullDownRefresh: Throttle(function () {
    this.page_no = 1;
    this.refresh = true;
    this.gethistoryList();
  }),
};
</script>

<style lang="scss" scoped>
.browseHistory-container {
  background-color: #f7f7f7;
  .history-ul {
    padding-top: 4rpx;
    .history-ltem {
      display: flex;
      padding: 30rpx 34rpx;
      background: #fff;
      margin-bottom: 4rpx;
      align-items: center;
      justify-content: space-between;
      .title {
        max-width: 625rpx;
        color: #4a4a4a;
        font-size: 34rpx;
      }
      .desc {
        margin-top: 17rpx;
        width: 625rpx;
        color: #999;
      }
    }
  }
}
</style>
