<template>
  <view class="width-100 height-100 view-page">
    <u-swiper height="185" :list="bannerList" @click="clickInfo" keyName="cover"></u-swiper>
    <u-list @scrolltolower="scrolltolower" height="calc(100% - 47px)" lowerThreshold="10">
      <view class="info-list">
        <view class="dis-flex flex-x-between info-item" v-for="(item, index) in list" :key="index"
          @click="toDetail(item.id)">
          <view class="info-pic">
            <u-image width="175rpx" height="175rpx" mode="aspectFill" :src="item.cover"></u-image>
          </view>
          <view class="info-view">
            <view class="info-title">
              {{item.subTitle}}
            </view>
            <view class="dis-flex info-bottom">
              <view style="margin-right: 20rpx;">{{item.createTime?item.createTime.substring(0,10):''}}</view>
              <u-icon name="thumb-up" color="#7f7f7f" size="18"></u-icon>
              <view style="margin-right: 20rpx;">{{item.likeNum || 0}}点赞</view>
              <u-icon name="eye" color="#7f7f7f" size="18"></u-icon>
              <view>{{item.views || 0}}阅读量</view>
            </view>
          </view>
        </view>
      </view>
      <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
        :nomore-text="page.nomoreText" />
    </u-list>
  </view>
</template>

<script>
  import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
  export default {
    mixins: [themeMixins],
    data() {
      return {
        bannerList: [],
        page: {
          current: 1,
          size: 10,
          total: 0,
          // loadmore loading nomore
          status: 'loadmore',
          loadingText: '正在加载中',
          loadmoreText: '上拉加载更多',
          nomoreText: '没有更多了'
        },
        keyword: '',
        list: []
      }
    },
    onShow() {
      this.getProfessionalStyleList();
      this.getBanners()
    },
    methods: {
      clickInfo(index) {
        if (index < 0) {
          return;
        }
        uni.navigateTo({
          url: "/pages/yuecai/information/detail/index?id=" + this.bannerList[index].id,
        })
      },
      getBanners() {
        this.$u.api.getInformationList(0, 6, {}).then(res => {
          this.bannerList = res.data.records || []
        })
      },
      scrolltolower() {
        this.loadmore()
      },
      loadmore() {
        this.page.current++;
        this.getProfessionalStyleList();
      },
      doRefresh() {
        this.page.current = 1;
        this.page.status = 'loadmore'
        this.list = [];
        this.getProfessionalStyleList();
      },
      getProfessionalStyleList() {
        if (this.page.status == 'loading' || this.page.status == 'nomore') {
          // 防止重复下拉
          return;
        }
        this.page.status = 'loading';
        //
        this.$u.api.getProfessionalStyleList(this.page.current, this.page.size, {
          name: this.keyword || ''
        }).then(res => {
          if (res.data.records && res.data.records.length > 0) {
            this.list.push(...res.data.records)
          }
          this.page.total = res.data.total || 0;
          if (this.page.size * this.page.current >= res.data.total) {
            this.page.status = 'nomore'
          } else {
            this.page.status = 'loadmore'
          }
        })
      },
      toDetail(id) {
        uni.navigateTo({
          url: "/pages/yuecai/professional_style/detail/index?id=" + id,
        })
      }
    },
  }
</script>

<style scoped lang="scss">
  .info-list {
    height: calc(100% - 95px);
    overflow: auto;
    background-color: #f4f6f8;

    .info-item {
      padding: 20rpx;
      border-bottom: 2rpx solid white;

      .info-pic {
        width: 175rpx;
        height: 175rpx;
        background: bisque;
      }

      .info-view {
        width: calc(100% - 205rpx);

        .info-title {
          height: 75px;
          word-break: break-all;
          color: #65371b;
          font-size: 24rpx;
          font-weight: 300;
          line-height: 47rpx;
          word-spacing: 2rpx;
          overflow: hidden;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 3;
          line-clamp: 3;
          -webkit-box-orient: vertical;
        }

        .info-bottom {
          color: #7f7f7f;
          font-size: 24rpx;
          margin-top: 10rpx;
        }
      }
    }
  }
</style>