<script setup name="ReportEnList">
import {nextTick, reactive,ref,computed,onMounted} from 'vue'
import apiReportEn from '@/api/reportEn'
import apiReport from '@/api/report'
import {getSystemInfo} from '@/api/common'
import moment from 'moment'
import ListClassify from './components/ListClassify.vue'
import SendEmail from './components/SendEmail.vue';
import EditStrategyReport from './components/EditStrategyReport.vue';
import { showToast,showDialog,Dialog } from 'vant';
import { useRouter } from 'vue-router';
import { useWindowSize } from '@vueuse/core'
import {useCachedViewsStore} from '@/store/modules/cachedViews'
import {usePublicSettingStore} from '@/store/modules/publicSetting'
import {useDownLoadFile} from '@/hooks/useDownLoadFile'
import {enReportManageBtn,useAuthBtn} from '@/hooks/useAuthBtn'
import {useReportApprove} from '@/hooks/useReportApprove'
import {Base64} from 'js-base64'

const cachedViewsStore=useCachedViewsStore()
const publicSettingStore = usePublicSettingStore()

const {startDownload}=useDownLoadFile()
const {checkAuthBtn} = useAuthBtn()
const {isApprove,isOtherApprove,getEtaConfig} = useReportApprove()

const { width, height } = useWindowSize()

const router=useRouter()
// 水印
const waterMarkStr=ref('')
//是否显示一键清空选项
const showCleanFilterBox=computed(()=>{
    if(isClickClose.value) return false
    if(
        listState.ClassifyNameRoot ||
        listState.ClassifyNameFirst||
        listState.ClassifyNameSecond||
        listState.EndDate||
        listState.Frequency||
        listState.MsgIsSend||
        listState.publishStatus
    ) return true
})
const isClickClose=ref(false)//是否点击过关闭一键清空模块
function handleCleanFilter(){
    listState.ClassifyNameRoot=''
    listState.ClassifyNameFirst=''
    listState.ClassifyNameSecond=''
    // 重置分类选择器状态
    classifySelector.value.clearClassifyOptions()

    listState.MsgIsSend=''
    listState.Frequency=''
    listState.StartDate=''
    listState.EndDate=''
    listState.publishStatus=''
    refreshList()
}

// 分类弹窗
const showClassify=ref(false)
const classifySelector=ref(null)

const listState = reactive({
    publishStatus:'',
    MsgIsSend:'',
    Frequency:'',
    ClassifyNameRoot:'',
    ClassifyNameFirst:'',
    ClassifyNameSecond:'',
    StartDate:'',
    EndDate:'',
    list:[],
    page:0,
    pageSize:20,
    finished:false,
    loading:false
})
async function getList(){
    const timeType = ['','publish_time','modify_time','approve_time']
    const res=await apiReportEn.getList({
        CurrentIndex:listState.page,
        PageSize:listState.pageSize,
        StartDate:listState.StartDate,
        EndDate:listState.EndDate,
        ClassifyIdRoot:listState.ClassifyNameRoot.id,
        ClassifyIdFirst:listState.ClassifyNameFirst.id,
        ClassifySecond:listState.ClassifyNameSecond.id,
        Frequency:listState.Frequency,
        EmailState:listState.MsgIsSend,
        TimeType:timeType[dateType.value]||'publish_time',
        State:listState.publishStatus
    })
    if(res.Ret===200){
        listState.loading=false
        if(!res.Data){
            listState.finished=true
            return
        }
        
        listState.finished=res.Data.Paging.IsEnd
        const arr=res.Data.List||[]
        listState.list=[...listState.list,...arr]
    }
}
function onLoad(){
    listState.page++
    getList()
}

function refreshList(){
    listState.page=1
    listState.list=[]
    listState.finished=false
    getList()
}


// 删除报告
function handleReportDel(item){
    showDialog({
        title: '提示',
        message: '删除操作不可恢复，确认删除吗？',
        showCancelButton:true
    }).then(() => {
        // on close
        apiReportEn.reportDel({ReportIds:item.Id}).then(res=>{
            if(res.Ret===200){
                showToast('删除成功')
                refreshList()
                showReportItemOpt.value=false
            }
        })
    }).catch(()=>{})
}

// 发布报告
async function handleReportPublish(item){
    showDialog({
        title: '提示',
        message: item.PrePublishTime?'该报告已设置定时发布，是否修改为立即发布？':`是否确定立即发布报告？`,
        showCancelButton:true
    }).then(()=>{
        apiReportEn.reportPublish({
            ReportIds:item.Id.toString(),
            ReportUrl:generatePdfLinks(item.ReportCode)
        }).then(res=>{
            if(res.Ret===200){
                showToast('发布成功')
                showReportItemOpt.value=false
                refreshList()
            }
        })
    })
    
}

function generatePdfLinks(Code){
    return `${publicSettingStore.publicSetting.ReportViewUrl}/reportshare_pdf_en?code=${Code}&flag=${waterMarkStr.value}`
}

// 取消发布
function handleReportPublishCancle(item){
    showDialog({
        title: '提示',
        message: `是否确认撤销发布？`,
        showCancelButton:true
    }).then(()=>{
        apiReportEn.reportPublishCancle({ReportIds:Number(item.Id)}).then(res=>{
            if(res.Ret===200){
                refreshList()
                showReportItemOpt.value=false
            }
        })
    })
}

// type 1-pdf 2-长图
function downloadPdfImg(item,type){
    showReportItemOpt.value=false
    if(type == 1){
        window.open(item.DetailPdfUrl,"_blank")
    }else{
        startDownload(item.DetailImgUrl,`${item.Title}.jpeg`)
    }
}

//提交报告
function handleReportSubmit(item){
    showDialog({
        title: '提示',
        message: '是否确认提交该报告进入审批流程?',
        showCancelButton:true
    }).then(()=>{
        apiReportEn.reportEnSubmit({
            ReportId:Number(item.Id)
        }).then(res=>{
            if(res.Ret!==200) return 
            showToast('提交成功')
            refreshList()
        })
    }).catch(()=>{})
}
//撤销报告
function handleReportCancle(item){
    showDialog({
        title: '提示',
        message: '确定要撤销审批吗?',
        showCancelButton:true
    }).then(()=>{
        apiReportEn.reportEnCancel({
            ReportId:Number(item.Id)
        }).then(res=>{
            if(res.Ret!==200) return 
            showToast('撤销成功')
            refreshList()
        })
    }).catch(()=>{})
}

// 日期筛选
const calendarMinDate=new Date(2010,0,1)
const showCalendar=ref(false)
const calendarIns=ref(null)
const dateType=ref(1)//1发布时间 2更新时间 3 审批时间
function handleCalendarChange(e){
    listState.StartDate=moment(e[0]).format('YYYY-MM-DD')
    listState.EndDate=moment(e[1]).format('YYYY-MM-DD')
    refreshList()
    showCalendar.value=false
}
function handleResetCalendar(){
    listState.StartDate=''
    listState.EndDate=''
    calendarIns.value.reset()
    refreshList()
    showCalendar.value=false
}

// 分类筛选
function handleConfirmClassify({rootClassify,firstClassify,secondClassify}){
    listState.ClassifyNameRoot=rootClassify
    listState.ClassifyNameFirst=firstClassify
    listState.ClassifyNameSecond=secondClassify
    refreshList()
    showClassify.value=false
}

// 跳转详情
function goDetail(item){
    //若没有预览权限，则不跳转
    if(!checkAuthBtn(enReportManageBtn.enReport_reportView)) return 
    router.push({
        path:"/reportEn/detail",
        query:{
            id:item.Id
        }
    })
}

// 长按弹出操作
let activeItem=ref(null)
const showReportItemOpt=ref(false)
function onLongPressItem(e){
    // 校验是否有人在编辑报告
    if(!e.CanEdit){
        showToast(`${e.Editor}正在编辑中，不可操作！`)
        return
    }
    //检验权限，如果该状态下无可操作项，则长按不弹出
    let checkState = false
    if([1,3].includes(e.State)){ //编辑、发布、删除
        checkState = checkAuthBtn(enReportManageBtn.enReport_reportEdit)
            ||checkAuthBtn(enReportManageBtn.enReport_publish)
            ||checkAuthBtn(enReportManageBtn.enReport_reportDel)
    }
    if([2,6].includes(e.State)){ //群发邮件/群发日志、取消发布
        checkState = checkAuthBtn(enReportManageBtn.enReport_sendEmail)
            ||checkAuthBtn(enReportManageBtn.enReport_cancelPublish)
    }
    if([4,5].includes(e.State)){
        checkState = checkAuthBtn(enReportManageBtn.enReport_cancelPublish)
    }
    if(!checkState) return
    activeItem.value=e
    showReportItemOpt.value=true
}

// 更多操作
const frequencyDropMenuIns=ref(null)
const statusDropMenuIns=ref(null)
const publishStatusDropMenuIns=ref(null)
const showMoreFilter=ref(false)
const temFrequencyVal=ref('')
const temMsgIsSendVal=ref('')
const temPublishStatusVal=ref('')
const frequencyOpt=[
    {
        label:'年度',
        value:'年度'
    },
    {
        label:'半年度',
        value:'半年度'
    },
    {
        label:'季度',
        value:'季度'
    },
    {
        label:'月度',
        value:'月度'
    },
    {
        label:'双周度',
        value:'双周度'
    },
    {
        label:'周度',
        value:'周度'
    },
    {
        label:'日度',
        value:'日度'
    },
    {
        label:'不定时',
        value:'不定时'
    },
]//频度筛选项
const reportStatusOpt=[
    {
        label:'已群发邮件',
        value:2
    },
    {
        label:'未群发邮件',
        value:1
    }
]
const publishStatusOpt=[
{
        label:'未发布',
        value:1
    },
    {
        label:'已发布',
        value:2
    },
    {
        label:'待提交',
        value:3
    },
    {
        label:'待审批',
        value:4
    },
    {
        label:'已驳回',
        value:5
    },
    {
        label:'已通过',
        value:6
    }
]
const statusOpt = computed(()=>{
    let tempArr = publishStatusOpt
    if(!isApprove.value){
        tempArr = tempArr.filter(i=>![3,4].includes(i.value))
    }
    if(isOtherApprove.value){
        tempArr = tempArr.filter(i=>i.value!==1)
    }
    return tempArr
})
function handleSelectReportStatus(item){
    if(temMsgIsSendVal.value==item.value){
        temMsgIsSendVal.value=''
    }else{
        temMsgIsSendVal.value=item.value
    }
}
function handleSelectFrequency(item){
    if(temFrequencyVal.value==item.value){
        temFrequencyVal.value=''
    }else{
        temFrequencyVal.value=item.value
    }
}
function handleSelectReportPublishStatus(item){
    if(temPublishStatusVal.value==item.value){
        temPublishStatusVal.value=''
    }else{
        temPublishStatusVal.value=item.value
    }
}
function handleShowFilter(){
    temFrequencyVal.value=listState.Frequency
    temMsgIsSendVal.value=listState.MsgIsSend
    showMoreFilter.value=true
    nextTick(()=>{
        setTimeout(() => {
            frequencyDropMenuIns.value?.toggle(true);
        }, 100);
    })
}
function handleConfirmFrequency(){
    listState.Frequency=temFrequencyVal.value
    refreshList()
    showMoreFilter.value=false
}
function handleConfirmStatus(){
    listState.MsgIsSend=temMsgIsSendVal.value
    refreshList()
    showMoreFilter.value=false
}
function handleConfirmPublishStatus(){
    listState.publishStatus=temPublishStatusVal.value
    refreshList()
    showMoreFilter.value=false
}

function goSearch(){
    // 删除报告搜索页的缓存
    cachedViewsStore.removeCaches('ReportEnSearchList')
    router.push('/reportEn/search')
}

// 编辑从策略同步过来的报告
const showEditStrategyReport=ref(false)
function handleEditStrategyReportSuccess(){
    refreshList()
    showEditStrategyReport.value=false
}

//点击编辑
async function handleReportEdit(e){
    showReportItemOpt.value=false
    // 先mark一下
    const markRes=await apiReportEn.reportMark({
        Status:1,
        ReportId:e.Id
    })
    if(markRes.Ret===200){
        if(markRes.Data.Status===1){
            showToast(markRes.Data.Msg || '该研报正在编辑，不可重复编辑')
            listState.list.forEach(item=>{
                if(item.Id===e.Id){
                    item.CanEdit=false
                    item.Editor=markRes.Data.Editor || ''
                }
            })
            return
        }else if(markRes.Data.Status===0){
            listState.list.forEach(item=>{
                if(item.Id===e.Id){
                    item.CanEdit=true
                    item.Editor=markRes.Data.Editor || ''
                }
            })
        }
    }else{
        showToast(markRes.ErrMsg || '未知错误，请稍后重试')
        return
    }
    if(e.FromReportId>0){
        //策略同步来的报告只能改部分内容不能改报告内容
        showEditStrategyReport.value=true
        return
    }

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

}

// 显示群发邮件
const showSendEmail=ref(false)

// 查看群发邮件日志
function handleGoEmailLog(e){
    showReportItemOpt.value=false
    router.push({
        path:'/reportEn/sendemaillog',
        query:{
            id:e.Id,
            hasFail:e.EmailHasFail
        }
    })
}
const getSystemInfoFun=()=>{
    getSystemInfo().then(res=>{
        if(res.Ret===200){
          const systemUserInfo=res.Data
          // 设置水印文案
          let waterMarkString=''
          if(systemUserInfo){
            waterMarkString=`${systemUserInfo.RealName}${systemUserInfo.Mobile?systemUserInfo.Mobile:systemUserInfo.Email}`
            waterMarkString=encodeURIComponent(waterMarkString)
            waterMarkStr.value=Base64.encode(waterMarkString)
          }
        }
    })
}

onMounted(()=>{
    getEtaConfig()
    getSystemInfoFun()
})
</script>

<template>
    <div class="report-list-page">
        <div class="sticky-box">
            <div class="clear-filter-box" v-if="showCleanFilterBox">
                <span>想要清空所有筛选项？试试</span>
                <span @click="handleCleanFilter" style="display:flex;align-items:center">
                    <span style="color:#0052D9">一键清空</span>
                    <img class="rocket" src="@/assets/imgs/icon_rocket.png" alt="">
                </span>
                <van-icon name="cross" class="close-icon" @click="isClickClose=true"/>
            </div>
            <div class="top-box">
                <van-search
                    style="flex:1"
                    shape="round" 
                    readonly 
                    placeholder="请输入报告标题或创建人"
                    @click="goSearch"
                />
                <div :class="['menu-icon',showClassify||listState.ClassifyNameSecond?'active':'']" @click="showClassify=true">
                    <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M33.75 5.25C38.7206 5.25 42.75 9.27944 42.75 14.25C42.75 19.2206 38.7206 23.25 33.75 23.25C28.7794 23.25 24.75 19.2206 24.75 14.25C24.75 9.27944 28.7794 5.25 33.75 5.25ZM27.75 14.25C27.75 17.5637 30.4363 20.25 33.75 20.25C37.0637 20.25 39.75 17.5637 39.75 14.25C39.75 10.9363 37.0637 8.25 33.75 8.25C30.4363 8.25 27.75 10.9363 27.75 14.25Z" fill="currentColor"/>
                        <path d="M6 9C6 7.34315 7.34315 6 9 6H19.5C21.1569 6 22.5 7.34315 22.5 9V19.5C22.5 21.1569 21.1569 22.5 19.5 22.5H9C7.34315 22.5 6 21.1569 6 19.5V9ZM9 9V19.5H19.5V9H9Z" fill="currentColor"/>
                        <path d="M6 28.5C6 26.8431 7.34315 25.5 9 25.5H19.5C21.1569 25.5 22.5 26.8431 22.5 28.5V39C22.5 40.6569 21.1569 42 19.5 42H9C7.34315 42 6 40.6569 6 39V28.5ZM9 28.5V39H19.5V28.5H9Z" fill="currentColor"/>
                        <path d="M25.5 28.5C25.5 26.8431 26.8431 25.5 28.5 25.5H39C40.6569 25.5 42 26.8431 42 28.5V39C42 40.6569 40.6569 42 39 42H28.5C26.8431 42 25.5 40.6569 25.5 39V28.5ZM28.5 39H39V28.5H28.5V39Z" fill="currentColor"/>
                    </svg>
                </div>
                <div :class="['menu-icon',showCalendar||listState.EndDate?'active':'']" @click="showCalendar=true">
                    <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M37.5718 42.5667H10.4282C9.52087 42.5605 8.65247 42.1973 8.01089 41.5558C7.36931 40.9142 7.00615 40.0458 7 39.1385V11.9948C7.00615 11.0875 7.36931 10.2191 8.01089 9.57754C8.65247 8.93596 9.52087 8.5728 10.4282 8.56665H37.5718C38.4791 8.5728 39.3475 8.93596 39.9891 9.57754C40.6307 10.2191 40.9939 11.0875 41 11.9948V39.1385C40.9939 40.0458 40.6307 40.9142 39.9891 41.5558C39.3475 42.1973 38.4791 42.5605 37.5718 42.5667ZM10.4282 10.7269C10.0919 10.7269 9.76938 10.8605 9.5316 11.0982C9.29381 11.336 9.16022 11.6585 9.16022 11.9948V39.1385C9.16022 39.4748 9.29381 39.7973 9.5316 40.0351C9.76938 40.2728 10.0919 40.4064 10.4282 40.4064H37.5718C37.9081 40.4064 38.2306 40.2728 38.4684 40.0351C38.7062 39.7973 38.8398 39.4748 38.8398 39.1385V11.9948C38.8398 11.6585 38.7062 11.336 38.4684 11.0982C38.2306 10.8605 37.9081 10.7269 37.5718 10.7269H10.4282Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M39.4972 19.7435H8.50274C8.21628 19.7435 7.94155 19.6297 7.73899 19.4271C7.53643 19.2246 7.42263 18.9498 7.42263 18.6634C7.41942 18.5207 7.44517 18.3788 7.49831 18.2463C7.55146 18.1138 7.6309 17.9934 7.73184 17.8925C7.83279 17.7915 7.95314 17.7121 8.08563 17.6589C8.21813 17.6058 8.36002 17.5801 8.50274 17.5833H39.4972C39.6399 17.5801 39.7818 17.6058 39.9143 17.6589C40.0468 17.7121 40.1672 17.7915 40.2681 17.8925C40.3691 17.9934 40.4485 18.1138 40.5016 18.2463C40.5548 18.3788 40.5805 18.5207 40.5773 18.6634C40.5773 18.8052 40.5494 18.9457 40.4951 19.0767C40.4408 19.2078 40.3613 19.3268 40.261 19.4271C40.1607 19.5274 40.0416 19.607 39.9106 19.6613C39.7795 19.7155 39.6391 19.7435 39.4972 19.7435ZM17.7306 15.0473C17.4442 15.0473 17.1694 14.9336 16.9669 14.731C16.7643 14.5284 16.6505 14.2537 16.6505 13.9672V6.45342C16.6505 6.16696 16.7643 5.89223 16.9669 5.68967C17.1694 5.48711 17.4442 5.37331 17.7306 5.37331C17.8734 5.37011 18.0153 5.39585 18.1477 5.449C18.2802 5.50214 18.4006 5.58158 18.5015 5.68253C18.6025 5.78347 18.6819 5.90382 18.7351 6.03632C18.7882 6.16881 18.814 6.3107 18.8108 6.45342V13.9672C18.814 14.11 18.7882 14.2518 18.7351 14.3843C18.6819 14.5168 18.6025 14.6372 18.5015 14.7381C18.4006 14.8391 18.2802 14.9185 18.1477 14.9717C18.0153 15.0248 17.8734 15.0506 17.7306 15.0473ZM30.2458 15.0473C30.104 15.0473 29.9635 15.0194 29.8325 14.9651C29.7015 14.9108 29.5824 14.8313 29.4821 14.731C29.3818 14.6307 29.3022 14.5116 29.2479 14.3806C29.1937 14.2495 29.1657 14.1091 29.1657 13.9672V6.45342C29.1657 6.31158 29.1937 6.17113 29.2479 6.04008C29.3022 5.90904 29.3818 5.78997 29.4821 5.68967C29.5824 5.58937 29.7015 5.50981 29.8325 5.45553C29.9635 5.40125 30.104 5.37331 30.2458 5.37331C30.3886 5.37011 30.5304 5.39585 30.6629 5.449C30.7954 5.50214 30.9158 5.58158 31.0167 5.68253C31.1177 5.78347 31.1971 5.90382 31.2503 6.03632C31.3034 6.16881 31.3292 6.3107 31.3259 6.45342V13.9672C31.3292 14.11 31.3034 14.2518 31.2503 14.3843C31.1971 14.5168 31.1177 14.6372 31.0167 14.7381C30.9158 14.8391 30.7954 14.9185 30.6629 14.9717C30.5304 15.0248 30.3886 15.0506 30.2458 15.0473Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M30.8799 26.0128C30.8799 26.2996 30.9364 26.5835 31.0461 26.8485C31.1558 27.1134 31.3167 27.3541 31.5195 27.5569C31.7222 27.7597 31.963 27.9205 32.2279 28.0303C32.4929 28.14 32.7768 28.1965 33.0636 28.1965C33.3504 28.1965 33.6343 28.14 33.8993 28.0303C34.1642 27.9205 34.4049 27.7597 34.6077 27.5569C34.8105 27.3541 34.9713 27.1134 35.0811 26.8485C35.1908 26.5835 35.2473 26.2996 35.2473 26.0128C35.2473 25.726 35.1908 25.4421 35.0811 25.1771C34.9713 24.9122 34.8105 24.6715 34.6077 24.4687C34.4049 24.2659 34.1642 24.1051 33.8993 23.9953C33.6343 23.8856 33.3504 23.8291 33.0636 23.8291C32.7768 23.8291 32.4929 23.8856 32.2279 23.9953C31.963 24.1051 31.7222 24.2659 31.5195 24.4687C31.3167 24.6715 31.1558 24.9122 31.0461 25.1771C30.9364 25.4421 30.8799 25.726 30.8799 26.0128Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M21.8163 26.0128C21.8163 26.592 22.0464 27.1474 22.4559 27.5569C22.8654 27.9664 23.4208 28.1965 24 28.1965C24.5791 28.1965 25.1346 27.9664 25.5441 27.5569C25.9536 27.1474 26.1837 26.592 26.1837 26.0128C26.1837 25.4336 25.9536 24.8782 25.5441 24.4687C25.1346 24.0592 24.5791 23.8291 24 23.8291C23.4208 23.8291 22.8654 24.0592 22.4559 24.4687C22.0464 24.8782 21.8163 25.4336 21.8163 26.0128Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M12.7528 26.0128C12.7528 26.2996 12.8093 26.5835 12.919 26.8485C13.0288 27.1134 13.1896 27.3541 13.3924 27.5569C13.5952 27.7597 13.8359 27.9205 14.1008 28.0303C14.3658 28.14 14.6497 28.1965 14.9365 28.1965C15.2233 28.1965 15.5072 28.14 15.7722 28.0303C16.0371 27.9205 16.2778 27.7597 16.4806 27.5569C16.6834 27.3541 16.8442 27.1134 16.954 26.8485C17.0637 26.5835 17.1202 26.2996 17.1202 26.0128C17.1202 25.726 17.0637 25.4421 16.954 25.1771C16.8442 24.9122 16.6834 24.6715 16.4806 24.4687C16.2778 24.2659 16.0371 24.1051 15.7722 23.9953C15.5072 23.8856 15.2233 23.8291 14.9365 23.8291C14.6497 23.8291 14.3658 23.8856 14.1008 23.9953C13.8359 24.1051 13.5952 24.2659 13.3924 24.4687C13.1896 24.6715 13.0288 24.9122 12.919 25.1771C12.8093 25.4421 12.7528 25.726 12.7528 26.0128Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M21.8163 34.0668C21.8163 34.6459 22.0464 35.2013 22.4559 35.6109C22.8654 36.0204 23.4208 36.2505 24 36.2505C24.5791 36.2505 25.1346 36.0204 25.5441 35.6109C25.9536 35.2013 26.1837 34.6459 26.1837 34.0668C26.1837 33.4876 25.9536 32.9322 25.5441 32.5226C25.1346 32.1131 24.5791 31.8831 24 31.8831C23.4208 31.8831 22.8654 32.1131 22.4559 32.5226C22.0464 32.9322 21.8163 33.4876 21.8163 34.0668Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                        <path d="M12.7528 34.0668C12.7528 34.3535 12.8093 34.6375 12.919 34.9024C13.0288 35.1674 13.1896 35.4081 13.3924 35.6109C13.5952 35.8136 13.8359 35.9745 14.1008 36.0842C14.3658 36.194 14.6497 36.2505 14.9365 36.2505C15.2233 36.2505 15.5072 36.194 15.7722 36.0842C16.0371 35.9745 16.2778 35.8136 16.4806 35.6109C16.6834 35.4081 16.8442 35.1674 16.954 34.9024C17.0637 34.6375 17.1202 34.3535 17.1202 34.0668C17.1202 33.78 17.0637 33.496 16.954 33.2311C16.8442 32.9662 16.6834 32.7254 16.4806 32.5226C16.2778 32.3199 16.0371 32.159 15.7722 32.0493C15.5072 31.9395 15.2233 31.8831 14.9365 31.8831C14.6497 31.8831 14.3658 31.9395 14.1008 32.0493C13.8359 32.159 13.5952 32.3199 13.3924 32.5226C13.1896 32.7254 13.0288 32.9662 12.919 33.2311C12.8093 33.496 12.7528 33.78 12.7528 34.0668Z" fill="currentColor" stroke="currentColor" stroke-width="0.5"/>
                    </svg>
                </div>
                <div :class="['menu-icon',showMoreFilter||listState.Frequency||listState.MsgIsSend||listState.publishStatus?'active':'']" @click="handleShowFilter">
                    <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M30.283 23.977L40.824 9.5685C41.3719 8.81954 41.6002 7.88381 41.459 6.96667C41.3177 6.04952 40.8184 5.22589 40.0705 4.6765C39.4715 4.23699 38.7479 4 38.005 4H9.995C8.065 4 6.5 5.567 6.5 7.5C6.5 8.244 6.7365 8.9685 7.1755 9.5685L17.717 23.977V42.5C17.717 43.3285 18.3875 44 19.215 44C19.6125 43.9996 19.9935 43.8414 20.2743 43.5601C20.5552 43.2788 20.7128 42.8975 20.7125 42.5V23.486C20.7125 23.1675 20.611 22.857 20.423 22.5995L9.592 7.7955C9.53761 7.72096 9.50489 7.63283 9.49745 7.54085C9.49001 7.44887 9.50814 7.35663 9.54984 7.27431C9.59155 7.192 9.65519 7.12281 9.73375 7.0744C9.81231 7.02599 9.90272 7.00024 9.995 7H38.005C38.0973 7.00015 38.1878 7.02586 38.2664 7.07427C38.345 7.12268 38.4086 7.1919 38.4503 7.27426C38.492 7.35663 38.51 7.44892 38.5025 7.54092C38.4949 7.63292 38.4621 7.72104 38.4075 7.7955L27.5765 22.5995C27.3884 22.8568 27.287 23.1673 27.287 23.486V38.271C27.287 39.0995 27.9575 39.771 28.785 39.771C28.9819 39.7709 29.1768 39.732 29.3586 39.6565C29.5404 39.5811 29.7056 39.4705 29.8447 39.3312C29.9838 39.192 30.0941 39.0266 30.1693 38.8447C30.2445 38.6628 30.2831 38.4678 30.283 38.271V23.977Z" fill="currentColor"/>
                    </svg>
                </div>
            </div>
            <template v-if="showMoreFilter">
            <van-dropdown-menu :close-on-click-overlay="false" :close-on-click-outside="false">
                <van-dropdown-item title="选择频度" ref="frequencyDropMenuIns">
                    <div class="frequency-opt-box">
                        <ul>
                            <li 
                                :class="['item',temFrequencyVal==item.value?'item-active':'']" 
                                v-for="item in frequencyOpt" 
                                :key="item.value"
                                @click="handleSelectFrequency(item)"
                            >{{item.label}}</li>
                            <li class="item" style="height:0"></li>
                        </ul>
                        <div class="bot-btn-box">
                            <div class="btn cancel-btn" @click="showMoreFilter=false">取消</div>
                            <div class="btn confirm-btn" @click="handleConfirmFrequency">确定</div>
                        </div>
                    </div>
                </van-dropdown-item>
                <van-dropdown-item title="群发状态" ref="statusDropMenuIns" v-if="checkAuthBtn(enReportManageBtn.enReport_sendEmail)">
                    <div class="report-status-box">
                        <ul>
                            <li 
                                :class="['status-item',listState.MsgIsSend===item.value?'active':'']" 
                                v-for="item in reportStatusOpt" 
                                :key="item.value"
                                @click="handleSelectReportStatus(item)"
                            >{{item.label}}</li>
                        </ul>
                        
                        <div class="bot-btn-box">
                            <div class="btn cancel-btn" @click="showMoreFilter=false">取消</div>
                            <div class="btn confirm-btn" @click="handleConfirmStatus">确定</div>
                        </div>
                    </div>
                </van-dropdown-item>
                <van-dropdown-item title="报告状态" ref="publishStatusDropMenuIns">
                    <div class="report-status-box">
                        <ul>
                            <li 
                                :class="['status-item',temPublishStatusVal===item.value?'active':'']" 
                                v-for="item in statusOpt" 
                                :key="item.value"
                                @click="handleSelectReportPublishStatus(item)"
                            >{{item.label}}</li>
                        </ul>
                        
                        <div class="bot-btn-box">
                            <div class="btn cancel-btn" @click="showMoreFilter=false">取消</div>
                            <div class="btn confirm-btn" @click="handleConfirmPublishStatus">确定</div>
                        </div>
                    </div>
                </van-dropdown-item>
            </van-dropdown-menu>
            </template>
        </div>
        <van-list
            v-model:loading="listState.loading"
            :finished="listState.finished"
            :finished-text="listState.list.length>0?'没有更多了':'暂无相关报告'"
            @load="onLoad"
        >   
            <img v-if="listState.list.length==0&&listState.finished" class="list-empty-img" src="https://hzstatic.hzinsights.com/static/ETA_mobile/empty_img.png" alt="">
            <ul class="list-wrap">
                <li 
                    v-for="item in listState.list" 
                    :key="item.Id"
                    class="select-text-disabled item" 
                    @click="goDetail(item)"
                    v-longpress="{ handler: onLongPressItem, args: item, duration: 1000 }"
                >
                    <h2 :class="['van-ellipsis title',item.Title.startsWith('【')?'inline-title':'']">
                        <span>{{item.Title}}</span>
                        <span v-if="item.CreateTime">({{item.CreateTime.substring(5,7)}}{{item.CreateTime.substring(8,10)}})</span>
                    </h2>
                    <p class="van-multi-ellipsis--l2 des">{{item.Abstract}}</p>
                    <div class="bot-info">
                        <div style="flex:1">
                            <span style="margin-right:2px">{{moment(item.ModifyTime).format('YYYY-MM-DD')}}</span>
                            <svg v-if="item.PrePublishTime&&item.State==1" style="width:14px;height:14px;position: relative;top:2px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28" fill="none">
                                <path d="M13.0357 6.28571V14.7501L17.8576 19.7857L19.2213 18.422L14.9643 13.9512V6.28571H13.0357Z" fill="#0052D9"/>
                                <path d="M27.5 14C27.5 21.4558 21.4558 27.5 14 27.5C6.54416 27.5 0.5 21.4558 0.5 14C0.5 6.54416 6.54416 0.5 14 0.5C21.4558 0.5 27.5 6.54416 27.5 14ZM25.5714 14C25.5714 7.60928 20.3907 2.42857 14 2.42857C7.60928 2.42857 2.42857 7.60928 2.42857 14C2.42857 20.3907 7.60928 25.5714 14 25.5714C20.3907 25.5714 25.5714 20.3907 25.5714 14Z" fill="#0052D9"/>
                            </svg>
                            <span style="margin-left:10px">{{item.AdminRealName}}</span>
                        </div>
                        <div class="read-count">
                            <span>PV:{{item.Pv}}</span>
                        </div>
                        <div>
                            <span v-if="item.State===1">未发布</span>
                            <span v-if="item.State===2" class="active-status">已发布</span>
                            <span v-if="item.State===3">待提交</span>
                            <span v-if="item.State===4">待审批</span>
                            <span v-if="item.State===5">已驳回</span>
                            <span v-if="item.State===6" class="active-status">已通过</span>
                        </div>
                    </div>
                </li>
            </ul>
        </van-list>
    </div>

    <!-- 添加报告按钮 -->
    <div class="add-report-btn" @click="$router.push('/reportEn/add')" v-if="checkAuthBtn(enReportManageBtn.enReport_reportAdd)">
        <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M12.0499 15.9499V27.5H15.9499V15.9499H27.5V12.0499H15.9499V0.5H12.0499V12.0499H0.5V15.9499H12.0499Z" fill="white"/>
        </svg>
    </div>

    <!-- 报告item操作 -->
    <van-action-sheet
        teleport="body"
        v-model:show="showReportItemOpt"
        cancel-text="取消"
        close-on-click-action
    >
        <div class="report-item-action-box" v-if="activeItem">
            <!-- <div class="title">{{activeItem.Title}}</div> -->
            <!-- 操作：未发布——发布、编辑、删除
            已发布——取消发布、群发邮件/群发日志
            待提交——提交、编辑、删除
            待审批——撤销
            已通过——撤销、群发邮件/群发日志
            已驳回——撤销 -->
            <!-- 未发布，待提交 -->
            <template v-if="[1,3].includes(activeItem.State)">
                <div class="item" @click="handleReportEdit(activeItem)" v-if="activeItem.CanEdit&&checkAuthBtn(enReportManageBtn.enReport_reportEdit)">编辑</div>
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_publish)&&activeItem.State===1"
                    @click="handleReportPublish(activeItem)">发布</div>
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_publish)&&activeItem.State===3"
                    @click="handleReportSubmit(activeItem)">提交</div>
                <div class="item" @click="handleReportDel(activeItem)" v-permission="enReportManageBtn.enReport_reportDel">删除</div>
            </template>
            <!-- 已发布，已通过 -->
            <template v-if="[2,6].includes(activeItem.State)">
                <div class="item" @click="showSendEmail=true;showReportItemOpt=false" v-if="activeItem.EmailState===0&&activeItem.EmailAuth&&checkAuthBtn(enReportManageBtn.enReport_sendEmail)">群发邮件</div>
                <div class="item" @click="handleGoEmailLog(activeItem)" v-if="activeItem.EmailState===1&&activeItem.EmailAuth&&checkAuthBtn(enReportManageBtn.enReport_sendEmail)">群发日志</div>
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_cancelPublish)&&activeItem.State===2"
                    @click="handleReportPublishCancle(activeItem)">撤销</div> <!-- 实际上是取消发布 -->
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_cancelPublish)&&activeItem.State===6"
                    @click="handleReportCancle(activeItem)">撤销</div>
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_exportPdf) && activeItem.DetailPdfUrl"
                    @click="downloadPdfImg(activeItem,1)">下载pdf</div>
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_exportImg) && activeItem.DetailImgUrl"
                    @click="downloadPdfImg(activeItem,2)">下载长图</div>   
            </template>
            <!-- 待审批,已驳回 -->
            <template v-if="[4,5].includes(activeItem.State)">
                <div class="item" v-if="checkAuthBtn(enReportManageBtn.enReport_cancelPublish)"
                    @click="handleReportCancle(activeItem)">撤销</div>
            </template>
            <!-- <template v-if="activeItem.State==1">
                <div class="item" @click="handleReportEdit(activeItem)" v-if="activeItem.CanEdit&&checkAuthBtn(enReportManageBtn.enReport_reportEdit)">编辑</div>
                <div class="item" @click="handleReportPublish(activeItem)" v-permission="enReportManageBtn.enReport_publish">发布</div>
                <div class="item" @click="handleReportDel(activeItem)" v-permission="enReportManageBtn.enReport_reportDel">删除</div>
            </template>
            <template v-if="activeItem.State==2">
                <div class="item" @click="showSendEmail=true;showReportItemOpt=false" v-if="activeItem.EmailState===0&&activeItem.EmailAuth&&checkAuthBtn(enReportManageBtn.enReport_sendEmail)">群发邮件</div>
                <div class="item" @click="handleGoEmailLog(activeItem)" v-if="activeItem.EmailState===1&&activeItem.EmailAuth&&checkAuthBtn(enReportManageBtn.enReport_sendEmail)">群发日志</div>
                <div class="item" @click="handleReportPublishCancle(activeItem)" v-permission="enReportManageBtn.enReport_cancelPublish">取消发布</div>
            </template> -->
        </div>
    </van-action-sheet>

    <!-- 分类弹窗 -->
    <van-popup 
        v-model:show="showClassify"
        :position="width>650?'center':'bottom'"
        :style="width>650?{ width: '400px'}:''"
        round
    >
        <ListClassify @close="showClassify=false" @confirm="handleConfirmClassify" ref="classifySelector"/>
    </van-popup>

    <!-- 日期筛选 -->
    <van-popup 
        v-model:show="showCalendar"
        :position="width>650?'center':'bottom'"
        :style="width>650?{ width: '400px'}:''"
        round
    >
        <van-calendar 
            ref="calendarIns"
            :poppable="false"
            type="range"
            allow-same-day
            :min-date="calendarMinDate"
            @confirm="handleCalendarChange" 
            :style="{ height: '500px' }"
            class="calendar-box"
        >
            <template #title>
                <div style="position: relative;">
                    <span style="color:#666;position: absolute;left:16px" @click="handleResetCalendar">重置</span>
                    <span>日期选择</span>
                </div>
                <div class="time-type-box">
                    <span @click="dateType=1" :class="['item',dateType===1?'active':'']">发布时间</span>
                    <span @click="dateType=2" :class="['item',dateType===2?'active':'']">更新时间</span>
                    <span @click="dateType=3" :class="['item',dateType===3?'active':'']">审批时间</span>
                </div>
            </template>
        </van-calendar>
    </van-popup>

    <!-- 群发邮件弹窗 -->
    <van-popup 
        v-model:show="showSendEmail"
        position="bottom"
        :style="{ height: '100%' }"
        closeable
    >
        <SendEmail
            v-if="showSendEmail"
            :reportId="activeItem.Id" 
            :defaultThemeVal="activeItem.Abstract" 
            @close="showSendEmail=false;refreshList()"
        />
    </van-popup>

    <!-- 编辑从策略同步过来的报告 -->
    <van-popup 
        v-model:show="showEditStrategyReport"
        position="bottom"
        :style="{ height: '100%' }"
    >
        <EditStrategyReport 
            :defaultData="activeItem" 
            @close="showEditStrategyReport=false"
            @confirm="handleEditStrategyReportSuccess"
        />
    </van-popup>
    
</template>

<style lang="scss" scoped>
.add-report-btn{
    width: var(--van-back-top-size);
    height: var(--van-back-top-size);
    position: fixed;
    right: var(--van-back-top-right);
    bottom: calc(var(--van-back-top-bottom) + var(--van-back-top-size) + 10px);
    background-color: $theme-color;
    border-radius: 50%;
    box-shadow: 0px 6px 28px 4px rgba(0, 0, 0, 0.05), 0px 16px 20px 2px rgba(0, 0, 0, 0.06), 0px 10px 10px -6px rgba(0, 0, 0, 0.1);
    svg{
        width: 27px;
        height: 27px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
    }
}
.sticky-box{
    position: sticky;
    top: 0;
    z-index: 99;
    :deep(.van-dropdown-menu__bar){
        box-shadow: none;
        border-bottom: 1px solid $border-color;
    }
    .bot-btn-box{
        border-top: 1px solid $border-color;
        padding: 32px;
        display: flex;
        justify-content: space-between;
        .btn{
            width: 327px;
            height: 80px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 12px;
            font-size: 32px;
            font-weight: 600;
        }
        .cancel-btn{
            background-color: #F2F3FF;
            color: $theme-color;
        }
        .confirm-btn{
            background-color: $theme-color;
            color: #fff;
        }
    }
    .frequency-opt-box{
        ul{
            display: flex;
            flex-wrap: wrap;
            padding: 32px;
        }
        .item{
            width: 200px;
            height: 80px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: rgba(0, 0, 0, 0.9);
            margin-left: 12px;
            margin-right: 12px;
            margin-bottom: 24px;
            background-color: #F3F3F3;
            border-radius: 12px;
        }
        .item-active{
            background-color: #F2F3FF;
            color: $theme-color;
        }
    }
    .report-status-box{
        ul{
           padding: 32px; 
        }
        
        .status-item{
            line-height: 80px;
            border-radius: 12px;
            background-color: #F3F3F3;
            text-align: center;
            margin-bottom: 24px;
            &.active{
                background-color: #F2F3FF;
                color: $theme-color;
            }
        }
    }
    .clear-filter-box{
        padding: 0 34px;
        height: 84px;
        background-color: #F2F3FF;
        display: flex;
        align-items: center;
        font-size: 28px;
        position: relative;
        .rocket{
            width: 48px;
            height: 48px;
        }
        .close-icon{
            position: absolute;
            right: 34px;
            top: 50%;
            transform: translateY(-50%);
        }
    }

}
.top-box{
    padding: 30px 34px;
    background-color: #fff;
    display: flex;
    align-items: center;
    .menu-icon{
        width: 70px;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #F2F6FA;
        margin-left: 20px;
        border-radius: 50%;
        &.active{
            color: $theme-color;
        }
        svg{
            width: 48px;
            height: 48px;
        }
    }
    :deep(.van-search){
        padding: 0;
    }
}


.list-wrap{
    padding: 30px 34px;
    .item{
        padding: 20px;
        margin-bottom: 20px;
        border: 1px solid $border-color;
        box-shadow: 0px 3px 12px rgba(52, 75, 120, 0.08);
        border-radius: 8px;
        .title{
            font-size: 32px;
            line-height: 44px;
            margin: 0;
        }
        .inline-title{
            margin-left: -14px;
        }
        .des{
            margin-top: 10px;
            margin-bottom: 20px;
            font-size: 28px;
            color: $font-grey;
            min-height: 60px;
        }
        .bot-info{
            display: flex;
            justify-content: space-between;
            color: $font-grey;
            font-size: 28px;
            .active-status{
                color: $font-success;
            }
            .read-count{
                color: $theme-warning;
                margin-right: 30px;
                span{
                    display: inline-block;
                    margin: 0 10px;
                }
            }
        }
    }
}

.report-item-action-box{
    .title{
        padding: 20px 32px;
    }
    .item{
        text-align: center;
        line-height: 48PX;
        font-size: 32px;
        border-top: 1px solid $border-color;
    }
}

.publish-report-pop-box{
    padding: 48px;
    .title{
        font-size: 36px;
        text-align: center;
        margin-bottom: 32px;
    }
    .tips{
        color: $font-grey;
        margin-bottom: 48px;
    }
    .btns{
        .btn{
            line-height: 96px;
            border-radius: 12px;
            text-align: center;
            font-size: 32px;
            font-weight: 600;
            margin-bottom: 24px;
            background-color: #F2F3FF;
            color: $theme-color;
        }
        .blue{
            background-color: $theme-color;
            color: #fff;
        }
    }
}

.calendar-box{
    :deep(.van-calendar__header-title){
        height: auto;
        min-height: var(--van-calendar-header-title-height);
    }
    :deep(.van-calendar__header){
        box-shadow: none;
    }
    .time-type-box{
        font-weight: normal;
        text-align: left;
        padding-left: 32px;
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
        .item{
            display: inline-block;
            margin-right: 40px;
            color: $font-grey;
            position: relative;
            &.active{
                color: #333;
                &::after{
                    content: '';
                    width: 30PX;
                    height: 4PX;
                    background-color: $theme-color;
                    position: absolute;
                    bottom: 0;
                    left: 50%;
                    border-radius: 2px;
                    transform: translateX(-50%);
                }
            }
        }
    }
}

@media screen and (min-width:$media-width){
    .add-report-btn{
        svg{
            width: 14px;
            height: 14px;
        }
    }
    .sticky-box{
        top: 60px;
        .bot-btn-box{
            padding: 32px;
            justify-content: flex-end;
            .btn{
                width: 120px;
                height: 40px;
                border-radius: 6px;
                font-size: 16px;
                margin-left: 20px;
            }
        }
        .frequency-opt-box{
            ul{
                padding: 32px;
            }
            .item{
                width: 100px;
                height: 40px;
                margin-left: 6px;
                margin-right: 6px;
                margin-bottom: 12px;
                border-radius: 6px;
            }
        }
        .report-status-box{
            ul{
                padding: 32px;
            }
            .status-item{
                line-height: 40px;
                border-radius: 6px;
                margin-bottom: 12px;
            }
        }
        .clear-filter-box{
            padding: 0 17px;
            height: 42px;
            font-size: 14px;
            .rocket{
                width: 24px;
                height: 24px;
            }
            .close-icon{
                right: 17px;
            }
        }
    }
    .top-box{
        padding: 15px;
        .menu-icon{
            width: 40px;
            height: 40px;
            svg{
                width: 28px;
                height: 28px;
            }
        }
    }

    .list-wrap{
        padding: 30px;
        .item{
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 4px;
            .title{
                font-size: 16px;
                line-height: 22px;
            }
            .inline-title{
                margin-left: -14px;
            }
            .des{
                margin-top: 5px;
                margin-bottom: 10px;
                font-size: 14px;
                min-height: 30px;
            }
            .bot-info{
                font-size: 14px;
            }
        }
    }

    .report-item-action-box{
        .title{
            padding: 10px 16px;
        }
        .item{
            font-size: 16px;
        }
    }
}
</style>