<template>
    <main class="index_main">
        <section class="index_0 clearfix">
            <div class="shop_head_1 clearfix">
                <div class="shop_head_1_name" :title="secNavTitle">{{ secNavTitle }}</div>
            </div>
            <div class="categ_color_box clearfix">
                <div class="categ_color_name clearfix">直达：</div>
                <div class="categ_color_in clearfix">
                    <NuxtLink class="categ_color_a" :href="`/${item.aLIas_pinyin}/list-1.html`" :title="item.title"
                        v-for="(item, index) in pageData" :key="index">
                        {{ item.alias }}
                    </NuxtLink>
                </div>
            </div>
        </section>
        <!-- 面包屑导航 -->
        <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 v-if="parent_name != ''">
                        <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item>
                        <NuxtLink :to="`list-1.html`"> {{ secNavTitle }}</NuxtLink>
                    </el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </div>
        <!-- 模块1,模块2 -->
        <section class="index_1 clearfix">
            <div class="box_1 clearfix" v-if="jobData.length > 0">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobData[0])" :title="jobData[0].title">
                        {{ jobData[0].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1">
                    <div class="ul_1_li" v-for="(item, index) in jobData[0].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_1_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
            <div class="box_1 clearfix" v-if="jobData.length > 1">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobData[1])" :title="jobData[1].title">
                        {{ jobData[1].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1 clearfix">
                    <div class="ul_1_li" v-for="(item, index) in jobData[1].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_1_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </section>
        <!-- 模块3 -->
        <section class="index_2 clearfix" v-if="jobData.length > 2">
            <div class="box_2 clearfix">
                <div class="box_2_head">
                    <NuxtLink class="box_2_head_name" :href="getLinkPath(jobData[2])" :title="jobData[2].title">
                        {{ jobData[2].title }}
                    </NuxtLink>
                </div>
                <div class="ul_2 clearfix">
                    <div class="ul_2_li" v-for="(item, index) in jobData[2].data" :key="index">
                        <NuxtLink class="ul_2_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_2_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_2_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </section>
        <!-- 模块4,模块5 -->
        <section class="index_1 clearfix" v-if="jobData.length > 4">
            <div class="box_1 clearfix" v-if="jobData.length > 3">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobData[3])" :title="jobData[3].title">
                        {{ jobData[3].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1">
                    <div class="ul_1_li" v-for="(item, index) in jobData[3].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_1_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
            <div class="box_1 clearfix" v-if="jobData.length > 4">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobData[4])" :title="jobData[4].title">
                        {{ jobData[4].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1 clearfix color_bule_box">
                    <div class="ul_1_li" v-for="(item, index) in jobData[4].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_1_li_text dot1 color_bule">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </section>
        <!-- 模块6 -->
        <section class="index_2 clearfix" v-if="jobData.length > 5">
            <div class="box_2 clearfix">
                <div class="box_2_head">
                    <NuxtLink class="box_2_head_name" :href="getLinkPath(jobData[5])" :title="jobData[5].title">
                        {{ jobData[5].title }}
                    </NuxtLink>
                </div>
                <div class="ul_2 clearfix">
                    <div class="ul_2_li" v-for="(item, index) in jobData[5].data" :key="index">
                        <NuxtLink class="ul_2_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_2_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_2_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </section>
        <!-- 模块7,模块8 -->
        <section class="index_1 clearfix">
            <div class="box_1 clearfix">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobData[6])" :title="jobData[6].title">
                        {{ jobData[6].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1">
                    <div class="ul_1_li" v-for="(item, index) in jobData[6].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.title }}</h4>
                            <div class="ul_1_li_text dot1">{{ item.business_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
            <!-- 求职 -->
            <div class="box_1 clearfix" v-if="jobHunting.length > 0">
                <div class="box_1_head">
                    <NuxtLink class="box_1_head_name" :href="getLinkPath(jobHunting[0])" :title="jobHunting[0].title">
                        {{ jobHunting[0].title }}
                    </NuxtLink>
                </div>
                <div class="ul_1 clearfix color_bule_box">
                    <div class="ul_1_li" v-for="(item, index) in jobHunting[0].data" :key="index">
                        <NuxtLink class="ul_1_li_a" :href="getLinkPathDetail(item)" :title="item.title">
                            <h4 class="ul_1_li_h4 ">{{ item.name }}</h4>
                            <div class="ul_1_li_text dot1 color_bule">{{ item.job_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </section>
    </main>
</template>


<script setup>
//0.加载页面依赖 start ---------------------------------------->
import { ref, onMounted } from 'vue';
import { ElMessage, ElBreadcrumb, ElBreadcrumbItem } from 'element-plus';
import { ArrowRight } from '@element-plus/icons-vue'
import { NuxtLink } from '#components';
//0.加载页面依赖 end ---------------------------------------->

//1.获得路由id start ---------------------------------------->
const targetSegment = getRoutePath(2);
const targetSegment1 = getRoutePath(1);
//1.1 获得当前的路由id
let routeId;
let routeType;
let secNavTitle = ref('')//二级导航标题
//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
console.log("getRouteId", getRouteId);

if (getRouteId.code == 200) {
    routeId = getRouteId.data.category_id
    secNavTitle.value = getRouteId.data.alias
    routeType = getRouteId.data.type
} else {
    console.log("获得路由id出错！", getRouteId.message)
}
//1.2 获得父级栏目
let parent_name = ref('');//父级名称
let parent_id = ref('');//父级id
let parent_pinyin = ref('');//父级拼音
const getRoutePName = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment1,
    },
});
// console.log("getRoutePName", getRoutePName);

if (getRoutePName.code == 200) {
    parent_id.value = getRoutePName.data.category_id
    parent_name.value = getRoutePName.data.alias
} else {
    console.log("获得路由id出错！", getRoutePName.message)
}
const getParentId = await requestDataPromise('/web/getOneWebsiteCategory', {
    method: 'GET',
    query: {
        'catid': parent_id.value,
    },
});
// console.log("getParentId", getParentId);

if (getParentId.code == 200) {
    parent_pinyin.value = getParentId.data.aLIas_pinyin
} else {
    console.log("获得路由id出错！", getParentId.message)
}
//1.获得路由id end ---------------------------------------->

//2.选项卡 start ---------------------------------------->
let showTabs = ref(1)
let qhtabs = function (number) {
    console.log(number)
    showTabs.value = number
}
//2.选项卡 end ---------------------------------------->

//4.页面数据 start ---------------------------------------->
const pageData = ref([
    //示例：
    // {
    //     id: 1, 
    //     title: "", //该导航的标题
    //     data: [], //数据1
    //     data1: [], //数据2
    //     data2: [], //数据3
    //     data3: [], //数据4
    //     data4: [], //数据5
    //     category_id1: "",  //子导航id1
    //     category_id2: "", 
    //     category_id3: "",
    //     category_id4: "",
    //     title1: "", //子导航标题1
    //     title2: "",
    //     title3: "",
    //     title4: "",
    //     cid: "" //该导航的id
    // },
])
const jobData = ref([])
const jobHunting = ref([])

//4.1 获取所有导航
try {
    const navigateData = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'placeid': 1,
            'pid': routeId,
            'num': 8,
            'type': 1
        },
    });
    // console.log('获取三级导航1111111', navigateData);

    if (navigateData.code == 200) {
        // 遍历可用的导航池放到页面中
        for (let index in navigateData.data) {
            let data = {
                title: navigateData.data[index].name,
                cid: navigateData.data[index].category_id,
                children_count: navigateData.data[index].children_count,
                alias: navigateData.data[index].alias,
                aLIas_pinyin: targetSegment1 + "/" + targetSegment + "/" + navigateData.data[index].aLIas_pinyin,
                type: navigateData.data[index].type,
                data: [],
                data1: [],
                data2: [],
                data3: [],
                data4: [],
                category_id1: "",
                category_id2: "",
                category_id3: "",
                category_id4: "",
                title1: "",
                title2: "",
                title3: "",
                title4: ""
            };
            if (navigateData.data[index].is_url == 1) {
                // 处理 URL 的逻辑
            } else {
                if (navigateData.data[index].type == 4) {
                    jobData.value.push(data);
                }
                if (navigateData.data[index].type == 5) {
                    jobHunting.value.push(data);
                }
                //每个页面最多8个模块
                pageData.value.push(data);
            }
        }
        // console.log('获取三级导航pageData', pageData.value);
        // console.log('获取三级导航jobData', jobData.value);
        // console.log('获取三级导航jobHunting', jobHunting.value);

        //导航池加载完毕，开始申请模块数据
        let getJson = []
        for (let i = 0; i < jobData.value.length; i++) {
            if (i == 0) {
                getJson.push({ "id": jobData.value[0].cid + ",4,3" })
            } else if (i == 1) {
                getJson.push({ "id": jobData.value[1].cid + ",4,3" })
            } else if (i == 2) {
                getJson.push({ "id": jobData.value[2].cid + ",4,6" })
            } else if (i == 3) {
                getJson.push({ "id": jobData.value[3].cid + ",4,3" })
            } else if (i == 4) {
                getJson.push({ "id": jobData.value[4].cid + ",4,3" })
            } else if (i == 5) {
                getJson.push({ "id": jobData.value[5].cid + ",4,6" })
            } else if (i == 6) {
                getJson.push({ "id": jobData.value[6].cid + ",4,3" })
            }
        }
        for (let i = 0; i < jobHunting.value.length; i++) {
            if (i == 0) {
                getJson.push({ "id": jobHunting.value[0].cid + ",5,3" })
            }
        }
        if (jobData.value.length > 0) {
            let jsonString = JSON.stringify(getJson);
            console.log("jsonString", jsonString);
            getPageAllData(jsonString);
        }


    } else {
        console.log("错误：渲染8个模块环节出错，请检查是否存在没有数据的模块！")
    }
} catch (error) {
    console.log("错误：导航池渲染执行接口出错！请检查频道页渲染的模块数据是否完整！")
}

async function getPageAllData(jsonString) {
    const mkdata = await requestDataPromise('/web/getWebsiteCategoryJob', {
        method: 'GET',
        query: {
            'id': jsonString
        },
    });
    // console.log('获取模块数据', mkdata);

    if (mkdata.code == 200) {
        //模块1
        jobData.value[0].data = mkdata.data[0]
        //模块2
        jobData.value[1].data = mkdata.data[1]
        //模块3
        jobData.value[2].data = mkdata.data[2]
        //模块4
        jobData.value[3].data = mkdata.data[3]
        //模块5
        jobData.value[4].data = mkdata.data[4]
        //模块6
        jobData.value[5].data = mkdata.data[5]
        //模块7
        jobData.value[6].data = mkdata.data[6]
        //模块8
        jobHunting.value[0].data = mkdata.data[7]
    } else {
        ElMessage.error(mkdata.message)
    }
}
//4.页面数据 end ---------------------------------------->

//5.设置seo信息 start---------------------------------------->
const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
    method: 'GET',
    query: {
        'catid': routeId
    },
});

if (setData.code == 200) {
    let seoTitle = setData.data.seo_title;
    let seoDescription = setData.data.seo_description;
    let seoKeywords = setData.data.seo_keywords;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" + seoSuffix,
        meta: [
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
} else {
    console.log("设置频道页SEO出错！", setData.message)
}
//5.设置seo信息 end---------------------------------------->
</script>


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