<template>
    <div>
        <!--样式1-->
        <div class="searchInputBox" v-if="componentStyle == 1">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput"/>
            </div>
            <div class="searchBtn" @click="goSearch">
                搜索
            </div>
        </div>
        <!--样式2-->
        <div class="searchInputBox searchInputStyle2" v-if="componentStyle == 2">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput"/>
            </div>
            <div class="searchBtn" @click="goSearch">
                搜索
            </div>
        </div>
        <!--样式3-->
        <div class="searchInputBox searchInputStyle3" v-if="componentStyle == 3">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                搜索
            </div>
        </div>
        <!--样式4-->
        <div class="searchInputBox searchInputStyle4" v-if="componentStyle == 4">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                搜索
            </div>
        </div>
        <!--样式5-->
        <div class="searchInputBox searchInputStyle5" v-if="componentStyle == 5">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                搜索
            </div>
        </div>
        <!--样式6-->
        <div class="searchInputBox searchInputStyle6" v-if="componentStyle == 6">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                <img src="http://192.168.1.234:19000/pre/image/png/20251219/1766107674897914.png">
            </div>
        </div>
        <!--样式7-->
        <div class="searchInputBox searchInputStyle7" v-if="componentStyle == 7">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
                <img src="http://192.168.1.234:19000/pre/image/png/20251219/1766107691269626.png"  @click="goSearch">
            </div>
        </div>
        <!--样式8-->
        <div class="searchInputBox searchInputStyle7" v-if="componentStyle == 8">
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
                <img src="http://192.168.1.234:19000/pre/image/png/20251219/1766107703516752.png"  @click="goSearch">
            </div>
        </div>
        <!--样式9-->
        <div class="searchInputBox searchInputStyle9" v-if="componentStyle == 9">    
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                <span>搜索</span> 
                <img src="http://192.168.1.234:19000/pre/image/png/20251219/1766107715193843.png" >
            </div>
        </div>
        <!--样式10-->
        <div class="searchInputBox searchInputStyle10" v-if="componentStyle == 10">    
            <div class="searchInputBorder">
                <input type="text" placeholder="请输入搜索内容" v-model="keywordInput" />
            </div>
            <div class="searchBtn"  @click="goSearch">
                <img src="http://192.168.1.234:19000/pre/image/png/20251219/1766107715193843.png">
                <span>搜索</span> 
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
//把搜索获得的值保存起来
import type { IListData } from '@/utils/dataInterface';
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)

const props = defineProps({
    componentStyle:Number,//样式编号
});
//搜索栏 start---------------------------------------->
//关键词
//let total = ref<number>(0)
//let page = ref<number>(1)
//let pageSize = ref<number>(20)
//格式化跳转链接
const getLinkPathDetail = (item:any) => {
    if (item.islink == 1) {
        return `${item.linkurl}`;
    } else {
        return `/${item.pinyin}/${item.id}.html`;
    }
}
//搜索栏 end---------------------------------------->
//新闻列表 start---------------------------------------->
//新闻列表
//const newsList = ref<IListData[]>([]);
//let keywordInput = ref("");
//搜索
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) {
        // console.log(listData)
        // newsList.value = listData.data.rows;
        // total.value = listData.data.count;
        // 获得搜索结果
        newsList.value = listData.data.rows; 
        total.value = listData.data.count;
    } else {
        // newsList.value = [];
        // total.value = 0;
        newsList.value = [];
        total.value = 0;
    }
}
goSearch();
//分页事件
let changePage = (value:any) => {
    console.log("当前页码", value);
    page.value = value
    console.log(page.value);
    goSearch()
}
//新闻列表 end---------------------------------------->
</script>

<style scoped lang="less">
//基本样式 start ---------------------------------------->
.searchInputBox {
    display: flex;
    align-items: center;
    justify-content: center;
    .searchInputBorder {
        width: 582px;
        height: 46px;
        input {
            width: 582px;
            height: 46px;
            font-size:16px;
            color:#333333;
            border:1px solid #E6E6E6;
            outline: none;
            box-sizing: border-box;
            padding:20px 13px;
        }
    }
    .searchBtn {
        width: 120px;
        height: 46px;
        text-align: center;
        line-height: 46px;
        color:#fff;
        background: #154079;
        cursor: pointer;
    }
}
//基本样式 end ---------------------------------------->

//样式2 start ---------------------------------------->
.searchInputStyle2 {
    // .searchInputBorder {
    //     box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, 0.1);
    // }
    .searchBtn {
        color:#333333;
        border:1px solid #E6E6E6;
        box-sizing: border-box;
        border-left: none;
        // box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, 0.1);
        background: #fff;
    }
}
//样式2 end ---------------------------------------->
//样式3
.searchInputStyle3 {
    .searchBtn{
        background-color: #333333;
    }
}
//样式4
.searchInputStyle4 {
    // .searchInputBorder {
    //     box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, 0.1);
    // }
    .searchBtn {
        margin-left: 5px;
        color:#fff;
        border:1px solid #E6E6E6;
        box-sizing: border-box;
        border-left: none;
        // box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, 0.1);
        background: #154079;
    }
}
//样式5
.searchInputStyle5 {
    .searchBtn {
        margin-left: 5px;
        color:#fff;
        background: #333333;
    }
}
//样式6
.searchInputStyle6 {
    .searchBtn {
        background: #154079;
        img {
            margin-top: 11px;
            width: 24px;
            height: 24px;
        }
    }
}
//样式7
.searchInputStyle7 {
    .searchInputBorder {
        width: 702px;
        height: 44px;
        position: relative;
        border: 1px solid #E6E6E6;
        input{
            height: 44px;;
            border: none;
        }
        img{
            position: absolute;
            right: 20px;
            top: 11px;
            width: 24px;
            height: 24px;
        }
    }
}
//样式9
.searchInputStyle9 {
    .searchBtn {
        img{
            width: 16px;
            height: 16px;
            margin-left: 5px;
            margin-top: 16px;
            vertical-align: -4px;
        }
    }
}
//样式10
.searchInputStyle10 {
    .searchBtn {
        img{
            width: 16px;
            height: 16px;
            margin-right: 5px;
            margin-top: 16px;
            vertical-align: -4px;
        }
    }
}
</style>