<template>
    <div class="search">
        <div class="inner">
            <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
            <button @click="goSearch" :class="'searchStyle' + skinId">搜索</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>
        </div>
    </div>
    <div :class="'newsListStyle' + skinId">
        <div class="inner">
            <div class="innerLeft">
                <ul class="list" v-if="newsList.length >= 0">
                    <li v-for="(item, index) in newsList" :key="index">
                        <NuxtLink :href="getLinkPathDetail(item)" :title="item.title"
                            :target="item.islink == 1 ? '_blank' : '_self'">
                            <span class="listText"> {{ item.title }}</span>
                            <span class="time">{{ getTime(item.updated_at, 'month', 1) }}</span>
                        </NuxtLink>
                    </li>
                </ul>
                <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" 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>
</template>

<script setup>
import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'
//获得皮肤编号
const props = defineProps({
    skinId:String,
});
//搜索栏 start---------------------------------------->
//自助建站没有城市，部门的功能
// const route = useRoute();
// const pageCatids = ""
// if (route.params.id == 'search') {
// } else {
//     const pageCatids = route.params.id
// }
//const pageDepartment_id = route.query.department_id;
//关键词
let total = useState("total", () => 0)
let page = useState("page", () => 1)
let pageSize = useState("pageSize", () => 20)
//格式化跳转链接
const getLinkPathDetail = (item) => {
    if (item.islink == 1) {
        return `${item.linkurl}`;
    } else {
        return `/${item.pinyin}/${item.id}.html`;
    }
}
//搜索栏 end---------------------------------------->
//新闻列表 start---------------------------------------->
// 新闻列表
const newsList = ref([]);
let keywordInput = ref("");
//搜索
let goSearch = async () => {
    console.log(page.value)
    console.log(pageSize.value)
    console.log(keywordInput.value)
    //console.log(pageCatids)
    //console.log(pageDepartment_id)
    const listData = await requestDataPromise('/web/selectWebsiteCategory', {
        method: 'GET',
        query: {
            'page': page.value,
            'pageSize': pageSize.value,
            'keyword': keywordInput.value,
            //'cityid': pageCatids,
            //'department_id': pageDepartment_id
        },
    });
    if (listData.data.rows) {
        console.log(listData)
        newsList.value = listData.data.rows;
        total.value = listData.data.count;
    } else {
        newsList.value = [];
        total.value = 0;
    }
}
goSearch();
//分页事件
let changePage = (value) => {
    console.log("当前页码", value);
    page.value = value
    console.log(page.value);
    goSearch()
}
//新闻列表 end---------------------------------------->
</script>

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