<template>
    <!-- 滑块 -->
     <!-- v-if="navigation1[2]" -->
    <div class="slider" v-if="navigation1[2]">
        <!-- 标题部分 -->
        <div class="scienceTitle" v-if="navigation1[2]">
            <h5 v-if="navigation1[2].category_id">
                <NuxtLink
                    :to="{ path: `/newsList/${navigation1[2].category_id}`}"
                    target="_blank" v-if="navigation1[2].category_id&&message.children_count!=0" class="active">
                    {{navigation1[2].alias}}
                </NuxtLink>
                <NuxtLink
                    :to="{ path: `/primaryNavigation/${navigation1[2].category_id}`}"
                    target="_blank" v-else-if="navigation1[2].category_id&&message.children_count==0" class="active">
                    {{navigation1[2].alias}}
                </NuxtLink>
            </h5>
            <NuxtLink :to="`/newsList/${navigation1[2].category_id}`" target="_blank">
                查看更多
            </NuxtLink>
            <!-- <span>查看更多</span> -->
            <!-- <p class="title">
                <span v-for="(item, index) in scienceTitleList" :key="index" @mousemove="changeUl(index)">
                    <a href="#">{{ item.title }}</a>
                </span>
            </p> -->
        </div>
        <!-- 标题下内容列表 -->
        <div class="box">
            <div class="boxcontent">
                <div class="boxleft" v-if="boxData1[0]">
                    <div class="boxBigImg">
                        <NuxtLink :to="`/newsDetail/${boxData1[0].id}`" target="_blank" class="imgbg">
                            <img :src="boxData1[0].imgurl">
                            <div>
                                <p><span>专题</span>{{ boxData1[0].title }}</p>
                                <span>{{ getDays(boxData1[0].created_at) }}</span>
                            </div>
                        </NuxtLink>
                    </div>
                    <div class="boxMainImg">
                        <NuxtLink :to="`/newsDetail/${boxData1[1].id}`" target="_blank" class="imgbg">
                            <img :src="boxData1[1].imgurl">
                            <div>
                                <p>{{ boxData1[1].title }}</p>
                                <span>{{ getDays(boxData1[1].created_at) }}</span>
                            </div>
                        </NuxtLink>
                        <NuxtLink :to="`/newsDetail/${boxData1[2].id}`" target="_blank" class="imgbg">
                            <img :src="boxData1[2].imgurl">
                            <div>
                                <p>{{ boxData1[2].title }}</p>
                                <span>{{ getDays(boxData1[2].created_at) }}</span>
                            </div>
                        </NuxtLink>
                    </div>
                    <div class="boxBigImg">
                        <NuxtLink :to="`/newsDetail/${boxData1[3].id}`" target="_blank" class="imgbg">
                            <img :src="boxData1[3].imgurl">
                            <div>
                                <p>{{ boxData1[3].title }}</p>
                                <span>{{ getDays(boxData1[3].created_at) }}</span>
                            </div>
                        </NuxtLink>
                    </div>
                </div>
                <div class="boxright">
                   <ul>
                        <li v-for="item in boxData2">
                            <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">
                                <p class="title">{{ item.title }}</p>
                                <p class="time">{{ getDays(item.created_at) }}</p>
                            </NuxtLink> 
                        </li>
                   </ul>
                </div>
            </div>
            <!-- <ul class="scienceList">
                <li v-for="item in boxData2">
                    <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">
                        <img :src="item.imgurl">
                        <p>{{ item.title }}</p>
                    </NuxtLink>
                </li>
            </ul> -->

            <!-- <transition name="fade">
                <div class="scienceListBox">
                    <ul class="scienceList">
                        <li v-for="item in boxData1">
                            <NuxtLink
                                :to="{ path: `/newsDetail/${item.id}`, query: { listId: routeId, listName: routeName } }"
                                target="_blank">
                                <img :src="item.imgurl">
                                <p>{{ item.title }}</p>
                            </NuxtLink>

                        </li>
                    </ul>
                    <ul class="scienceList">
                        <li v-for="item in 6">
                            <img src="../../static/images/sgbhsihfgisdfaasda45632113_A_Chinese_farmer_carrying_a_hoe_is_h_1ba32eee-c498-4dd7-9cd9-013568c09db7.png"
                                alt="">
                            <p>市农业农村局关于印发连云港市市级…</p>
                        </li>
                    </ul>
                    <ul class="scienceList">
                        <li v-for="item in 6">
                            <img src="../../static/images/rgmezdvz_19982_On_a_vast_and_boundless_wheat_field_many_harvest_5b5cfeda-ef17-4551-a935-5f8e3f799b69.png"
                                alt="">
                            <p>市农业农村局关于印发连云港市市级…</p>
                        </li>
                    </ul>
                    <ul class="scienceList">
                        <li v-for="item in 6">
                            <img src="../../static/images/rgmezdvz_19982_A_Chinese_farmer_carrying_a_hoe_is_hoeing_the_fi_a036c7b3-b05e-4d3d-a371-0bed91ec1ff8(1).png"
                                alt="">
                            <p>市农业农村局关于印发连云港市市级…</p>
                        </li>
                    </ul>
                </div>
            </transition> -->
        </div>
    </div>

</template>

<script setup>

const nuxtApp = useNuxtApp();
const axios = nuxtApp.$axios;

const radio1 = ref('1')

const props = defineProps({
    message: Array,
});


//获取导航一的栏目
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;
        getWebsiteModelArticles()
        getWebsiteModelArticles2()
    } catch (error) {
        console.error(error);
    }
}

const boxData1 = ref("");
const getWebsiteModelArticles = async () => {
    try {
        // console.log(99999999);
        // console.log(navigation1.value[2].category_id)
        let cid = navigation1.value[2].category_id
        const response = await axios.get(`/web/getWebsiteModelArticles?catid=${cid}&level=${1}&pagesize=${4}`);
        boxData1.value = response.data;
    } catch (error) {
        console.error(error);
    }
}

const boxData2 = ref("");
const getWebsiteModelArticles2 = async () => {
    try {
        // console.log(99999999);
        // console.log(navigation1.value[2].category_id)
        let cid = navigation1.value[2].category_id
        const response = await axios.get(`/web/getWebsiteModelArticles?catid=${cid}&level=${3}&pagesize=${6}`);
        boxData2.value = response.data;
    } catch (error) {
        console.error(error);
    }
}

function getTime(time) {
    const date = new Date(time);
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    return `${year}-${month}-${day}`;
}

onMounted(() => {
    // 一级导航
    navigateList()

})


let scienceTitleList = [
    {
        id: 1,
        title: "农产畅销"
    },
    {
        id: 2,
        title: "农业在线"
    },
    {
        id: 3,
        title: "农产行情"
    },
    {
        id: 4,
        title: "名优特产"
    }
]


//鼠标移入标题时,下方内容会发生变化
// let changeUl = (index) => {
//     // console.log(index);
//     if (process.browser) {
//         let scienceListBox = document.querySelector('.scienceListBox');
//         let titleList = document.querySelectorAll('.title>span>a')
//         for (let i = 0; i < titleList.length; i++) {
//             titleList[i].className = ''
//         }
//         titleList[index].setAttribute('class', 'current')
//         if (index == 0) {
//             scienceListBox.style.left = 0
//         } else if (index == 1) {
//             scienceListBox.style.left = "-790px"
//         } else if (index == 2) {
//             scienceListBox.style.left = "-1580px"
//         } else if (index == 3) {
//             scienceListBox.style.left = "-2370px"
//         }
//     }
// }
function getDays(time) {
    const date = new Date(time);
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    return `${month}-${day}`;
}

</script>

<style lang="less" scoped>
.slider {
    width: 720px;
}
// 标题
.scienceTitle {
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #D9D9D9;
    display: flex;
    justify-content: space-between;

    h5 {
        float: left;
        width: 96px;
        height: 34px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 24px;
        color: #000000;
        line-height: 28px;
        text-align: left;
        font-style: normal;
        text-transform: none;
        margin-right: 20px;
        // border-bottom: 2px solid #139602;

        height: 50px;
        line-height: 50px;
        a {
            font-size: 22px;
            color: #139602;
            border-bottom: 3px solid #139602;
            height: 50px;
            line-height: 50px;
            display: inline-block;
            box-sizing: border-box;
            width: auto;
            font-weight: bold;
        }
    }

    a {
        width: 65px;
        height: 50px;
        line-height: 50px;
        font-weight: 400;
        font-size: 16px;
        color: #333333;
        font-style: normal;
        text-transform: none;
        display: inline-block;
    }

    >p {
        float: left;
        height: 37px;
        line-height: 30px;

        >span {
            display: inline-block;
            height: 20px;
            line-height: 20px;
            text-align: center;
            margin: 4px 0px 3px;
            padding: 0 20px;
            border-right: 1px solid #ccc;

            >a {
                display: inline-block;
                padding-bottom: 11px;
                font-family: PingFang SC, PingFang SC;
                font-weight: 500;
                font-size: 20px;
                color: #666666;
                line-height: 20px;
                font-style: normal;
                text-transform: none;
                box-sizing: border-box;
            }

            .current {
                color: #139602;
                border-bottom: 1px solid #139602;
            }
        }

        >span:nth-child(4) {
            border-right: none;
        }

        >span:hover>a {
            color: #139602;
            border-bottom: 1px solid #139602;

        }
    }
}
.box {
    width: 720px;
    height: 700px;
    position: relative;
    overflow: hidden;
    .boxcontent {
        display: flex;
        justify-content: space-between;
        padding-top: 30px;
        .boxleft {
            width: 349px;
            height: 700px;
            padding-bottom: 30px;
        }
    }
    .boxMainImg {
        display: flex;
        justify-content: space-between;
        margin-bottom: 15px;
        
        a {
            position: relative;
            img {
                width: 170px;
                height: 115px;
                border-radius: 4px;
                border-radius: 6px;
            }
            div {
                position: absolute;
                bottom: 4px;
                left: 7px;  
                p {
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    word-break: break-all;
                    width: 158px;
                    height: 42px;
                    color: #fff;
                }
                span {
                    display:block;
                    height: 20px;
                    line-height: 20px;
                    text-align: left;
                    color: #fff;
                }
            }
        }
    }
    .boxBigImg {
        margin-bottom: 15px;
        
        a {
            position: relative;
            img {
                width: 349px;
                height: 236px;
                border-radius: 6px;
            }
            div {
                position: absolute;
                bottom: 7px;
                left: 20px;  
                z-index: 99;
                p{
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    word-break: break-all;
                    width: 320px;
                    height: 42px;
                    color: #fff;
                    font-size: 16px;
                    margin-bottom: 5px;
                    span {
                        display: inline-block;
                        background: #9CD26B;
                        font-size: 14px;
                        color: #fff;
                        padding: 0 6px;
                        border-radius: 4px;
                        margin-right: 5px;
                    }
                }
                span {
                    display:block;
                    height: 20px;
                    line-height: 20px;
                    text-align: left;
                    color: #fff;
                }
            }
        }
    }
}

.fade-in {
    animation: fadeIn 1s ease-in-out;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}

.fade-enter-to,
.fade-leave-from {
    opacity: 1;
}

.fade-enter-active,
.fade-leave-active {
    transition: opacity 1s ease;
}

.scienceListBox {
    width: 3160px;
    height: 570px;
    position: absolute;
    top: 0;
    left: 0;
    transition: all 3s linear 0;
    z-index: 99;
}

// 标题下列表
.scienceList {
    width: 790px;
    height: 570px;
    float: left;
    margin-top: 17px;

    >li {
        width: 250px;
        height: 276px;
        float: left;
        margin-right: 20px;
        position: relative;

        img {
            width: 250px;
            height: 220px;
            border-radius: 40px 4px 40px 4px;
        }

        p {
            width: 254px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            text-overflow: ellipsis;
            word-break: break-all;
            height: 48px;
            overflow: hidden;
            font-family: PingFang SC, PingFang SC;
            font-weight: 600;
            font-size: 18px;
            color: #333333;
            line-height: 24px;
            text-align: left;
            font-style: normal;
            text-transform: none;

        }

        p:hover {
            color: #139602;
        }
    }

    >li:nth-child(3),
    >li:nth-child(6) {
        margin-right: 0;
    }

    >li::before {
        content: "";
        display: inline-block;
        width: 40px;
        height: 20px;
        position: absolute;
        z-index: 99;
        top: 0;
        right: 0;
        background-image: url("../../static/images/Component 209.png");
    }
}

.boxright {
    ul {
        li {
            width: 349px;
            
            box-sizing: border-box;
            border-bottom: 1px solid #E6E6E6;
            margin-bottom: 20px;
            padding-bottom: 10px;
            .title {
                height: 42px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                overflow: hidden;
                text-overflow: ellipsis;
                word-break: break-all;
                height: 42px;
                width: 100%;
                font-size: 16px;
                color: #333333;
                margin-bottom: 5px;
            }
            .title:hover {
                color: #49A769;
            }
            .time {
                font-size: 14px;
                color: #999999;
                margin-bottom: 10px;
            }
           
            
        }
    }
}

.imgbg::after{
    content: '';
    display: block;
    width:100%;
    height:68px;
    z-index:44;
    left:0px;
    bottom:4px;
    position:absolute;
    background:linear-gradient(to bottom,rgba(0,0,0,0),black);
    opacity:.3;
    border-radius: 6px;
}
</style>