<template>
  <auth-wrap class="usr-collect-info-container" ref="authWrap">
    <template slot="content">
      <view class="search-content">
        <u-search placeholder="请输入关键字" v-model="keyword" @custom="onSearch" @search="onSearch"></u-search>
      </view>
      <view class="u-page" v-if="indexList&&indexList.length>0">
        <item-list :ds="indexList" :onItemClick="onContentClick" />
      </view>
      <u-empty
          v-else
          mode="data"
          text="还没有收藏，赶紧去收藏吧！"
      >
      </u-empty>
    </template>
  </auth-wrap>
</template>

<script>
import { fetchUsrContentInfo } from '@/common/api';
import AuthWrap from '@/components/AuthComp/index.vue';
import ItemList from '@/components/ItemList/index.vue';
import { getImageUrl } from '@/util';

export default {
  components: {
    AuthWrap,
    ItemList,
  },
  data() {
    return {
      keyword: '',
      indexList: [],
    };
  },
  onLoad() {
    debugger
    this.$refs.authWrap.reloadPage();
    this.loadmore();
  },
  methods: {
    onContentClick(item) {
      uni.navigateTo({
        url: `/pasb/pages/detail/index?id=${item.id}`,
      });
    },
    async loadmore(keyword = '') {
      const res = await fetchUsrContentInfo({
        pageNum: 1,
        pageSize: 999,
        contentType: 3,
        title: keyword,
      });
      this.indexList = res.rows.map(item => {
        return {
          id: item.id,
          imgUrl: getImageUrl(item.thumbnail),
          title: item.title,
          date: item.updateTime,
        };
      });
    },
    onSearch(val) {
      this.loadmore(val);
    },
  },
  onShareAppMessage() {
    return {
      title: 'First UI组件库',
    };
  },
};
</script>

<style lang="scss" src="./index.scss" />
