<template>
    <div class="app-container home">
        <banner-bar v-if="bannerList&&bannerList.length" class="banner-bar" :options="bannerList" @close="closeBanner" :show="showBanner" />
        <div class="page-content">
            <div class="title-bar">
                <span class="title">{{ t('tools.pageTitle') }}</span>
            </div>
            <el-row v-if="!loading" >
                <el-col :span="24" v-for="(item,i) in dataList" :key="i" >
                    <div class="news-item" >
                        <el-image class="news-img" :src="item.img_url" fit="cover" />
                        <div class="news-info">
                            <div class="news-title">{{ item.title }}</div>
                            <div class="news-time">{{ item.release_time }}</div>
                            <div class="news-desc">{{ item.summarize }}</div>
                            <router-link :to="'/tools/toolsDetail/' + item.id" v-slot="{ navigate }" >
                                <el-button class="news-btn" type="primary" @click="navigate" >{{ t('news.read') }}</el-button>
                            </router-link>
                        </div>
                    </div>
                </el-col>
            </el-row>
            <data-loading v-if="loading" />
            <pagination v-show="total > 0" :total="total" :autoScroll="false"
                v-model:page="queryParams.curr_page"
                v-model:limit="queryParams.page_size"
                layout="total, prev, pager, next"
                @pagination="getList" />
        </div>
    </div>
</template>

<script setup name="Tools">
import BannerBar from "@/components/BannerBar"
import useAppStore from '@/store/modules/app'
import { queryBannerList } from '@/api/common'
import { queryToolReportList } from '@/api/tools'
import { serverLang } from '@/utils/i18n'
import { useLocale } from 'element-plus'
import { ref } from "vue"
import DataLoading from '@/components/DataLoading'

const { t } = useLocale()
const appStore = useAppStore()
const router = useRouter()

const showBanner = ref(appStore.showBanner == '1')
const bannerList = ref([])

const loading = ref(false);
const dataList = ref([])
const total = ref(0)
const data = reactive({
  queryParams: {
    curr_page: 1,
    page_size: 10,
    qcc_language: serverLang()
  }
});

const { queryParams } = toRefs(data)

function closeBanner() {
    showBanner.value = false
    appStore.setShowBanner('0')
}

function loadBannerList() {
    queryBannerList({
        qcc_language: serverLang(),
        position: 1,
        type: 2
    }).then(resp => {
        if (resp.data) {
            bannerList.value = resp.data
        }
    })
}

function getList() {
  loading.value = true;
  queryToolReportList(queryParams.value).then(response => {
    dataList.value = response.data.records;
    total.value = response.data.totalRecords;
    loading.value = false;
  })
}

function loadPageData() {
    loadBannerList();
    getList();
}

loadPageData();
</script>

<style lang="scss" scoped>
.banner-bar {
  margin-bottom: 5px;
}

.page-content {
  width: 100%;
  display: flex;
  flex-direction: column;

  .title-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;

    .title {
      font-size: 34px;
      font-weight: 700;
    }
  }
}

.news-item {
    height: 228px;
    width: 100%;
    margin-bottom: 30px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    // box-shadow: var(--el-box-shadow-light);

    .news-img {
        width: 408px;
        height: 100%;
        margin-right: 20px;
        object-fit: cover;
        flex-shrink: 0;
    }

    .news-info {
        width: 100%;
        height: 100%;
        padding: 14px 18px;
        position: relative;

        .news-title {
            font-size: 26px;
            font-weight: 700;
            color: rgba(51, 51, 51, 1);
            margin-bottom: 4px;
        }

        .news-time {
            font-size: 18px;
            font-weight: 400;
            color: #777777;
            margin-bottom: 8px;
        }

        .news-desc {
            color: #666666;
            font-size: 16px;
            font-weight: 400;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            line-clamp: 4;/*省略几行写几*/
            -webkit-line-clamp: 4;/*省略几行写几*/
            -webkit-box-orient: vertical;
        }

        .news-btn {
            position: absolute;
            bottom: 14px;
            left: 18px;
        }
    }
}
</style>