<template>
  <div class="xl:w-screen-xl m-auto py-4 px-4 lg:px-0">
    <div class="text-center flex justify-between items-center z-0 relative my-5">
      <el-space class="text-3xl font-bold text-green-600 flex items-center"><el-icon><Tickets /></el-icon>百农新闻</el-space>
      <nuxt-link to="/article/4151.html">
        <span class="text-lg font-bold tracking-tight text-gray-800 hover:text-red-500 dark:text-white">{{ '进入新闻中心' }}</span>
      </nuxt-link>
    </div>
    <el-card shadow="hover">
      <el-row :gutter="24">
        <el-col :lg="10" :xs="24">
          <HotNewsCarousel v-if="imgList.length > 0" :data="imgList" />
        </el-col>
        <el-col :lg="14" :xs="24" class="w-full h-auto">
          <template v-for="(item, index) in list" :key="index">
            <nuxt-link :to="`/detail/${item.articleId}.html`" class="item">
              <div class="text-lg my-3 flex justify-between">
                <span class="title text-gray-800 hover:text-green-700 text-sm lg:text-lg">{{ item.title }}</span>
                <span class="text-gray-400 text-sm text-right w-[100px]">{{
                  dayjs(item.createTime).format('YYYY.MM.DD')
                }}</span>
              </div>
            </nuxt-link>
          </template>
        </el-col>
      </el-row>
    </el-card>
  </div>
  <div v-if="list.length == 0" class="px-1 text-center text-gray-500 min-h-xs">没有更多了</div>
</template>

<script lang="ts" setup>
  import { navigateTo } from '#imports';
  import {
    ArrowRight,
    Tickets
  } from '@element-plus/icons-vue'
  import dayjs from 'dayjs';
  import type { CmsArticle } from '~/api/cms/cmsArticle/model';
  import { pageCmsArticle } from '~/api/cms/cmsArticle';
  import HotNewsCarousel from "~/components/Index/HotNewsCarousel.vue";

  const list = ref<CmsArticle[]>([]);
  const imgList = ref<CmsArticle[]>([]);

  // 请求数据
  const reload = async () => {
    pageCmsArticle({
      limit: 8,
      recommend: 1,
      parentId: 4131
    }).then(res => {
      list.value = res?.list || [];
    });

    pageCmsArticle({
      recommend: 1,
      limit: 5,
      lang: getLang()
    }).then(res => {
      imgList.value = res?.list || [];
    })
  };
  onMounted(() => {
    reload();
  });
</script>
