<script setup>
import Comment from '@/components/Comment.vue'
import moment from 'moment'
import {ref,onMounted,nextTick} from 'vue'
import { useRoute } from 'vue-router'
import {useWaterMark} from '@/hooks/waterMark.js'

import {apiGetChapterReportDetail,apiGetReportDetail} from '@/api/activity'
import { useStore } from 'vuex'

const route=useRoute()
const store=useStore()

const waterMarkEl=ref('')//水印盒子

let research_report_type_id=ref(route.query.research_report_type_id)
let info=ref(null)
const getInfo=async ()=>{
    info.value=null
    const res=await apiGetChapterReportDetail({research_report_type_id:Number(research_report_type_id.value)})
    if(res.code===200){
        info.value=res.data

        // 设置水印
        nextTick(()=>{
            useWaterMark(store.state.userInfo.mobile,waterMarkEl)
        })
    }
}
getInfo()

// 获取底部列表
let info2=ref(null)
let botList=ref([])
const getBotList=async ()=>{
    const res=await apiGetReportDetail({research_report_id:Number(route.query.research_report_id)})
    if(res.code===200){
        botList.value=res.data.research_report_type_list
        info2.value=res.data.research_report_info
    }
}
getBotList()



let preViewImgs=ref([])
let preViewImgIndex=ref(0)
let showPreViewImg=ref(false)

onMounted(()=>{
    $(document).on('click', '.content-wrap img',function(event) {
	    let imgArray = [];
	    let curImageSrc = $(this).attr('src');
		let oParent = $(this).parent();
		if (curImageSrc && !oParent.attr('href')) {
            if(preViewImgs.value.length===0){
                $('.content-wrap img').each(function(index, el) {
                    let itemSrc = $(this).attr('src');
                    imgArray.push(itemSrc);
                });
                preViewImgs.value=imgArray
            }
            preViewImgIndex.value=preViewImgs.value.indexOf(curImageSrc)||0
            showPreViewImg.value=true
	    }
    })
})

// 免责声明
let showDisclaimers=ref(false)

//点击切换章节
const chapterTypeChange=(item)=>{
    research_report_type_id.value=item.ResearchReportTypeId
    info.value=null
    preViewImgs.value=[]
    preViewImgIndex.value=0
    getInfo()
}
</script>


<template>
    <div class="report-detail-page" v-if="info">
        <!-- 章节详情 -->
        <div class="other-type-wrap">
            <div class="section top-box">
                <span class="title">【第{{info2.periods}}期 | {{info2.type=='week'?'周报':'晨报'}} | {{info.research_report_type_info.report_chapter_type_name}}】{{info.research_report_type_info.research_report_type_title}}</span>
                <!-- <div class="flag-box" style="margin:14px 0">
                    <img style="width:18px;vertical-align: middle;display: inline-block;" :src="info.research_report_type_info.banner_url" alt="">
                    <span style="vertical-align: middle;margin:0 13px 0 6px;display: inline-block;">{{info.research_report_type_info.report_chapter_type_name}}</span>
                    <span style="vertical-align: middle;color:#999999;display: inline-block;">弘则研究</span>
                </div> -->
                <div class="flex author">
                    <span>FICC团队</span>
                    <span class="time">{{moment(info2.researchReportDate).format('YYYY-MM-DD HH:mm:ss')}}</span>
                </div>
                <div class="tips">
                    <span>注：请务必阅读</span>
                    <span style="color:#F3A52F;margin-left:20px;cursor: pointer;" @click="showDisclaimers=true">免责声明</span>
                </div>
            </div>
            <div class="no-select-text section content-wrap" ref="waterMarkEl">
                <div class="item" v-for="item in info.research_report_type_content_list" :key="item.sort">
                    <h2 class="content-title">{{item.content_type?item.content_type:'核心观点'}}</h2>
                    <div v-html="item.content" class="content-text" @click="clickContent"></div>
                </div>
            </div>
            <!-- 种类快捷切换 -->
            <div class="section classify-list">
                <div class="top-name">更多</div>
                <ul class="flex list">
                    <li 
                        :class="['item',item.ResearchReportTypeId==research_report_type_id&&'active']" 
                        v-for="item in botList" 
                        :key="item.ResearchReportTypeId"
                        @click="chapterTypeChange(item)"
                    >
                        <img :src="item.BannerUrl" alt="">
                        <span>{{item.ReportChapterTypeName}}</span>
                    </li>
                </ul>
            </div>

            <!-- 评论点赞模块 -->
            <Comment
                :data="{
                    report_id:0,
                    report_chapter_id:0,
                    old_report_id:info.research_report_type_info.research_report_id,
                    old_report_chapter_id:info.research_report_type_info.research_report_type_id,
                    like_enabled:info.like_enabled,
                    like_num:info.like_num
                }"
            />
        </div>
        
    </div>

    <!-- 图片预览 -->
    <el-image-viewer
        v-if="showPreViewImg"
        :initial-index="preViewImgIndex"
        @close="showPreViewImg=false"
        :url-list="preViewImgs"
    />

    <!-- 免责申明 -->
    <el-dialog v-model="showDisclaimers" title="免责声明" center draggable width="40%">
        <div class="disclaimers-box">
            <div style="margin-bottom:10px">1、本报告仅供弘则弥道（上海）投资咨询有限公司正式签约的机构客户使用，不会因接收人/接收机构收到本报告而将其视为客户。</div>
            <div style="margin-bottom:10px">2、本报告根据国际和行业通行的准则，以合法渠道获得这些信息，尽可能保证可靠、准确和完整，但并不保证报告所述信息的准确性和完整性，也不保证本报告所包含的信息或建议在本报告发出后不会发生任何变更。本报告中所提供的信息仅供参考。</div>
            <div style="margin-bottom:10px">3、报告中的内容不对投资者做出的最终操作建议做任何的担保，也没有任何形式的分享投资收益或者分担投资损失的书面或口头承诺。不作为客户在投资、法律、会计或税务等方面的最终操作建议，也不作为道义的、责任的和法律的依据或者凭证，无论是否已经明示或者暗示。</div>
            <div style="margin-bottom:10px">4、在任何情况下，本公司不对客户/接收人/接收机构因使用报告中内容所引致的一切损失负责任，客户/接收人/接收机构需自行承担全部风险。</div>
        </div>
    </el-dialog>
</template>

<style lang="scss" scoped>
.report-detail-page{
    .section{
        padding: 20px;
    }
}
.other-type-wrap{
    .top-box{
        .title{
            font-size: 24px;
            font-weight: bold;
            margin-left: -13px;
        }
        .author{
            margin-top: 20px;
            color: #666;
            justify-content: space-between;
        }
        .tips{
            margin-top: 20px;
            font-size: 18px;
            &::before{
                content: '';
                width: 6px;
                height: 28px;
                display: inline-block;
                background-color: #F3A52F;
                margin-right: 10px;
                position: relative;
                top: 8px;
            }
        }
        .sub-title{
            margin-top: 30px;
            font-size: 18px;
                &::before{
                    content: '';
                    display: inline-block;
                    width: 6px;
                    height: 28px;
                    background: #F3A52F;
                    margin-right: 6px;
                    position: relative;
                    top: 8px;
                }
            
        }
    }
    .content-wrap{
        .item{
            .content-title{
                font-size: 20px;
                color: #000;
                &::before{
                    content: '';
                    display: inline-block;
                    margin-right: 5px;
                    position: relative;
                    top: 7px;
                    width: 6px;
                    height: 28px;
                    background: #F3A52F;
                }
            }
            .content-text{
                font-size: 18px;
                line-height: 1.8;
                :deep(img){
                    max-width: 100%;
                    margin-left: auto;
                    margin-right: auto;
                    display: block;
                }
            }
        }

    }
}
.classify-list{
    .top-name{
            text-align: center;
            color: #F3A52F;
            font-size: 18px;
            margin-bottom: 50px;
            &::before,&::after{
                content: '';
                display: inline-block;
                width: 83px;
                height: 1px;
                background-color: #F3A52F;
                vertical-align: middle;
                margin: 0 22px;
            }
    }
    .list{
        margin-top: 20px;
        flex-wrap: wrap;
        .item{
            display: flex;
            justify-content: center;
            align-items: center;
            width: 148px;
            height: 36px;
            background-color: #F7F7F7;
            border-radius: 4px;
            margin-right: 20px;
            margin-bottom: 20px;
            cursor: pointer;
            cursor: pointer;
            img{
                width: 20px;
                height: 20px;
                vertical-align: middle;
            }
            span{
                vertical-align: middle;
                margin-left: 6px;
                font-size: 16px;
            }
        }
        .active{
            border:1px solid #F3A52F;
        }
    }
}
.disclaimers-box{
    max-height: 60vh;
    overflow: auto;
}
</style>