<template>
    <!-- 新闻头条部分 -->
    <div class="topNewsPart">
        <div class="inner">
            <div class="toutiao">
                <div class="xwtt">
                    <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'" v-for="(item, index) in headlinelist" :key="index">
                        <h1 class="tttitle">{{ item.title }}</h1>
                    </NuxtLink>
                </div>
                <ul class="toutiao1">
                    <li class="toutiaolist" v-for="item in headlinelist1">
                        <NuxtLink :to="{path:`/${item.pinyin}/${item.id}.html`}" :title="item.title">{{item.title}}</NuxtLink>
                    </li>
                </ul>
            </div>
            <div class="messageLeft">
                <div class="lunbo">
                    <HomeBigSwiper></HomeBigSwiper>
                </div>
                <div class="messageleft_photo_text">
                    <div class="messageleft_photo" v-for="item in moveBannerList" :key="index">
                        <NuxtLink :to="`/${item.pinyin}/${item.id}.html`" :title="item.title">
                            <img :src="item.imgurl">
                            <div class="message_text">
                                {{item.title}}
                            </div>
                        </NuxtLink>
                    </div>
                </div>
            </div>
            <div class="messageRight">
                <div class="messageRight_title">
                    要闻
                </div>
                <ul class="messageRight_content">  
                    <li v-for="item in hotNewsList_data1" :key="index" class="messageRight_content_title">
                        <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'">
                            {{ item.title }}
                        </NuxtLink>
                    </li>
                </ul>
                <ul class="messageRight_content">
                    <li v-for="item in hotNewsList_data2" :key="index" class="messageRight_content_title">
                        <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'">
                            {{ item.title }}
                        </NuxtLink>
                    </li>
                </ul>
                <ul class="messageRight_content">
                    <li v-for="item in hotNewsList_data3" :key="index" class="messageRight_content_title">
                        <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'">
                            {{ item.title }}
                        </NuxtLink>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script setup>
//0.加载必备依赖 start ---------------------------------------->
import { NuxtLink } from "#components";
import { ref, onMounted } from "vue"
const nuxtApp = useNuxtApp();
const axios = nuxtApp.$axios;

const getLinkPathDetail = (item) => {
    if (item.islink == 1) {
        return `${item.linkurl}`;
    } else {
        return `/${item.pinyin}/${item.id}.html`;
    }
}
//0.加载必备依赖 end ---------------------------------------->

//1.获得板块数据 start ---------------------------------------->
//大标题
const headlinelist = ref([])
//大标题下面的二级内容
const headlinelist1 = ref([])

async function getModelData1() {
    const mkdata =  await requestDataPromise('/web/getWebsiteArticlett', {
        method: 'GET',
        query: {
            'pageSize': 4,
            'level': 1,
            'placeid': 0,
            'id':''
        },
    });
    if(mkdata.code == 200){
        //填充大标题
        headlinelist.value.push(mkdata.data[0])
        //剩余的两条放到大标题下面
        headlinelist1.value.push(mkdata.data[1])
        headlinelist1.value.push(mkdata.data[2])
        headlinelist1.value.push(mkdata.data[3])
    }else{
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
        console.log("错误位置：设置大标题")
        console.log("后端错误反馈：",mkdata.message)
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    }
}
getModelData1()

const moveBannerList = ref([])
async function getModelData2() {
    const mkdata =  await requestDataPromise('/web/getWebsiteArticlett', {
        method: 'GET',
        query: {
            'pageSize': 2,
            'level': 2,
            'placeid': 6,
            'id':''
        },
    });
    if(mkdata.code == 200){
        moveBannerList.value = mkdata.data;
    }else{
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
        console.log("错误位置：获取首页轮播图下面的图文")
        console.log("后端错误反馈：",mkdata.message)
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    }
}
getModelData2()

const hotNewsList_data1 = ref([])
const hotNewsList_data2 = ref([])
const hotNewsList_data3 = ref([])
async function getModelData3() {
    const mkdata =  await requestDataPromise('/web/getWebsiteArticlett', {
        method: 'GET',
        query: {
            'pageSize': 8,
            'level': 6,
            'placeid': 0,
            'id':''
        },
    });
    if(mkdata.code == 200){
        for(let i = 0; i < mkdata.data.length; i++){
            if(i >= 0 && i <= 4){
                hotNewsList_data1.value.push(mkdata.data[i])
            } else if(i >= 5 && i <= 9){
                hotNewsList_data2.value.push(mkdata.data[i])
            } else if(i >= 10 && i <= 14){
                hotNewsList_data3.value.push(mkdata.data[i])
            }
        }
    }else{
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
        console.log("错误位置：获取首页今日热点")
        console.log("后端错误反馈：",mkdata.message)
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    }
}
getModelData3()
//1.获得板块数据 end ---------------------------------------->
</script>

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