<template>
    <div id="projectList">
        <!-- 页面头部 -->
        <HomePageHead></HomePageHead>
        <!-- 导航栏 -->
        <HomePageNavigation1 :type="type"></HomePageNavigation1>
        <!-- 列表页广告一 -->
        <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
        <!-- 搜索框 -->
        <div class="search">
            <div class="inner">
                <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
                <button @click="goSearch">搜索</button>
            </div>
        </div>
        <div class="breadcrumb">
            <div class="inner">
                <span class="location">当前位置:</span>
                <el-breadcrumb :separator-icon="ArrowRight">
                    <el-breadcrumb-item>
                        <NuxtLink to="/">首页</NuxtLink>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item>搜索</el-breadcrumb-item>
                    <el-breadcrumb-item>项目</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </div>
        <div class="newsList">
            <div class="inner">
                <div class="innerLeft">
                    <ul class="list" v-if="projectList.length >= 0">
                        <li class="listItem" v-for="(item, index) in projectList" :key="index">
                            <NuxtLink :href="getLinkPathDetail(item)" :title="item.title"
                                :target="item.islink == 1 ? '_blank' : '_self'">
                                {{ item.title }}
                            </NuxtLink>
                            <!-- <span class="time right">{{ getTime(item.updated_at, 'month', 1) }}</span> -->
                        </li>
                    </ul>
                    <div v-if="projectList.length == 0" class="empty">
                        <div>
                            <img src="../../public/search/empty.png" alt="暂无内容">
                            <p>暂无搜索数据</p>
                        </div>
                    </div>
                    <!-- 分页器 -->
                    <div class="pagination" v-if="total > 0">
                        <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
                            :page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
                    </div>
                </div>
            </div>
        </div>
        <!-- 列表页广告二 -->
        <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
        <!-- 页面底部 -->
        <HomeFoot1></HomeFoot1>
    </div>
</template>

<script setup>
//1.页面依赖 start ---------------------------------------->
import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue';
//1.页面依赖 end ---------------------------------------->


//2.获取url中的参数 start ---------------------------------------->
const route = useRoute();
let keywordInput = ref(route.query.keyword);
let type = ref(route.query.type);

//2.获取url中的参数 end ---------------------------------------->

//3.在该页进行搜索 start ---------------------------------------->
//3.1 分页
let total = useState("total", () => 0)
let page = useState("page", () => 1)
let pageSize = useState("pageSize", () => 20)

//3.2 获得新闻列表
const projectList = ref([]);

//3.3 在本页进行搜索的方法
let goSearch = async () => {
    console.log(page.value)
    console.log(pageSize.value)
    console.log(keywordInput.value)

    const listData = await requestDataPromise('/web/getWebsiteProjectList', {
        method: 'GET',
        query: {
            'page': page.value,
            'pageSize': pageSize.value,
            'keyword': keywordInput.value,
        },
    });
    if (listData.code == 200) {
        console.log('listData', listData)
        projectList.value = listData.data.rows;
        total.value = listData.data.count;
    } else {
        projectList.value = [];
        total.value = 0;
    }
}

goSearch();

//3.4 分页事件
let changePage = (value) => {
    console.log("当前页码", value);
    page.value = value
    console.log(page.value);
    goSearch()
}
//3.在该页进行搜索 end ---------------------------------------->


//4.广告 start ---------------------------------------->
let adImg1 = ref([]);
let adImg2 = ref([]);

onMounted(async () => {
    //从客户端获取行政职能部门 加快打开速度
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_search_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];

    //广告2
    let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_search_0002`
    const responseAd2 = await fetch(url2, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd2 = await responseAd2.json();
    adImg2.value = resultAd2.data[0];
})
//4.页面数据 end ---------------------------------------->


//5.设置seo信息 start---------------------------------------->
const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
    method: 'GET',
    query: {},
});

let seoTitle = setData.data.website_head.title;
let seoDescription = setData.data.website_head.description;
let seoKeywords = setData.data.website_head.keywords;
let seoSuffix = setData.data.website_head.suffix;
let seoName = setData.data.website_head.website_name;

useSeoMeta({
    title: seoTitle + "_" + seoSuffix,
    meta: [
        { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
        { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
    ]
});
//5.设置seo信息 end---------------------------------------->
</script>

<style lang="less" scoped>
@import url('@/assets/css/project.less');

</style>