<template>
    <div class="default-main">
        <el-descriptions :column="2" border>
            <el-descriptions-item label="监测点名称">
                {{ detailData.lineName }}
            </el-descriptions-item>
            <el-descriptions-item label="接入母线">
                {{ detailData.connectedBus }}
            </el-descriptions-item>
            <!-- <el-descriptions-item label="终端编号">
                {{ detailData.monitoringTerminalCode }}
            </el-descriptions-item> -->
            <el-descriptions-item label="终端名称">
                {{ detailData.monitoringTerminalName }}
            </el-descriptions-item>
            <el-descriptions-item label="变电站">
                {{ detailData.powerSubstationName }}
            </el-descriptions-item>
            <el-descriptions-item label="调试原因">
                {{ detailData.reason }}
            </el-descriptions-item>
            <el-descriptions-item label="监测点在线率">
                {{ detailData.onlineRate ? detailData.onlineRate * 100 + '%' : '/' }}
            </el-descriptions-item>
            <el-descriptions-item label="监测点数据完整性">
                {{ detailData.integrityRate ? detailData.integrityRate * 100 + '%' : '/' }}
            </el-descriptions-item>
            <el-descriptions-item label="试运行报告">
                <el-icon class="elView" v-if="detailData?.reportName">
                    <View @click="openFile(detailData?.reportName)" />
                </el-icon>
                <a target="_blank" :href="detailData?.reportUrl">
                    {{ detailData?.reportName }}
                </a>
            </el-descriptions-item>
        </el-descriptions>
    </div>
</template>
<script lang="ts" setup>
import { onMounted, ref, reactive } from 'vue'
import { useRoute } from 'vue-router'
import { propTypes } from '@/utils/propTypes'
import { Link, View } from '@element-plus/icons-vue'
import { getMointorPointTempLinedebugDetail } from '@/api/supervision-boot/jointDebugList/index'
import { getRunTestById } from '@/api/supervision-boot/lineRunTest'
import { getFileNameAndFilePath } from '@/api/system-boot/file'
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 getInfo = async () => {
    detailLoading.value = true
    try {
        await getRunTestById(props.id).then(res => {
            detailData.value = res.data
            if (res.data.testRunReport.length > 0 && res.data.testRunReport != null) {
                getFileNameAndFilePath({ filePath: res.data.testRunReport }).then(report => {
                    detailData.value.reportUrl = report.data.url
                    detailData.value.reportName = report.data.fileName
                   // console.log('🚀 ~ getFileNameAndFilePath ~ detailData.value:', detailData.value)
                })
            }
        })
    } finally {
        detailLoading.value = false
    }
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗
const openFile = (name: any) => {
    window.open(window.location.origin + '/#/previewFile?/supervision/' + name)
}
/** 初始化 **/
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;
}

.elView {
    cursor: pointer;
    margin-right: 10px;
}
</style>
