<template>
  <view class="fui-wrap">
    <view class="search-content">
      <u-search placeholder="请输入关键字" v-model="keyword"></u-search>
    </view>

    <view class="u-page">
      <view class="u-page-title">
        <view class="line"></view>
        <view class="rectangle"></view>
        <view class="rectangle"></view>
        <view class="title-content">最新资讯</view>
        <view class="rectangle"></view>
        <view class="rectangle"></view>
        <view class="line"></view>
      </view>
      <item-list :ds="indexList" :onItemClick="onContentClick" />
    </view>
  </view>
</template>

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

export default {
  components: {
    ItemList,
  },
  data() {
    return {
      keyword: this.queryParams?.keyword || '',
      indexList: [],
    };
  },
  watch: {
    keyword(val) {
      this.indexList = [];
      this.loadmore();
    },
  },
  onLoad() {
    this.loadmore();
  },
  methods: {
    async loadmore() {
      const res = await fetchContentInfo({
        pageNum: 1,
        pageSize: 99,
        title: this.keyword,
      });
      this.indexList = res.rows.map(item => {
        return {
          id: item.id,
          imgUrl: getImageUrl(item.thumbnail),
          title: item.title,
          date: item.createTime,
        };
      });
    },
    onContentClick(item) {
      uni.navigateTo({
        url: `/pages/detail/index?id=${item.id}`,
      });
    },
  },

};
</script>

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