// import { splitEvery, concat } from 'ramda'
Component({
  props: {
    className: '',
    pageSize: 9999,
    height: '100vh',
    emptyTitle: '暂无数据',
    emptyMessage: '前不见古人、后不见来者',
    onRef: () => null,
    onService: () => Promise.reject(new Error('请传入service'))
  },
  data: {
    list: [],
    loadContent: ['正在加载', '没有更多记录'],
    pageNum: 0
  },
  methods: {
    saveRef(ref) {
      this.scrollRef = ref;
    },

    // 底部触底事件
    // onScrollToLower () {
    //   console.log('66666666');
    //   const { list, pageNum } = this.data;
    //   const that = this;
    //   if (pageNum < list.length && list.length > 1) {
    //     this.data.list = concat(list, list[pageNum + 1])
    //     that.setData({
    //       pageNum: pageNum + 1,
    //     })
    //   } else {
    //     console.log('1111');
    //   }
    // },

    /* 分页逻辑 */
    async onFetchData(page, limit) {
      const {
        list: _list
      } = this.data;
      const {
        onService
      } = this.props;
      const {
        list = [],
        pagination = {}
      } = await onService({
        pageIndex: page,
        pageSize: limit
      });
      const newList = page === 1 ? list : [..._list, ...list];
      // const theList = splitEvery(10, newList)
      this.setData({
        list: newList,
        // pageNum: 0
      });
      const {
        total
      } = pagination;
      return {
        total,
        list
      };
    },

    /* 刷新 */
    async refresh() {
      this.scrollRef.refresh();
    }

  }
});