<template>
     <div v-if="detailLoading" class="loading">
            <el-spin description="加载中..." />
        </div>
        <div v-else>
    <el-descriptions :column="2" border>
        <el-descriptions-item label="监测点台账信息" v-if="detailData.lineFilePath">
            <el-icon>
                <Link />
            </el-icon>
            <span :href="detailData?.lineFilePath.url">
                {{ detailData?.lineFilePath.name }}
           </span >
        </el-descriptions-item>
        <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.userName }}
        </el-descriptions-item>
        <el-descriptions-item label="关联终端">
            {{ detailData.monitoringTerminalName }}
        </el-descriptions-item>
        <el-descriptions-item label="监测点名称">
            {{ detailData.lineName }}
        </el-descriptions-item>
        <el-descriptions-item label="监测点电压等级">
            {{
                voltageLevelList.find(item => {
                    return detailData.voltageLevel == item.id
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="接入母线">
            {{ detailData.connectedBus }}
        </el-descriptions-item>
        <el-descriptions-item label="短路容量">
            {{ detailData.shortCapacity }}
        </el-descriptions-item>
        <el-descriptions-item label="协议容量">
            {{ detailData.dealCapacity }}
        </el-descriptions-item>
        <el-descriptions-item label="终端容量">
            {{ detailData.devCapacity }}
        </el-descriptions-item>
        <el-descriptions-item label="基准容量">
            {{ detailData.standardCapacity }}
        </el-descriptions-item>
        <el-descriptions-item label="CT变比">
            {{ detailData.ct1 }}/{{ detailData.ct2  }}
        </el-descriptions-item>
        <el-descriptions-item label="PT变比">
            {{ detailData.pt1 }}/{{ detailData.pt2  }}
        </el-descriptions-item>
        <el-descriptions-item label="上送网公司编码">
            {{ detailData.lineId }}
        </el-descriptions-item>
        <el-descriptions-item label="测量间隔">
            {{
                timeIntervalList.find(item => {
                    return item.id == detailData.timeInterval
                })?.name
            }}
        </el-descriptions-item>
        <el-descriptions-item label="干扰源类型">
            {{ detailData.loadType }}
        </el-descriptions-item>
        <el-descriptions-item label="干扰源类别">
            {{ detailData.businessType }}
        </el-descriptions-item>
        <el-descriptions-item label="监测点性质">
            {{ detailData.pointNature == '0' ? '电网侧' : '非电网侧' }}
        </el-descriptions-item>
        <el-descriptions-item label="是否参与统计">
            {{ detailData.isStatistical == '0' ? '是' : '否' }}
        </el-descriptions-item>
        <el-descriptions-item label="对象名称(对端)">
            {{ detailData.objName }}
        </el-descriptions-item>
        <el-descriptions-item label="电网侧变电站">
            {{ detailData.powerSubstationName }}
        </el-descriptions-item>
        <el-descriptions-item label="是否并网点">
            {{ detailData.isGridConnectionPoint == '0' ? '是' : '否' }}
        </el-descriptions-item>
        <el-descriptions-item label="电压偏差上限">
            {{ detailData.voltageDeviationUpperLimit }}
        </el-descriptions-item>
        <el-descriptions-item label="电压偏差下限">
            {{ detailData.voltageDeviationLowerLimit }}
        </el-descriptions-item>
        <el-descriptions-item label="监测点运行状态">
            {{
                operationStatusList.find(item => {
                    return detailData.operationStatus == item.id
                })?.name
            }}
        </el-descriptions-item>
        <!--文件地址-->
        <el-descriptions-item label="主接线图" v-if="detailData?.mainWiringDiagram">
            <el-icon class="elView" v-if="detailData?.mainWiringDiagram.name ">
                <View @click="openFile(detailData?.mainWiringDiagram.name)" />
            </el-icon>
            <span  class="aLoad" @click="download(detailData?.mainWiringDiagram.keyName)">
                {{ detailData?.mainWiringDiagram.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 { getTempLineDetailsById } from '@/api/supervision-boot/monitorpoint/index'
import { useDictData } from '@/stores/dictData'
import { getFileNameAndFilePath } from '@/api/system-boot/file'
import {download} from '@/utils/fileDownLoad'
import { Link, View } from '@element-plus/icons-vue'
const openFile = (name: any) => {
    window.open(window.location.origin + '/#/previewFile?/supervision/' + name)
}
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 timeIntervalList = [
    {
        id: '1',
        name: '1分钟'
    },
    {
        id: '3',
        name: '3分钟'
    },
    {
        id: '5',
        name: '5分钟'
    },
    {
        id: '10',
        name: '10分钟'
    }
]
//用户状态数组
const userStateList = reactive([
    {
        label: '可研',
        value: '0'
    },
    {
        label: '建设',
        value: '1'
    },
    {
        label: '运行',
        value: '2'
    },
    {
        label: '退运',
        value: '3'
    }
])
const dictData = useDictData()
//字典获取监测点电压等级
const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
//定义监测点运行状态下拉框数据
const operationStatusList = [
    {
        id: '0',
        name: '运行'
    },
    {
        id: '1',
        name: '检修'
    },
    {
        id: '2',
        name: '停运'
    },
    {
        id: '3',
        name: '调试'
    },
    {
        id: '4',
        name: '退运'
    }
]
/** 获得数据 */
const getInfo = async () => {
    detailLoading.value = true
    try {
        await getTempLineDetailsById({ id: props.id || queryId }).then(res => {
            detailData.value = res.data
            getFileName()
        })
    } finally {
        detailLoading.value = false
    }
}
const getFileName = async () => {
    //监测点台账信息
    if (detailData.value.lineFilePath) {
        await getFileNamePath(detailData.value.lineFilePath, 'lineFilePath')
    }
    //主接线图
    else if (detailData.value.mainWiringDiagram) {
        await getFileNamePath(detailData.value.mainWiringDiagram, 'mainWiringDiagram')
    }
}
//根据文件名请求
const getFileNamePath = async (val: any, pathName: any) => {
    await getFileNameAndFilePath({ filePath: val }).then(res => {
        if (res.data) {
            //监测点台账信息
            if (pathName == 'lineFilePath' && detailData.value.lineFilePath) {
                detailData.value.lineFilePath = {
                    name: res.data.fileName,
                    keyName: res.data.name,
                    url: res.data.url
                }
            }
            //主接线图
            else if (pathName == 'mainWiringDiagram' && detailData.value.mainWiringDiagram) {
                detailData.value.mainWiringDiagram = {
                    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>
