<template>
    <!-- 导航 -->
    <div class="navigate">
        <div class="partOne">
            <div class="inner">
                <!-- 导航一 -->
                <ul class="navigationOne">
                    <li v-for="(item, index) in navigation1" :key="index">
                        <!-- <NuxtLink :to="`/primaryNavigation/${item.alias}`" target="_blank">{{ item.alias }}</NuxtLink> -->
                        <NuxtLink :to="{path:`/primaryNavigation/${item.category_id}`,query:{name:item.name}}" target="_blank" v-if="item.children_count!=0">{{ item.name }}</NuxtLink>
                        <NuxtLink :to="{path:`/newsList/${item.category_id}`,query:{name:item.name}}" target="_blank" v-if="item.children_count==0">{{ item.name }}</NuxtLink>
                    </li>
                </ul>
            </div>
        </div>

        <!-- <div class="partTwo">
            <div class="inner">
                <ul class="navigationTwo">
                    <li v-for="(item,index) in navigation2" :key="index">{{ item.name }}</li>
                </ul>
            </div>
        </div> -->

        <!-- <div class="partThree">
            地方频道
            <div class="inner">
                channel 频道
                <h5 class="channel">地方频道</h5>
                <p class="areaChannel">
                    <span v-for="(item, index) in areaList" :key="index">
                        <a href="#">{{ item.name }}</a>
                    </span>
                </p>
            </div>
        </div> -->

        <!-- 导航栏下的大图 -->
        <!-- <div class="logo">
            <div class="inner">
                <img src="../../static/images/banner1.png" alt="">
            </div>
        </div> -->
        <HomeSannongzixun></HomeSannongzixun>

        <!-- 行政查询 -->
        <!-- <div class="select">
            <div class="inner">
                <div class="role left">
                    <div class="title">行政职能查询</div>
                    <div class="searchRole">
                        <el-select v-model="depValue" placeholder="职能部门" size="large" style="width: 80px">
                            <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="searchDepartment"></em>
                    </div>
                </div>
                <div class="region left">
                    <div class="title">行政区划查询</div>
                    <div class="searchRole">
                        <el-select v-model="province" placeholder="请选择省" size="large" style="width: 80px">
                            <el-option v-for="item in provinceList" :key="item.id" :label="item.name"
                                @click="change(item.id)" :value="item.id" />
                        </el-select>
                        <i></i>
                        <el-select v-model="city" placeholder="请选择市" no-data-text="请先选择省份" size="large"
                            style="width: 80px">
                            <el-option v-for="(item, index) in cityList" :key="item.id" :label="item.name"
                                @click="change1(item.id)" :value="item.id" />
                        </el-select>
                        <i></i>
                        <el-select v-model="region" placeholder="请选择区/县" no-data-text="请先选择市" size="large"
                            style="width: 100px">
                            <el-option v-for="item in regionList" :key="item.id" :label="item.name"
                                :value="item.id" />
                        </el-select>
                        <em @click="goToPrimary"></em>
                    </div>
                </div>
            </div>
        </div> -->
    </div>

</template>

<script setup>
import { ref, onMounted } from 'vue';
import { ElSelect, ElOption } from 'element-plus'
const nuxtApp = useNuxtApp();
const axios = nuxtApp.$axios;
//获得route
const route = useRoute();
const routeId = route.params.id; //获得该页面的id
const pageName = route.query.name;//获得页面名称

//获取导航一的栏目
const navigation1 = ref("");
const navigateList = async () => {
    try {
        const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
        console.log(response.data);
        navigation1.value = response.data;
    } catch (error) {
        console.error(error);
    }
}

// const navigateList = async () => {
//     try {
//         const response = await axios.get(`/web/getWebsiteCategory?pageSize=${24}`);
//         console.log(response.data);
//         navigation1.value = response.data;
//     } catch (error) {
//         console.error(error);
//     }
// }

//获取导航二的栏目
const navigation2 = ref("");
const navigate2List = async () => {
    try {
        const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${2}&pid=${1}&num=${13}`);
        // console.log(response.data);
        navigation2.value = response.data;
    } catch (error) {
        console.error(error);
    }
}

//职能部门 搜索
let department = ref("安全")
const depValue = ref("")
const typeValue = ref("")
let departmentList = async () => {
    try {
        const response = await axios.get(`/web/selectWebsiteDepartment?keyword=${department.value}`);
        // console.log(response.data.department);
        department.value = response.data.department
        // console.log(department.value);
    } catch (error) {
        console.error(error);
    }
}


//获取地区各省名称
let areaList = ref("")
//获取省名称
let province = useState("province", () => "")
let provinceid = useState("provinceid", () => null)
let provinceList = useState("provinceList", () => "")
let areaArrList = async () => {
    try {
        const response = await axios.get('/web/getWebsiteDistrit');
        console.log(response.data);
        areaList.value = response.data;
        provinceList.value = response.data
    } catch (error) {
        console.error(error);
    }
}

// 获取城市名称
let city = useState("city", () => "")
let cityid = useState("cityid", () => "")
let cityList = useState("cityList", () => "")

//选择省份后省份的id
let change = (id) => {
    console.log(id);
    provinceid.value = id
    console.log(provinceid.value);

    //根据省id获取对应的市名称
    axios.get(`web/selectWebsiteArea?province=${provinceid.value}&city=0`).then(response => {
        // console.log("response", response.data.city);
        cityList.value = response.data.city;
        // console.log("cityList", cityList.value);
    }).catch(error => {
        console.error(error);
    })

}

// 获取区/县名称
let region = useState("region", () => "")
let regionid = useState("regionid", () => "")
let regionList = useState("regionList", () => "")

//选择市后市的id
let change1 = (id) => {
    console.log(id);
    cityid.value = id
    console.log(cityid.value);

    //根据市id获取对应的区/县名称
    axios.get(`web/selectWebsiteArea?province=${provinceid.value}&city=${cityid.value}`).then(response => {
        // console.log("response", response.data);
        regionList.value = response.data.region;
        // console.log("regionList", regionList.value);
    }).catch(error => {
        console.error(error);
    })
}

//depValue.value 行政区划
//二级导航id
//province.value 省id
//city.value 市id
//region.value 县id
const getcityid = ref("")
//获得cityid和
let goToPrimary = () => {
    console.log(depValue.value)
    console.log(routeId)
    if(province.value!=""){getcityid.value = province.value}
    if(city.value!=""){getcityid.value = city.value}
    if(region.value!=""){getcityid.value = region.value}
    console.log(getcityid.value)
    console.log(pageName)

    //跳转过去
    // navigateTo({
    //     path: `/primaryNavigation/${routeId}`,
    //     query: {
    //         cityid: getcityid.value,
    //         name: pageName,
    //         department_id: depValue.value
    //     }
    // })

    const route = `/primaryNavigation/${routeId}?cityid=${getcityid.value}&name=${pageName}&department_id=${depValue.value}`;
    window.open(route, '_blank');

}

let searchDepartment = () => {
    //搜索职能部门
    //console.log(typeValue.value)
    //console.log(department.value)
    let status = false;
    for(let item of department.value){
        if(item.name==typeValue.value){
            console.log(item.name)
            //如果有就赋值过去
            depValue.value = item.id
            status = true; //说明有可用的结果
        }
    }
    if(status==true){
        //弹出提示告诉用户不存在
    }
}

//挂载成功钩子函数
onMounted(() => {
    //导航一栏目
    navigateList()

    //导航二栏目
    navigate2List()

    //获取地区各省名称
    areaArrList()

    //获取职能部门
    departmentList()


})


</script>

<style lang="less" scoped>
// 导航部分
.partOne .navigationOne,
.partOne .navigationOne>li,
.partTwo .navigationTwo,
.partTwo .navigationTwo>li {
    float: left;
}

.partOne {
    width: 100%;
    height: 110px;
    line-height: 50px;
    margin-bottom: 30px;
    background-color: #fff;
    font-size: 20px;
    font-family: PingFang SC-Semibold;
    border-bottom: 1px solid #e3e3e3;

    .navigationOne {
        width: 1200px;
        height: 105px;
        color: #333;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;

        li {
            font-family: PingFang SC;
            font-weight: 600;
            font-size: 20px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            margin: 0 10px;

            // &:nth-last-child(1) {
            //     margin-right: 0px;
            // }

            a {
                color: #333;
            }
        }

        >li:hover a {
            color: #139602;
        }

    }
}

// .partTwo {
//     width: 100%;
//     height: 57px;
//     line-height: 57px;
//     border-bottom: 1px solid #e3e3e3;

//     .navigationTwo {
//         width: 1207px;
//         height: 57px;
//         color: #333333;
//         border-bottom: 1px solid #e3e3e3;

//         li {
//             font-weight: 600;
//             font-size: 20px;
//             height: 56px;
//             margin-right: 21px;

//             &:nth-last-child(1) {
//                 margin-right: 0px;
//             }
//         }

//         li:hover {
//             color: #139602;
//             border-bottom: 2px solid #139602;
//         }

//     }
// }

.partThree {
    width: 100%;
    height: 105px;

    .inner {
        margin-bottom: 5px;
    }

    .channel,
    .areaChannel {
        float: left;
        margin-top: 17px;
    }

    .channel {
        width: 56px;
        height: 20px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 14px;
        color: #666666;
        line-height: 20px;
        text-align: left;
        font-style: normal;
        text-transform: none;

    }


    .areaChannel {
        width: 1122px;
        margin-left: 14px;

        >span {
            display: inline-block;
            height: 16px;
            line-height: 16px;
            margin-bottom: 10px;
            padding: 0 8px;
            text-align: center;
            font-family: PingFang SC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            text-align: center;
            font-style: normal;
            text-transform: none;
            border-right: 1px solid #e6e6e6;

            a {
                display: inline-block;
                height: 16px;
                color: #868686;
            }

            a:hover {
                color: #868686;
            }
        }

        >span:last-child,
        >span:nth-child(18),
        >span:nth-child(32) {
            border-right: none;

        }

        >span:hover a {
            color: #139602;
        }
    }
}


.logo {
    margin-top: 5px;
    height: 90px;

    img {
        width: 1200px;
        height: 90px;
    }
}

// 行政查询
.select {
    width: 100%;
    height: 62px;
    line-height: 62px;
    margin-top: 20px;

    .inner {
        width: 1200px;
        height: 62px;
        margin-top: 10px;
        background-color: #fafafa;
    }

    .role,
    .region {
        float: left;
        height: 62px;

        .el-select--large::v-deep .el-select__wrapper {
            font-size: 14px;
            gap: 6px;
            line-height: 24px;
            min-height: 35px;
            padding: 0;
            border: none;
            box-shadow: none;
        }

        .el-select__placeholder::v-deep.is-transparent {
            color: #999999;
            font-weight: 600;
        }

        >.title {
            float: left;
            width: 120px;
            font-family: PingFang SC, PingFang SC;
            font-weight: 600;
            font-size: 20px;
            color: #666666;
            text-align: left;
            font-style: normal;
            text-transform: none;
        }

        .searchRole {
            float: left;
            padding-left: 20px;
            box-sizing: border-box;

            i {
                display: inline-block;
                width: 1px;
                height: 12px;
                background-color: #d9d9d9;
                margin: 0 10px;
                vertical-align: middle;
            }
        }

    }

    .role {
        padding-left: 16px;

        .searchRole {
            width: 440px;
            height: 40px;
            line-height: 35px;
            background-color: #fff;
            border: 1px solid #ededed;
            margin: 10px 20px 12px 22px;
            border-radius: 25px;

            em {
                display: inline-block;
                width: 29px;
                height: 29px;
                margin: 4px;
                margin-right: 25px;
                vertical-align: -13px;
                background: url('../../static/images/Iconly／Broken／Search.png');
                cursor: pointer;
            }

            >.ipt {
                width: 245px;
                font-family: PingFang SC, PingFang SC;
                font-weight: 600;
                font-size: 14px;
                color: #666;
                line-height: 16px;
                padding-left: 22px;
                box-sizing: border-box;
                text-align: left;
                font-style: normal;
                text-transform: none;
                border: none;
                outline: none;
            }

            >.ipt::placeholder {
                color: #cccccc;
            }



            span {
                color: #999999;
            }
        }
    }

    .region {
        .searchRole {
            width: 440px;
            height: 40px;
            line-height: 35px;
            background-color: #fff;
            border: 1px solid #ededed;
            margin: 10px 0px 12px 16px;
            border-radius: 25px;
        }

        em {
            display: inline-block;
            width: 29px;
            height: 29px;
            margin-left: 48px;
            vertical-align: middle;
            background: url('../../static/images/Iconly／Broken／Search.png');
            cursor: pointer;
        }

        i {
            display: inline-block;
            width: 24px;
            height: 24px;
            margin-right: 11px;
            vertical-align: middle;
            background: url("../../static/images/Iconly／Two-tone／Arrow - Down 3.png");
        }

        span {
            color: #999999;
            margin-right: 22px;
        }
    }
}
</style>