<template>
  <view class="file-info-container">
    <view class="u-page">
      <u-list
          @scrolltolower="scrolltolower"
      >
        <u-list-item
            v-for="(item, index) in indexList"
            :key="index"
        >
          <view class="file-info-item">
            <view class="file-info-item-img">
              <image :src="getImageUrl(ICON_CFG.file_icon)" mode="aspectFill" />
            </view>
            <view class="file-info-item-content">
              <view class="file-info-item-title">{{ item.title }}</view>
              <view class="file-info-item-date">{{ item.date }}</view>
            </view>
          </view>
        </u-list-item>
      </u-list>
      <u-loadmore :status="loadStatus" />
    </view>
  </view>
</template>

<script>

import { fetchFileList } from '@/common/api';
import { ICON_CFG } from '@/common/EnumConst';
import { getImageUrl } from '@/util';

let page = 1;
export default {
  name: 'content',
  props: {},
  data() {
    return {
      ICON_CFG,
      indexList: [],
      loadStatus: 'loadmore', // loadmore,loading,nomore
    };
  },
  created() {
  },
  onLoad() {
    this.loadmore();
  },
  methods: {
    getImageUrl,
    scrolltolower() {
      this.loadmore();
    },
    loadmore() {
      this.loadStatus = 'loading';
      fetchFileList({
        pageNum: page,
        pageSize: 10,
        fileType: 1,
      }).then(res => {
        page += 1;
        if (res.rows.length > 0) {
          this.indexList = this.indexList.concat(res.rows.map(item => {
            return {
              id: item.id,
              title: item.fileName,
              date: item.createTime,
            };
          }));
        }
        if (res.rows.length < 10) {
          this.loadStatus = 'nomore';
        }
      });
    },
  },
};
</script>
<style lang="scss" src="./index.scss" />;
