<script setup name="reportEnDetail">
import {ref} from 'vue'
import { useRoute, useRouter } from "vue-router";
import apiReportEn from '@/api/reportEn'
import { showToast,showDialog } from 'vant';
import {enReportManageBtn,useAuthBtn} from '@/hooks/useAuthBtn'
const {checkAuthBtn} = useAuthBtn()

const route=useRoute()
const router=useRouter()

// 获取报告详情
let reportInfo=ref(null)
async function getReportDetail(){
    if(route.query.id==-1){
        //编辑时预览来的
        const data=JSON.parse(sessionStorage.getItem('reportEnPreData'))
        reportInfo.value={
            Title:data.Title,
            Author:data.Author,
            PublishTime:data.CreateTime,
            Abstract:data.Abstract,
            Overview:data.Overview,
            Content:data.Content
        }
        return
    }
    const res=await apiReportEn.getReportDetail({ReportId:Number(route.query.id)})
    if(res.Ret===200){
        reportInfo.value=res.Data
        document.title=res.Data.Title
    }
}
getReportDetail()

//去编辑
async function goEdit(){
    // 先mark一下
    const markRes=await apiReportEn.reportMark({
        Status:1,
        ReportId:reportInfo.value.Id
    })
    if(markRes.Ret===200){
        if(markRes.Data.Status===1){
            showToast(markRes.Data.Msg || '该研报正在编辑，不可重复编辑')
            return
        }
    }else{
        showToast(markRes.ErrMsg || '未知错误，请稍后重试')
        return
    }

    router.push({
        path:'/reportEn/edit',
        query:{
            id:reportInfo.value.Id
        }
    })
}

</script>

<template>
    <div class="report-detail-page" v-if="reportInfo">
        <div class="top-stage-box" v-if="route.query.id>0">
            <span class="stage">第{{reportInfo.Stage}}期 / {{reportInfo.Frequency}}</span>
            <img v-if="reportInfo.State==1&&checkAuthBtn(enReportManageBtn.enReport_reportEdit)" class="edit-icon" src="@/assets/imgs/report/icon_edit2.png" alt="" @click="goEdit">
        </div>
        <h1 class="report-title">{{reportInfo.Title}}</h1>
        <div class="auth-box">
            <span>{{reportInfo.Author}}</span>
            <span>{{reportInfo.PublishTime}}</span>
        </div>
        <div class="report-abstract">Abstract：{{reportInfo.Abstract}}</div>
        <div class="overview-box" v-html="'Overview：'+reportInfo.Overview"></div>
        
        <div class="report-html-wrap" v-html="reportInfo.Content"></div>
    </div>
</template>

<style lang="scss" scoped>
.report-detail-page{
    padding: 30px 34px;
    .report-title{
        margin: 30px 0;
        font-weight: 600;
        font-size: 42px;
        line-height: 56px;
    }
    .auth-box{
        font-size: $font-grey;
        font-size: 36px;
        padding-bottom: 40px;
        border-bottom: 1px solid $border-color;
        margin-bottom: 20px;
        span{
            display: block;
            margin-bottom: 20px;
        }
    }
    .report-abstract{
        font-size: 34px;
        line-height: 54px;
        font-weight: bold;
        &::before{
            content: '';
            display: inline-block;
            position: relative;
            top: 8px;
            margin-right: 10px;
            width: 6px;
            height: 40px;
            background-color: $theme-color;
        }
    }
    .overview-box{
        margin-top: 20px;
        margin-bottom: 40px;
        background: #F2F3FF;
        border-radius: 24px;
        padding: 30px 20px;
        line-height: 1.8;
        font-size: 34px;
    }
}
.top-stage-box{
    .stage{
        display: inline-block;
        background-color: #F2F3FF;
        border-radius: 8px;
        height: 72px;
        line-height: 72px;
        padding: 0 20px;
        font-size: 28px;
    }
    .edit-icon{
        float: right;
        width: 70px;
        height: 70px;
    }
}

@media screen and (min-width:$media-width){
    .report-detail-page{
        max-width: 800px;
        margin: 0 auto;
        padding: 30px;
        .report-title{
            margin: 15px 0;
            font-size: 21px;
            line-height: 28px;
        }
        .auth-box{
            font-size: 18px;
            padding-bottom: 20px;
            margin-bottom: 20px;
            span{
                margin-bottom: 10px;
            }
        }
        .report-abstract{
            font-size: 17px;
            line-height: 27px;
            &::before{
                margin-right: 5px;
                width: 3px;
                height: 20px;
                top: 4px;
            }
        }
        .overview-box{
            margin-top: 10px;
            margin-bottom: 20px;
            border-radius: 12px;
            padding: 15px 10px;
            font-size: 17px;
        }
    }
    .top-stage-box{
        .stage{
            border-radius: 4px;
            height: 36px;
            line-height: 36px;
            padding: 0 10px;
            font-size: 14px;
        }
        .edit-icon{
            width: 35px;
            height: 35px;
        }
    }
}
</style>