<template>
    <!-- 页面头部 -->
    <HomePageHead></HomePageHead>
    <!-- 页面导航 -->
    <HomePageNavigation></HomePageNavigation>
    <!-- 广告1 -->
    <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>

    <!-- 面包屑导航 -->
    <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>
                    <NuxtLink :to="{ path: `/newsList/${routLevelId}` }">
                        {{ routLevelTitle }}
                    </NuxtLink>
                </el-breadcrumb-item>
                <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
    </div>

    <!-- 资讯列表 -->
    <div class="newsDetail">
        <div class="inner">
            <div class="innerLeft">
                <div class="LeftTop">
                    <h1>{{ newsDetail.title }}</h1>
                    <p>
                        来源: <span>{{ newsDetail.copyfrom }}</span>
                        作者: <span>{{ newsDetail.author }}</span>
                        发布时间: <span>{{ time }}</span>
                    </p>
                </div>
                <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
                </div>
                <div v-if="previewVisible" class="preview-modal" @click="closePreview">
                    <img :src="selectedImage" alt="Preview">
                </div>

                <!-- 免责声明: -->
                <div class="disclaimer" v-if="newsDetail.fromurl">
                    <p>原文链接：{{ newsDetail.fromurl }}</p>
                    <p>[免责声明]本文来源于网络转载，仅供学习交流使用，不构成商业目的。 版权归原作者所有，如涉及作品内容，版权和其他问题，请在30日与本网联系，我们将第一时间处理。</p>
                </div>
            </div>
            <div class="innerRight">
                <!-- 热点资讯1 -->
                <div class="hotList1">
                    <DetailHotNews></DetailHotNews>
                </div>
                <!-- 热点资讯2 -->
                <div class="hotList2">
                    <DetailHotNews2></DetailHotNews2>
                </div>
            </div>
        </div>
    </div>

    <!-- 页面底部 -->
    <HomeFoot></HomeFoot>
</template>

<script setup>
//1.页面依赖 start ---------------------------------------->
import { onMounted } from 'vue'
import { ElBreadcrumb, ElBreadcrumbItem} from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'


//获得跳转过来的id
const route = useRoute();
const articleId = route.params.id; //获得该页面的id
//1.页面依赖 end ---------------------------------------->

//2.页面数据 start ---------------------------------------->
//2.1 资讯详情
const newsDetail = ref({})
const routeNewsTtitle = ref("");
//2.2 发布日期
const time = ref("");
//2.3 路径
const routLevelTitle = ref("");
const routLevelId = ref("");
//是否展示投票
const articleChoice = ref(false);
//2.4获取详情
async function getPageData() {
    const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
        method: 'GET',
        query: {
            'articleid': articleId
        },
    });
    if (mkdata.code == 200) {
        //判断是否显示投票
        if (mkdata.data.is_survey == 1) {
            console.log("本篇文章含有投票！")
            articleChoice.value = true;
            getVoteList();
        }
        //获取内容
        newsDetail.value = mkdata.data;
        //获取路径
        routLevelTitle.value = newsDetail.value.cat_name;
        routLevelId.value = newsDetail.value.category_id;
        //获取发布时间
        time.value = newsDetail.value.updated_at.split(' ')[0];
        //修正标题长度
        if (newsDetail.value.title.length >= 30) {
            routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
        } else {
            routeNewsTtitle.value = newsDetail.value.title
        }
    } else {
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
        console.log("错误位置：获取详情内容")
        console.log("后端错误反馈：", mkdata.message)
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    }
}
getPageData();

//2.5 获得广告
//广告列表
let adImg1 = ref([]);
// async function getAdData(){
//     const adData = await requestDataPromise('/web/getWebsiteAdvertisement',{method:'GET',query:{'ad_tag':'DETAIL'}});
//     if(adData.code==200){
//         for(let item of adData.data){
//             if(item.ad_tag == 'DETAIL_0001'){
//                 adImg1.value = item;
//             }
//         }
//     }else{
//         console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
//         console.log("错误位置：获取详情页广告列表")
//         console.log("后端错误反馈：",adData.message)
//         console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
//     }
// }
// getAdData();

onMounted(async () => {
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_detail_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];
})

//2.页面数据 end ---------------------------------------->

//3.设置seo信息 start---------------------------------------->
//3.1 设置seo信息
const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
    method: 'GET',
    query: {
        'articleid': articleId
    },
});
if (setData.code == 200) {
    let seoTitle = setData.data.title;
    let seoDescription = setData.data.introduce;
    let seoKeywords = setData.data.keyword;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" + seoName + "_" + seoSuffix,
        meta: [
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
} else {
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    console.log("错误位置：设置详情页面SEO数据")
    console.log("后端错误反馈：", setData.message)
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
}
//3.设置seo信息 end---------------------------------------->
//5.页面图片放大 start---------------------------------------->
const previewVisible = ref(false)
const selectedImage = ref(' ')

const openPreview = (event) => {
    if (event.target.tagName === 'IMG') {
        selectedImage.value = event.target.src;
        previewVisible.value = true;
    }
}
const closePreview = () => {
    previewVisible.value = false;
}
//5.页面图片放大 end---------------------------------------->
</script>

<style lang="less" scoped>
//导航条
.breadcrumb {
    width: 100%;
    height: 22px;
    margin-bottom: 30px;
    margin-top: 40px;
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: 20px;
    color: #666666;
    line-height: 23px;
    text-align: left;
    font-style: normal;
    text-transform: none;

    .el-breadcrumb::v-deep {
        display: inline-block;
        vertical-align: -4px;
    }

    /deep/.el-breadcrumb__inner a,
    /deep/.el-breadcrumb__inner.is-link {
        color: #666666;
        font-weight: 400;
        text-decoration: none;
        transition: var(--el-transition-color);
    }

    span {
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 400;
        font-size: 20px;
        color: #666666;
        line-height: 23px;
        text-align: left;
        font-style: normal;
        text-transform: none;
    }

    span:hover {
        color: #666666;
    }

    .location {
        margin-right: 20px;
        width: 100px;
        height: 22px;
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 400;
        font-size: 20px;
        color: #666666;
        line-height: 23px;
        text-align: left;
        font-style: normal;
        text-transform: none;
    }
}

// 资讯列表
.newsDetail {
    width: 100%;
    //height: 1400px;
    margin-bottom: 70px;

    .inner {
        width: 1200px;
        //height: 1400px;
        overflow: hidden;
        font-size: 16px;

        .innerLeft {
            width: 810px;
            border-top: 1px solid #ccc;
            margin-right: 40px;

            .LeftTop {
                // height: 522px;
                margin-top: 50px;

                >h1 {

                    line-height: 40px;
                    margin-bottom: 30px;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                    font-weight: bold;
                    font-size: 30px;
                    color: #333333;
                }

                >p {
                    height: 18px;
                    line-height: 18px;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                    font-weight: 400;
                    font-size: 14px;
                    color: #999999;

                    span {
                        margin-right: 40px;
                    }
                }

                >img {
                    width: 680px;
                    height: 382px;
                    padding: 50px 0px 60px 55px;
                }
            }

            .leftBottom {
                width: 790px;
                margin-top: 50px;
                font-size: 20px;
                line-height: 38px;
                margin-bottom: 30px;

                ul>li img {
                    width: 790px;
                    height: 382px;
                }

                img {
                    width: 790px;
                    height: 382px;
                }

                p.tinymce-material {
                    img {
                        width: 790px;
                    }
                }

                >h3,
                >p {
                    text-indent: 2em;
                    width: 790px;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                    font-size: 20px;
                    color: #333333;
                    line-height: 38px;
                    padding-bottom: 30px;

                    img {
                        width: 790px;
                    }
                }

                >h3 {
                    font-weight: 600px;
                }

                >p {
                    font-weight: 400;
                }

            }

            .disclaimer {
                width: 790px;
                overflow: hidden;
                border-top: 1px solid #e6e6e6;
                padding: 30px 0px;
                color: #999999;
                font-size: 17px;

                p {
                    width: 790px;
                    line-height: 30px;
                }
            }
        }

        .innerRight {
            width: 350px;
            height: 1248px;
            border-top: 1px solid #ccc;
            border-bottom: 1px solid #ccc;

        }
    }
}

.leftBottom::v-deep p img,
.leftBottom::v-deep img,
.leftBottom::v-deep video {
    max-width: 700px;
}

.leftBottom::v-deep h1,
.leftBottom::v-deep h2,
.leftBottom::v-deep h3,
.leftBottom::v-deep h4,
.leftBottom::v-deep h5,
.leftBottom::v-deep h6 {
    font-size: 20px;
    font-weight: 500;
}

//放大图片
.preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.preview-modal img {
    max-width: 100%;
    max-height: 100%;
    cursor: pointer;
    /* 关闭按钮样式 */
}
</style>