<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 { CONTENT_TYPE } from '@/common/EnumConst';
import ItemList from '@/components/ItemList/index.vue';
import { getImageUrl } from '@/util';

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

};
</script>

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