<template>
    <div class="search">
        <div class="inner">
            <!--搜索框样式1-->
            <div v-if="skinId == 5">
                <searchStyle5 :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">
                <!--皮肤5列表-->
                <listNews5 :listData="newsList"  :componentStyle="props.templateData[1].component_style" v-if="skinId == 5"/>
                <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 searchStyle5 from '~/components/template/component/search/700x46/5.vue'
//引入文章列表
import listNews5 from '@/components/template/component/list/1200x2250/1.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', () => 10)
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 ---------------------------------------->

//分页样式5 start ---------------------------------------->
.paginatioStyle5 {
    .el-pagination::v-deep :hover {
        color: #3848a0;
    }
    .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: #3848a0;
    }
}
//分页样式5 end ---------------------------------------->
</style>