<template>
    <div class="search">
        <div class="inner">
            <!--搜索框样式1-->
            <div v-if="skinId == 1">
                <searchStyle1 :componentStyle="props.templateData[0].component_style"/>
            </div>
            <!--搜索框样式2-->
            <div v-if="skinId == 2">
                <searchStyle2 :componentStyle="props.templateData[0].component_style"/>
            </div>
            <!--搜索框样式3-->
            <div v-if="skinId == 3">
                <searchStyle3 :componentStyle="props.templateData[0].component_style"/>
            </div>
            <!--搜索框样式4-->
            <div v-if="skinId == 4">
                <searchStyle4 :componentStyle="props.templateData[0].component_style"/>
            </div>
        </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>
        </div>
    </div>
    <div :class="'newsList newsListStyle' + skinId">
        <div class="inner">
            <div class="innerLeft">
                <!--列表样式1 列表无需判断皮肤-->
                <listNews1 :listData="newsList" v-if="props.templateData[1].component_style==1"/>
                <!--列表样式2 列表无需判断皮肤-->
                <listNews2 :listData="newsList" v-if="props.templateData[1].component_style==2"/> 
                <!--列表样式3 列表无需判断皮肤-->
                <ListNews3 :listData="newsList" v-if="props.templateData[1].component_style==3"/>
                <!--列表样式4 列表无需判断皮肤-->
                <ListNews4 :listData="newsList" v-if="props.templateData[1].component_style==4"/>
                <div v-if="newsList.length == 0" class="empty">
                    <div>
                        <img src="http://img.bjzxtw.org.cn/pre/image/png/20250721/1753076876631321.png" alt="暂无内容">
                        <p>暂无搜索数据</p>
                    </div>
                </div>
                <div class="pagination" :class="'paginatioStyle'+skinId" v-if="total > 0">
                    <el-pagination 
                        size="small" 
                        background layout="prev, pager, next" 
                        :total="total" 
                        class="mt-4"
                        prev-text="上一页" 
                        next-text="下一页" 
                        @change="changePage" 
                    />
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
//引入搜索组件
import searchStyle1 from '@/components/template/component/search/700x46/1.vue'
import searchStyle2 from '@/components/template/component/search/700x46/2.vue'
import searchStyle3 from '~/components/template/component/search/700x46/3.vue'
import searchStyle4 from '@/components/template/component/search/700x46/4.vue'
//引入文章列表
import listNews1 from '@/components/template/component/list/900x1050/1.vue'
import listNews2 from '@/components/template/component/list/900x1050/2.vue'
import ListNews3 from '@/components/template/component/list/900x1050/3.vue'
import ListNews4 from '@/components/template/component/list/900x1050/4.vue'
//接口约束
import type { IListData } from '@/utils/dataInterface';
import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'
//获得皮肤编号
const props:any = defineProps({
    skinId:Number,
    templateData:Array,
});
console.log(props.templateData[0].component_style)
//把搜索获得的值保存起来
import { useState } from '#app'
const keywordInput = useState<string>('keywordInput', () => '')
const newsList = useState<IListData[]>('searchResults', () => [])
const total = useState<number>('searchTotal', () => 0)
const page = useState<number>('page', () => 1)
const pageSize = useState<number>('pageSize', () => 20)
console.log('搜索结果:', newsList.value)
console.log('搜索结果总数:', total.value)
//搜索事件
let goSearch = async () => {
    console.log(page.value)
    console.log(pageSize.value)
    console.log(keywordInput.value)
    const listData = await requestDataPromise('/web/selectWebsiteCategory', {
        method: 'GET',
        query: {
            'page': page.value,
            'pageSize': pageSize.value,
            'keyword': keywordInput.value,
        },
    });
    console.log(listData)
    if (listData.data.rows) {
        newsList.value = listData.data.rows; 
        total.value = listData.data.count;
    } else {
        newsList.value = [];
        total.value = 0;
    }
}
//分页事件
let changePage = (value:any) => {
    console.log("当前页码", value);
    page.value = value
    console.log(page.value);
    goSearch()
}
</script>

<style lang="less" scoped>
@import url('@/assets/css/search.less');
//基本样式 start ---------------------------------------->
//列表样式
.listBigBox{
    width: 100%;
    height: 1220px;
    margin-bottom: 30px;
    .listBox{
        width: 1200px;
        height: 1220px;
        margin: 0 auto;
        .listRouterBox{
            height: 52px;
            border-bottom: 1px solid #D9D9D9;
        }
        .listContentBox {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-top: 17px;
            .listContentBoxLeft {
                width: 900px;
                height: 1050px;
                position: relative;
            }
            .listContentBoxRight {
                width: 270px;
                height: 1050px;
                .listContentBoxRightTop {
                    width: 270px;
                    height: 440px;
                    margin-bottom: 30px;
                    position: relative;
                }
                .listContentBoxRightBottom {
                    width: 270px;
                    height: 580px;
                    position: relative;
                }
            }
        }
        .paginationBox {
            height: 100px;
            .paginationBoxLeft {
                width: 900px;
                height: 100px;
                //padding-top: 33px;
                box-sizing: border-box;
                text-align: center;
            }
        }
    }
}
//分页基本样式
.paginationBoxLeft {
    width: 800px;
    height: 34px;
    margin-left: 141px;
    display: flex;
    justify-content: center;
    margin: 0;
    .el-pagination.is-background::v-deep .btn-next,
    .el-pagination.is-background::v-deep .btn-prev {
        width: 70px;
        height: 34px;
        margin: 0px 10px;
        border-radius: 4px;
    }
    .el-pagination.is-background::v-deep .el-pager li {
        margin: 0px 10px;
        width: 38px;
        height: 34px;
        border-radius: 4px;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        color: #fff;
    }
}
//基本样式 end ---------------------------------------->

//分页样式1 start ---------------------------------------->
.paginatioStyle1 {
    .el-pagination::v-deep :hover {
        color: #004564;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        background-color: #004564;
    }
}
//分页样式1 end ---------------------------------------->

//分页样式2 start ---------------------------------------->
.paginatioStyle2 {
    .el-pagination::v-deep :hover {
        color: #A91B33;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        background-color: #A91B33;
    }
}
//分页样式2 end ---------------------------------------->

//分页样式3 start ---------------------------------------->
.paginatioStyle3 {
    .el-pagination::v-deep :hover {
        color: #c82200;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        background-color: #c82200;
    }
}
//分页样式3 end ---------------------------------------->

//分页样式4 start ---------------------------------------->
.paginatioStyle4 {
    .el-pagination::v-deep :hover {
        color: #fe8f00;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        background-color: #fe8f00;
    }
}
//分页样式4 end ---------------------------------------->

//分页样式5 start ---------------------------------------->
.paginatioStyle5 {
    .el-pagination::v-deep :hover {
        color: #49a769;
    }
    .el-pagination.is-background::v-deep .btn-next.is-active,
    .el-pagination.is-background::v-deep .btn-prev.is-active,
    .el-pagination.is-background::v-deep .el-pager li.is-active {
        background-color: #49a769;
    }
}
//分页样式5 end ---------------------------------------->
</style>