<template>
    <div class="default-main">
        <el-descriptions :column="2" border>
            <el-descriptions-item label="填报人">
                {{ detailData.reporter }}
            </el-descriptions-item>
            <el-descriptions-item label="填报日期">
                {{ formatDate(detailData.reportDate, 'YYYY-MM-DD') }}
            </el-descriptions-item>
            <el-descriptions-item label="填报部门">
                {{ detailData.orgName }}
            </el-descriptions-item>
            <el-descriptions-item label="工程投产日期">
                {{ formatDate(detailData.expectedProductionDate, 'YYYY-MM-DD') }}
            </el-descriptions-item>
            <el-descriptions-item label="所属地市">
                {{ detailData.city }}
            </el-descriptions-item>
            <el-descriptions-item label="用户状态">
                {{
                    userStateList.find(item => {
                        return item.value == detailData.userStatus
                    })?.label
                }}
            </el-descriptions-item>
            <el-descriptions-item label="工程名">
                {{ detailData.projectName }}
            </el-descriptions-item>
            <!--文件地址-->
            >
            <el-descriptions-item label="终端台账信息">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.preliminaryDesignDescription.url">
                    {{ proviteData?.preliminaryDesignDescription.name }}
                </a>
            </el-descriptions-item>
            <el-descriptions-item label="监测点台账信息">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.predictionEvaluationReport.url">
                    {{ proviteData?.predictionEvaluationReport.name }}
                </a>
            </el-descriptions-item>
            <el-descriptions-item label="验收检验报告单">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.predictionEvaluationReviewOpinions.url">
                    {{ proviteData?.predictionEvaluationReviewOpinions.name }}
                </a>
            </el-descriptions-item>
            <el-descriptions-item label="验收检验报告">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.sensitiveDevices.url">{{ proviteData?.sensitiveDevices.name }}</a>
            </el-descriptions-item>
            <el-descriptions-item label="型式实验报告">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.antiInterferenceReport.url">{{ proviteData?.antiInterferenceReport.name }}</a>
            </el-descriptions-item>
            <el-descriptions-item label="出厂检验报告">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.powerQualityReport.url">{{ proviteData?.powerQualityReport.name }}</a>
            </el-descriptions-item>
            <el-descriptions-item label="性能检测报告">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.antiInterferenceReport.url">{{ proviteData?.antiInterferenceReport.name }}</a>
            </el-descriptions-item>
            <el-descriptions-item label="信息安全检测报告">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.powerQualityReport.url">{{ proviteData?.powerQualityReport.name }}</a>
            </el-descriptions-item>
            <el-descriptions-item label="其他附件">
                <el-icon>
                    <Link />
                </el-icon>
                <a :href="proviteData?.additionalAttachments.url">{{ proviteData?.additionalAttachments.name }}</a>
            </el-descriptions-item>
        </el-descriptions>
    </div>
</template>
<script lang="ts" setup>
import { onMounted, ref, reactive } from 'vue'
import { useRoute } from 'vue-router'
import { formatDate } from '@/utils/formatTime'
import { propTypes } from '@/utils/propTypes'
import { getUserReportById } from '@/api/supervision-boot/userReport/form'
import { getDictTreeById } from '@/api/system-boot/dictTree'
import { useDictData } from '@/stores/dictData'
import { getFileNameAndFilePath } from '@/api/system-boot/file'
import { Link } from '@element-plus/icons-vue'

defineOptions({ name: 'BpmUserReportDetail' })

const { query } = useRoute() // 查询参数

const props = defineProps({
    id: propTypes.string.def(undefined)
})
const detailLoading = ref(false) // 表单的加载中
const detailData = ref<any>({}) // 详情数据
const queryId = query.id as unknown as string // 从 URL 传递过来的 id 编号
//用户性质数组
const userTypeList = reactive([
    {
        label: '新建电网工程',
        value: '0'
    },
    {
        label: '扩建电网工程',
        value: '1'
    },
    {
        label: '新建非线性负荷用户',
        value: '2'
    },
    {
        label: '扩建非线性负荷用户',
        value: '3'
    },
    {
        label: '新建新能源发电站',
        value: '4'
    },
    {
        label: '扩建新能源发电站',
        value: '5'
    },
    {
        label: '敏感及重要用户',
        value: '6'
    }
])
//用户状态数组
const userStateList = reactive([
    {
        label: '可研',
        value: '0'
    },
    {
        label: '建设',
        value: '1'
    },
    {
        label: '运行',
        value: '2'
    },
    {
        label: '退运',
        value: '3'
    }
])
const dictData = useDictData()
//字典获取所属地市
const areaOptionList = dictData.getBasicData('jibei_area')
//字典获取敏感电能质量指标
const energyQualityIndexList = dictData.getBasicData('Indicator_Type')
//字典获取行业类型
const industryList = dictData.getBasicData('industry_type_jb')
//字典电压等级
const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
//字典评估类型
const evaluationTypeList = dictData.getBasicData('Evaluation_Type')
//字典预测评估单位
const evaluationDeptList = dictData.getBasicData('evaluation_dept')
/** 获得数据 */
const getInfo = async () => {
    detailLoading.value = true
    try {
        await getUserReportById(props.id || queryId).then(res => {
            detailData.value = res.data
            getProviteData()
        })
    } finally {
        detailLoading.value = false
    }
}
const proviteData = ref()
//判断userType选择取用的对象
const getProviteData = async () => {
    if (detailData.value.userType == '0' || detailData.value.userType == '1') {
        proviteData.value = detailData.value.userReportProjectPO
        //查询非线性设备类型
        await getDictTreeById(proviteData.value.nonlinearDeviceType).then(res => {
            console.log(res, '==========')
            proviteData.value.nonlinearDeviceType = res.data?.name
        })
    } else if (
        detailData.value.userType == '2' ||
        detailData.value.userType == '3' ||
        detailData.value.userType == '4' ||
        detailData.value.userType == '5'
    ) {
        proviteData.value = detailData.value.userReportSubstationPO
        //查询非线性负荷类型
        await getDictTreeById(proviteData.value.nonlinearLoadType).then(res => {
            console.log(res, '==========')
            proviteData.value.nonlinearLoadType = res.data?.name
        })
    } else {
        proviteData.value = detailData.value.userReportSensitivePO
    }
    console.log(proviteData.value, '++++++++++++proviteData.evaluationType')
    //可研报告
    if (proviteData.value.feasibilityReport) {
        await getFileNamePath(proviteData.value.feasibilityReport, 'feasibilityReport')
    }
    //终端台账信息
    if (proviteData.value.preliminaryDesignDescription) {
        await getFileNamePath(proviteData.value.preliminaryDesignDescription, 'preliminaryDesignDescription')
    }
    //预测评估报告
    if (proviteData.value.predictionEvaluationReport) {
        await getFileNamePath(proviteData.value.predictionEvaluationReport, 'predictionEvaluationReport')
    }

    //预测评估评审意见报告
    if (proviteData.value.predictionEvaluationReviewOpinions) {
        await getFileNamePath(
            proviteData.value.predictionEvaluationReviewOpinions,
            'predictionEvaluationReviewOpinions'
        )
    }
    //用户接入变电站主接线示意图
    if (proviteData.value.substationMainWiringDiagram) {
        await getFileNamePath(proviteData.value.substationMainWiringDiagram, 'substationMainWiringDiagram')
    }

    //主要敏感设备清单
    if (proviteData.value.sensitiveDevices) {
        await getFileNamePath(proviteData.value.sensitiveDevices, 'sensitiveDevices')
    }

    //抗扰度测试报告
    if (proviteData.value.antiInterferenceReport) {
        await getFileNamePath(proviteData.value.antiInterferenceReport, 'antiInterferenceReport')
    }

    //背景电能质量测试报告
    if (proviteData.value.powerQualityReport) {
        await getFileNamePath(proviteData.value.powerQualityReport, 'powerQualityReport')
    }

    //其他附件
    if (proviteData.value.additionalAttachments) {
        getFileNamePath(proviteData.value.additionalAttachments, 'additionalAttachments')
    }
}
//根据文件名请求
const getFileNamePath = async (val: any, pathName: any) => {
    await getFileNameAndFilePath({ filePath: val }).then(res => {
        console.log(111111111)
        if (res.data && res.data.name && res.data.url) {
            //可研报告
            if (pathName == 'feasibilityReport' && proviteData.value.feasibilityReport) {
                proviteData.value.feasibilityReport = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //终端台账信息
            else if (pathName == 'preliminaryDesignDescription' && proviteData.value.preliminaryDesignDescription) {
                proviteData.value.preliminaryDesignDescription = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //预测评估报告
            else if (pathName == 'predictionEvaluationReport' && proviteData.value.predictionEvaluationReport) {
                proviteData.value.predictionEvaluationReport = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //预测评估评审意见报告
            else if (
                pathName == 'predictionEvaluationReviewOpinions' &&
                proviteData.value.predictionEvaluationReviewOpinions
            ) {
                proviteData.value.predictionEvaluationReviewOpinions = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //用户接入变电站主接线示意图
            else if (pathName == 'substationMainWiringDiagram' && proviteData.value.substationMainWiringDiagram) {
                proviteData.value.substationMainWiringDiagram = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //主要敏感设备清单
            else if (pathName == 'sensitiveDevices' && proviteData.value.sensitiveDevices) {
                proviteData.value.sensitiveDevices = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //抗扰度测试报告
            else if (pathName == 'antiInterferenceReport' && proviteData.value.antiInterferenceReport) {
                proviteData.value.antiInterferenceReport = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //背景电能质量测试报告
            else if (pathName == 'powerQualityReport' && proviteData.value.powerQualityReport) {
                proviteData.value.powerQualityReport = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
            //其他附件
            else if (pathName == 'additionalAttachments' && proviteData.value.additionalAttachments) {
                proviteData.value.additionalAttachments = {
                    name: res.data.fileName,
                    url: res.data.url
                }
            }
        }
    })
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗

/** 初始化 **/
onMounted(() => {
    getInfo()
})
</script>
<style lang="scss">
.default-main {
    //   height: calc(100vh - 100px);
    overflow: auto;
}

::v-deep.el-icon svg {
    margin: 5px !important;
    position: absolute !important;
    top: 20px !important;
}
</style>
