<template>
     <div v-if="detailLoading" class="loading">
            <el-spin description="加载中..." />
        </div>
        <div v-else>
    <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.supervisionTempDeviceReport?.powerCompany }}
        </el-descriptions-item>
        <el-descriptions-item label="并网变电站">
            {{ detailData.supervisionTempDeviceReport?.substationName }}
        </el-descriptions-item>
        <el-descriptions-item label="变电站电压等级">
            {{
                voltageLevelList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.substationVoltageLevel
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="经度">
            {{ detailData.supervisionTempDeviceReport?.longitude }}
        </el-descriptions-item>
        <el-descriptions-item label="纬度">
            {{ detailData.supervisionTempDeviceReport?.latitude }}
        </el-descriptions-item>
        <el-descriptions-item label="检测终端编码">
            {{ detailData.supervisionTempDeviceReport?.monitoringTerminalCode }}
        </el-descriptions-item>
        <el-descriptions-item label="检测终端名称">
            {{ detailData.supervisionTempDeviceReport?.monitoringTerminalName }}
        </el-descriptions-item>
        <el-descriptions-item label="通讯类型">
            {{
                frontTypeList.filter(item => item.id == detailData.supervisionTempDeviceReport?.frontType)[0]?.name ||
                detailData.supervisionTempDeviceReport?.frontType
            }}
        </el-descriptions-item>
        <el-descriptions-item label="电压互感器类型">
            {{
                voltageTransformerTypeList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.voltageTransformerType
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="终端接线方式类型">
            {{
                terminalWiringMethodTypeList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.terminalWiringMethodType
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="中性点接线方式">
            {{
                neutralPointWiringMethodList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.neutralPointWiringMethod
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="厂家">
            {{
                manufacturerList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.manufacturer
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="厂家终端编号">
            {{ detailData.supervisionTempDeviceReport?.manufacturerDeviceNumber }}
        </el-descriptions-item>
        <el-descriptions-item label="终端IP">
            {{ detailData.supervisionTempDeviceReport?.terminalIp }}
        </el-descriptions-item>
        <el-descriptions-item label="终端型号">
            {{
                terminalTypeList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.terminalType
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="端口">
            {{ detailData.supervisionTempDeviceReport?.terminalPort }}
        </el-descriptions-item>
        <el-descriptions-item label="所属前置机">
            {{
                frontEndMachineList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.frontEndMachine
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="本次终端检测时间">
            {{ detailData.supervisionTempDeviceReport?.currentTerminalDetectionTime?.replace('T', ' ') }}
        </el-descriptions-item>
        <el-descriptions-item label="下次终端定检时间">
            {{ detailData.supervisionTempDeviceReport?.nextTerminalInspectionTime?.replace('T', ' ') }}
        </el-descriptions-item>
        <el-descriptions-item label="识别码">
            {{ detailData.supervisionTempDeviceReport?.identificationCode }}
        </el-descriptions-item>
        <el-descriptions-item label="终端秘钥">
            {{ detailData.supervisionTempDeviceReport?.terminalSecretKey }}
        </el-descriptions-item>
        <!-- <el-descriptions-item label="经度">
            {{ detailData.supervisionTempDeviceReport?.longitude }}
        </el-descriptions-item>
        <el-descriptions-item label="纬度">
            {{ detailData.supervisionTempDeviceReport?.latitude }}
        </el-descriptions-item> -->
        <el-descriptions-item label="终端模型">
            {{
                terminalModelList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.terminalModel
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="数据类型">
            {{
                dataTypeList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.dataType
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="通讯状态">
            {{
                communicationStatusList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.communicationStatus
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="SIM卡号">
            {{ detailData.supervisionTempDeviceReport?.simCardNumber }}
        </el-descriptions-item>
        <el-descriptions-item label="投运时间">
            {{ detailData.supervisionTempDeviceReport?.commissioningTime?.replace('T', ' ') }}
        </el-descriptions-item>
        <el-descriptions-item label="数据更新时间">
            {{ detailData.supervisionTempDeviceReport?.dataUpdateTime?.replace('T', ' ') }}
        </el-descriptions-item>
        <el-descriptions-item label="对时功能">
            {{
                detailData.supervisionTempDeviceReport?.timeSyncFunction == '0'
                    ? '否'
                    : detailData.supervisionTempDeviceReport?.timeSyncFunction == '1'
                    ? '是'
                    : '-'
            }}
        </el-descriptions-item>
        <el-descriptions-item label="电度功能">
            {{
                detailData.supervisionTempDeviceReport?.electroplatingFunction == '0'
                    ? '否'
                    : detailData.supervisionTempDeviceReport?.electroplatingFunction == '1'
                    ? '是'
                    : '-'
            }}
        </el-descriptions-item>
        <el-descriptions-item label="监测终端安装位置">
            {{
                monitoringDeviceInstallationPositionList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.monitoringDeviceInstallationPosition
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="召唤标志">
            {{
                summonFlagList.find(item => {
                    return item.id == detailData.supervisionTempDeviceReport?.summonFlag
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="告警功能">
            {{
                detailData.supervisionTempDeviceReport?.alarmFunction == '0'
                    ? '否'
                    : detailData.supervisionTempDeviceReport?.alarmFunction == '1'
                    ? '是'
                    : '-'
            }}
        </el-descriptions-item>
        <el-descriptions-item label="合同号">
            {{ detailData.supervisionTempDeviceReport?.contractNumber }}
        </el-descriptions-item>
        <el-descriptions-item label="信息安全检测报告">
            <el-icon class="elView" v-if="detailData?.informationSecurityTestReport?.name ">
                <View @click="openFile(detailData?.informationSecurityTestReport?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.informationSecurityTestReport.keyName)"
                v-if="detailData?.informationSecurityTestReport?.name"
            >
                {{ detailData?.informationSecurityTestReport.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="验收检验报告单">
            <el-icon class="elView" v-if="detailData?.acceptanceInspectionReportSingle?.name ">
                <View @click="openFile(detailData?.acceptanceInspectionReportSingle?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.acceptanceInspectionReportSingle.keyName)"
                v-if="detailData?.acceptanceInspectionReportSingle?.name"
            >
                {{ detailData?.acceptanceInspectionReportSingle?.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="验收检验报告">
            <el-icon class="elView" v-if="detailData?.acceptanceInspectionReport?.name ">
                <View @click="openFile(detailData?.acceptanceInspectionReport?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.acceptanceInspectionReport.keyName)"
                v-if="detailData?.acceptanceInspectionReport?.name"
            >
                {{ detailData?.acceptanceInspectionReport?.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="型式实验报告">
            <el-icon class="elView" v-if="detailData?.typeExperimentReport?.name ">
                <View @click="openFile(detailData?.typeExperimentReport?.name)" />
            </el-icon>
            <span
                v-if="detailData?.typeExperimentReport?.name"
                class="aLoad"
                @click="download(detailData?.typeExperimentReport.keyName)"
            >
                {{ detailData?.typeExperimentReport?.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="出厂检验报告">
            <el-icon class="elView" v-if="detailData?.factoryInspectionReport?.name ">
                <View @click="openFile(detailData?.factoryInspectionReport?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.factoryInspectionReport.keyName)"
                v-if="detailData?.factoryInspectionReport?.name"
            >
                {{ detailData?.factoryInspectionReport?.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="性能检测报告">
            <el-icon class="elView" v-if="detailData?.performanceTestReport?.name ">
                <View @click="openFile(detailData?.performanceTestReport?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.performanceTestReport.keyName)"
                v-if="detailData?.performanceTestReport?.name"
            >
                {{ detailData?.performanceTestReport?.name }}
            </span>
        </el-descriptions-item>
        <el-descriptions-item label="其他附件">
            <el-icon class="elView" v-if="detailData?.otherAttachments?.name ">
                <View @click="openFile(detailData?.otherAttachments?.name)" />
            </el-icon>
            <span
                class="aLoad"
                @click="download(detailData?.otherAttachments.keyName)"
                v-if="detailData?.otherAttachments?.name"
            >
                {{ detailData?.otherAttachments?.name }}
            </span>
        </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 { getTerminalDetailsById } from '@/api/supervision-boot/terminal/index'
import { getDictTreeById } from '@/api/system-boot/dictTree'
import { useDictData } from '@/stores/dictData'
import { getFileNameAndFilePath } from '@/api/system-boot/file'
import { Link, View } from '@element-plus/icons-vue'
import { nodeAllList } from '@/api/device-boot/Business'
import { download } from '@/utils/fileDownLoad'
defineOptions({ name: 'BpmUserReportDetail' })
const openFile = (name: any) => {
    window.open(window.location.origin + '/#/previewFile?/supervision/' + name)
}
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 userStateList = reactive([
    {
        label: '可研',
        value: '0'
    },
    {
        label: '建设',
        value: '1'
    },
    {
        label: '运行',
        value: '2'
    },
    {
        label: '退运',
        value: '3'
    }
])
const dictData = useDictData()
//字典获取所在地市
const frontTypeList = dictData.getBasicData('Front_Type', ['CLD', '61850'])
const areaOptionList = dictData.getBasicData('jibei_area')
//定义监测终端安装位置下拉框数据
const monitoringDeviceInstallationPositionList = [
    {
        id: '0',
        name: '电网侧'
    },
    {
        id: '1',
        name: '用户侧'
    }
]
//定义召唤标志下拉框数据
const summonFlagList = [
    {
        id: '0',
        name: '周期触发'
    },
    {
        id: '1',
        name: '变位触发'
    }
]
//定义终端模型下拉框数据
const terminalModelList = [
    {
        id: '0',
        name: '虚拟终端'
    },
    {
        id: '1',
        name: '实际终端'
    },
    {
        id: '2',
        name: '离线'
    }
]
//定义通讯状态下拉框数据
const communicationStatusList = [
    {
        id: '0',
        name: '中断'
    },
    {
        id: '1',
        name: '正常'
    }
]
//字典获取监测点电压等级
const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
//字典获取数据类型
const dataTypeList = [
    {
        id: '0',
        name: '暂态系统'
    },
    {
        id: '1',
        name: '稳态系统'
    },
    {
        id: '2',
        name: '两个系统'
    }
]
//字典获取终端型号
const terminalTypeList = dictData.getBasicData('Dev_Type')
//字典获取电压互感器类型
const voltageTransformerTypeList = dictData.getBasicData('Voltage_Transformer')
//字典获取中性点接线方式
const neutralPointWiringMethodList = dictData.getBasicData('Neutral_Point')
//字典获取终端接线方式类型
const terminalWiringMethodTypeList = dictData.getBasicData('Dev_Connect')
//字典获取厂家
const manufacturerList = dictData.getBasicData('Dev_Manufacturers')
/** 获得数据 */
const getInfo = async () => {
    detailLoading.value = true
    try {
        await getTerminalDetailsById({ id: props.id || queryId }).then(res => {
            detailData.value = res.data
            getFileName()
        })
    } finally {
        detailLoading.value = false
    }
}
//获取所属前置机数据
const frontEndMachineList = ref([])
const getFrontEndMachineList = () => {
    nodeAllList().then(res => {
        frontEndMachineList.value = res.data
    })
}
getFrontEndMachineList()
const getFileName = async () => {
    //信息安全检测报告
    if (detailData.value.informationSecurityTestReport) {
        await getFileNamePath(detailData.value.informationSecurityTestReport, 'informationSecurityTestReport')
    }
    //验收检验报告单
    if (detailData.value.acceptanceInspectionReportSingle) {
        await getFileNamePath(detailData.value.acceptanceInspectionReportSingle, 'acceptanceInspectionReportSingle')
    }
    //验收检验报告
    if (detailData.value.acceptanceInspectionReport) {
        await getFileNamePath(detailData.value.acceptanceInspectionReport, 'acceptanceInspectionReport')
    }
    //型式实验报告
    if (detailData.value.typeExperimentReport) {
        await getFileNamePath(detailData.value.typeExperimentReport, 'typeExperimentReport')
    }
    //出厂检验报告
    if (detailData.value.factoryInspectionReport) {
        await getFileNamePath(detailData.value.factoryInspectionReport, 'factoryInspectionReport')
    }

    //性能检测报告
    if (detailData.value.performanceTestReport) {
        await getFileNamePath(detailData.value.performanceTestReport, 'performanceTestReport')
    }
    //其他附件
    if (detailData.value.otherAttachments) {
        await getFileNamePath(detailData.value.otherAttachments, 'otherAttachments')
    }
}
//根据文件名请求
const getFileNamePath = async (val: any, pathName: any) => {
    await getFileNameAndFilePath({ filePath: val }).then(res => {
        if (res.data) {
            //信息安全检测报告
            if (pathName == 'informationSecurityTestReport' && detailData.value.informationSecurityTestReport) {
                detailData.value.informationSecurityTestReport = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
            //验收检验报告单
            else if (
                pathName == 'acceptanceInspectionReportSingle' &&
                detailData.value.acceptanceInspectionReportSingle
            ) {
                detailData.value.acceptanceInspectionReportSingle = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }

            //验收检验报告
            else if (pathName == 'acceptanceInspectionReport' && detailData.value.acceptanceInspectionReport) {
                detailData.value.acceptanceInspectionReport = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
            //型式实验报告
            else if (pathName == 'typeExperimentReport' && detailData.value.typeExperimentReport) {
                detailData.value.typeExperimentReport = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
            //出场检验报告
            else if (pathName == 'factoryInspectionReport' && detailData.value.factoryInspectionReport) {
                detailData.value.factoryInspectionReport = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
            //性能检测报告
            else if (pathName == 'performanceTestReport' && detailData.value.performanceTestReport) {
                detailData.value.performanceTestReport = {
                    name: res.data.fileName,
                     keyName: res.data.name,
                    url: res.data.url
                }
            }
            //其他附件
            else if (pathName == 'otherAttachments' && detailData.value.otherAttachments) {
                detailData.value.otherAttachments = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
        }
    })
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗

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

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