<template>
  <div class="xl:w-screen-xl m-auto py-4">
    <div v-if="title" class="text-center flex flex-col items-center z-100 relative">
      <h2 class="text-4xl font-bold tracking-tight text-gray-500 dark:text-white">
        {{ title }}
      </h2>
      <div class="sub-title">
        <p class="text-gray-500 dark:text-gray-400 py-3">
          {{ comments }}
        </p>
      </div>
    </div>
    <el-row :gutter="24" id="container" class="clearfix">
      <el-col v-for="(item,index) in list" :key="index" :span="6" class="left mb-8">
        <el-card shadow="hover" :body-style="{ padding: '0px' }" class=" hover:bg-gray-50 cursor-pointer" @click="navigateTo(`/market/${item.websiteId}.html`)">
          <div class="flex-1 px-4 py-5 sm:p-4 !p-4">
            <div class="text-gray-700 dark:text-white text-base font-semibold  flex gap-1.5">
              <el-avatar
                  :src="item.websiteLogo" shape="square" :size="55" style="background-color: white;"/>
              <div class="flex-1 text-lg cursor-pointer flex flex-col">
                {{ item.websiteName }}
                <div class="flex justify-between items-center">
                  <sapn class="text-xs text-gray-400 font-normal line-clamp-1">{{ item.comments || '暂无描述' }}</sapn>
                  <el-button size="small" round>获取</el-button>
                </div>
              </div>
            </div>
            <div class="item-image pt-3">
              <el-image v-if="item.files" :src="`${JSON.parse(item.files)[0].url}`" class="w-full h-1/2 max-h-[220px]" />
              <el-image v-else class="w-full h-[220px]" />
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
  <el-row :gutter="24" class="flex w-full">
    <el-col v-for="(item,index) in list" :key="index" :span="6" :xs="24" class="mb-6">
      <nuxt-link :to="item.path">
        <el-card shadow="hover" :body-style="{ padding: '0px' }" class="hover:bg-green-50 cursor-pointer h-[200px] flex items-center justify-center">
          <div class="flex-1 px-4 py-5 sm:p-6 !p-4">
            <div class="text-gray-700 dark:text-white text-base font-semibold  flex flex-col gap-1.5">
              <el-space class="flex-1 cursor-pointer flex items-center flex-col">
                <el-image v-if="item.icon" :src="item.icon" class="w-[40px]" />
                <span class="py-3 text-lg">{{ item.title }}</span>
              </el-space>
            </div>
          </div>
        </el-card>
      </nuxt-link>
    </el-col>
  </el-row>
  <div v-if="disabled" class="px-1 text-center text-gray-500 min-h-xs">
    没有更多了
  </div>
</template>

<script setup lang="ts">
import {loginAdminByToken} from "~/utils/common";
import {useServerRequest} from "~/composables/useServerRequest";
import type {ApiResult, PageResult} from "~/api";
import type {Company, CompanyParam} from "~/api/system/company/model";
import {pageCompanyAll} from "~/api/system/company";
import {listCmsNavigation} from "~/api/cms/cmsNavigation";
import type {CmsNavigation} from "~/api/cms/cmsNavigation/model";
import {navigateTo} from "#imports";
import type {CmsWebsite} from "~/api/cms/cmsWebsite/model";
import {listWebsite} from "~/api/system/website";
import {listCmsWebsite, pageCmsWebsiteAll} from "~/api/cms/cmsWebsite";

const props = withDefaults(
    defineProps<{
      param?: CompanyParam;
      disabled?: boolean;
      title?: string;
      comments?: string;
      fit?: any;
    }>(),
    {
      fit: 'cover'
    }
);

const emit = defineEmits<{
  (e: 'done'): void;
}>();

const list = ref<CmsWebsite[]>([]);

// 请求数据
const reload = async () => {
  pageCmsWebsiteAll({
  }).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
