<template>
    <div class="navigate">
        <div class="partOne">
            <div class="inner">
                <div class="navLeft">
                    <div class="navIndex">
                        <NuxtLink :to="'/'" title="首页">首页</NuxtLink> 
                    </div>
                    <div class="navClass">
                        <div>
                            商城类
                        </div>
                        <div>
                            资讯类
                        </div>
                    </div>
                </div>
                <ul class="navigationOne">
                    <li v-for="(item, index) in navigation1" :key="index">
                        <NuxtLink :href="getLinkPath(item)" :title="item.alias" v-if="index<=23" :target="item.is_url == 1 ? '_blank' : '_self'">
                            {{ item.alias }}
                        </NuxtLink>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 深度服务 -->
        <div class="deepServer">
            <div class="inner">
                <div class="deepServer_left">
                    <div class="serverTitle">
                        深度服务
                    </div>
                    <ul class="contentList">
                        <li v-for="(item, index) in navigation2" :key="index">
                            <NuxtLink :href="getLinkPath(item)" :title="item.alias" :target="item.is_url == 1 ? '_blank' : '_self'">
                                {{ item.alias }}
                            </NuxtLink>
                        </li>
                    </ul>
                </div>
                <!-- <div class="deepServer_right">
                    <div class="serverTitle_right">
                        站内搜索:
                    </div>
                    <div class="searchRole">
                        <el-select v-model="depValue" placeholder="资讯" size="large" style="width: 100px">
                            <el-option v-for="(item, index) in department" :key="index" :label="item.name"
                                :value="item.id" />
                        </el-select>
                        <i></i>
                        <input type="text" v-model="typeValue" placeholder="输入关键词" class="ipt">
                        <em @click="goToPrimary"></em>
                    </div>
                </div> -->
            </div>
        </div>
    </div>
</template>

<script setup>
//1.获取导航菜单 start ---------------------------------------->
//第一行导航菜单 10个
const navigation1 = ref([]);
//两行的导航菜单 20个 
const navigation2 = ref([]);
//获取导航菜单1 
async function getNavigation1() {
    const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'pid': 0,
            'num': 20,
            'placeid': 1
        },
    });
    navigation1.value = mkdata.data;
}
getNavigation1();
//获取导航菜单2
async function getNavigation2() {
    const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'pid': 0,
            'num': 3,
            'placeid': 11
        },
    });
    navigation2.value = mkdata.data;
}
getNavigation2();
//1.获取导航菜单 end ---------------------------------------->

//2.搜索 start ---------------------------------------->
import { ElSelect, ElOption, ElMessage } from 'element-plus'
let department = ref("") //下拉框选项
const depValue = ref("") //搜索左侧下拉选择的值
const typeValue = ref("") //搜索右侧框输入的值

//2.1跳转到搜索页面
let goToPrimary = async () => {
    
    if (depValue.value == "" || typeValue.value=="") {
        ElMessage.error('搜索项不能为空！')
    }else{
        const route = `/search/search?depValue=${depValue.value}&typeValue=${typeValue.value}`;
        window.location.href = route;
    }
}

onMounted(async ()  => {
    //2.2 获得搜索选项
    try {
        const { $webUrl, $CwebUrl } = useNuxtApp();
        const response = await fetch($webUrl + '/web/selectWebsiteDepartment', {
            headers: {
                'Content-Type': 'application/json',
                'Userurl': $CwebUrl,
                'Origin': $CwebUrl
            }
        });
        const result = await response.json();
        department.value = result.data;
    } catch (error) {
        console.error('获取部门数据失败:', error);
    }
})
//2.搜索 end ---------------------------------------->

</script>

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