<template>
    <!-- 地区选择 -->
    <div class="shop_name_out">
        <div class="shop_name_box clearfix">
            <div class="shop_name">地区选择</div>
            <div class="shop_name_right">
                <div class="shop_name_in clearfix" ref="shop_name_parent">
                    <div class=" clearfix" v-show="shop_name_num == 1">
                        <NuxtLink
                            :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
                            :title="item.name" v-for="item in provinceList1"
                            :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]">
                            {{ item.abbreviation }}
                        </NuxtLink>
                    </div>
                    <div class=" clearfix" v-show="shop_name_num == 2">
                        <NuxtLink :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
                            :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
                            :title="item.name" v-for="item in provinceList2">
                            {{ item.abbreviation }}
                        </NuxtLink>
                    </div>
                    <div class=" clearfix" v-show="shop_name_num == 3">
                        <NuxtLink :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
                            :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
                            :title="item.name" v-for="item in provinceList3">
                            {{ item.abbreviation }}
                        </NuxtLink>
                    </div>
                </div>
                <div class="shop_name_btn hand"
                    @click="shop_name_num >= shop_name_leng ? shop_name_num = 1 : shop_name_num++">
                </div>
            </div>
        </div>
    </div>
    <!-- 地区选择 -->
</template>

<script setup>
import { ref, onMounted, watch } from 'vue'

//1.获得商城导航 start ---------------------------------------->
//1.1 获得频道导航的id，并且标记导航
//获得当前的完整路径
// const fullPath = route.path;
// //拆分，取出来中间这一段，然后提取数字部分
const targetSegment = getRoutePath(1);
const targetSegment1 = getRoutePath(2);
const targetSegment2 = getRoutePath(3);
// const segments = fullPath.split('/');
// const targetSegment = segments[2];

const navId = ref(0)//当前导航标记哪个
//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
console.log("getRouteId", getRouteId);

if (getRouteId.code == 200) {
    navId.value = parseInt(getRouteId.data.category_id)
} else {
    console.log("错误位置：通过url路径查询导航池id")
}

//1.2 获得商城导航
const shopNav = ref("")
const shopNavOnePinyin = ref("")//获得商城导航的第一个 作为默认的跳转链接
let getShowNav = async () => {
    const responseStatus = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            placeid: 0,
            pid: navId.value,
            num: 8,
            type: 1
        },
    });
    console.log("responseStatus", responseStatus);

    shopNav.value = responseStatus.data
    shopNavOnePinyin.value = responseStatus.data[0].aLIas_pinyin
    console.log("shopNavOnePinyin", shopNavOnePinyin.value);

}
getShowNav();

//1.3 标记当前选择的地区
const route = useRoute();
//获得详情id
const cityId = ref(route.query.cityid)

watch(route, () => {
    cityId.value = route.query.cityid
})



//1.获得商城导航 end ---------------------------------------->

//2.获得省列表 start ---------------------------------------->
const provinceList1 = ref([]);//省列表1
const provinceList2 = ref([]);//省列表2
const provinceList3 = ref([]);//省列表3
onMounted(async () => {
    //获得所有的省
    try {
        const { $webUrl, $CwebUrl } = useNuxtApp();
        const response = await fetch($webUrl + '/web/selectWebsiteArea', {
            headers: {
                'Content-Type': 'application/json',
                'Userurl': $CwebUrl,
                'Origin': $CwebUrl
            }
        });
        const result = await response.json();
        for (let index in result.data) {
            if (index < 15) {
                provinceList1.value.push(result.data[index])
            } else if (index > 14 && index < 30) {
                provinceList2.value.push(result.data[index])
            } else if (index > 29) {
                provinceList3.value.push(result.data[index])
            }
        }
    } catch (error) {
        console.error('获取行政区划数据失败:', error);
    }


})
//2.获得商城导航 start ---------------------------------------->

//3.地区滚动 start ---------------------------------------->
// 地区选择
const shop_name_num = ref(1)
const shop_name_parent = ref(null)
const shop_name_leng = ref(1)
onMounted(() => {
    const shop_name_son = shop_name_parent.value.querySelectorAll("div")
    shop_name_leng.value = shop_name_son.length
})
//3.地区滚动 end ---------------------------------------->
</script>

<style lang="less" scoped>
.shop_name_out {
    margin-top: 20px;
}

.shop_name_box {
    border-top: solid 1px #fff;

    .shop_name_box_a {
        height: 44px;
        line-height: 44px;
        color: #fff;
        font-weight: bold;
        font-size: 20px;
    }

    .shop_name {
        float: left;
        height: 44px;
        line-height: 44px;
        color: #fff;
        font-weight: bold;
        position: relative;
        z-index: 11;
        text-align: center;
        font-size: 20px;
        background: #a91b33;
        padding: 0px 14px;
    }

    .shop_name_right {
        height: 40px;
        border-bottom: 1px solid #E8E9EC;
        margin-top: 4px;
        background: #F8F8F8;
        position: relative;
        z-index: 2;
    }

    .shop_name_right::after {
        content: '';
        display: block;
        position: absolute;
        top: 0px;
        right: 0px;
        height: 100%;
        width: 16px;
        background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
        background-size: 100% auto;
    }

    .shop_name_btn {
        width: 24px;
        height: 24px;
        float: right;
        margin: 10px 22px 0px 0px;
        background: url(@/public/img/8.png) no-repeat center center;
        border-radius: 50%;
        background-size: 100% 100%;
    }
}

.shop_name_in {
    float: left;
    height: 40px;
    width: 1046px;
    float: left;
    box-sizing: border-box;

    .shop_name_a {
        float: left;
        height: 27px;
        line-height: 27px;
        color: #222;
        font-size: 20px;
        position: relative;
        margin: 7px 14.5px 0;
        padding: 0px 10px;
    }

    .shop_name_a::after {
        content: '/';
        display: block;
        position: absolute;
        top: 0px;
        right: -18px;
        height: 100%;
        line-height: 27px;
        color: #E9E9E9;
        font-size: 20px;
    }

    .shop_name_a:nth-last-of-type(1)::after {
        content: '';
        display: none;
    }

    .shop_name_a_only {
        background: #a91b33;
        color: #fff;
    }
}

.shop_name_out {
    margin-top: 20px;
}

.shop_name_box {
    border-top: solid 1px #fff;

    .shop_name_box_a {
        height: 44px;
        line-height: 44px;
        color: #fff;
        font-weight: bold;
        font-size: 20px;
    }

    .shop_name {
        float: left;
        height: 44px;
        line-height: 44px;
        color: #fff;
        font-weight: bold;
        position: relative;
        z-index: 11;
        text-align: center;
        font-size: 20px;
        background: #a91b33;
        padding: 0px 14px;
    }

    .shop_name_right {
        height: 40px;
        border-bottom: 1px solid #E8E9EC;
        margin-top: 4px;
        background: #F8F8F8;
        position: relative;
        z-index: 2;
    }

    .shop_name_right::after {
        content: '';
        display: block;
        position: absolute;
        top: 0px;
        right: 0px;
        height: 100%;
        width: 16px;
        background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
        background-size: 100% auto;
    }

    .shop_name_btn {
        width: 24px;
        height: 24px;
        float: right;
        margin: 10px 22px 0px 0px;
        background: url(@/public/img/8.png) no-repeat center center;
        border-radius: 50%;
        background-size: 100% 100%;
    }
}

.shop_nav {
    border: solid 1px #E9E9E9;
    background: #fafafa;
    margin-top: 20px;

    .shop_nav_head {
        float: left;
        height: 28px;
        width: 138px;
        margin: 30px 52px 0px 25px;
    }

    .shop_nav_head_a {
        display: block;
        height: 28px;
        width: 138px;
        background: url(@/public/img/7.png) no-repeat left top;
        background-size: 100% 100%;
    }
}

.clearfix {
    overflow: hidden;
}

.shop_nav_in_a {
    float: left;
    height: 75px;
    line-height: 75px;
    color: #333;
    font-size: 16px;
    background: #f8f5f5;
    width: 118px;
    border-bottom: solid 5px #a91b33;
    font-weight: bold;
    margin: 5px 0;
    text-align: center;
}

.shop_nav_in_a:nth-of-type(4) {
    margin-right: 8px;
}

.shop_nav_in_a:hover {
    color: #a91b33;
}

.shop_nav_in_a_active {
    color: #a91b33;
}
</style>