<template>
    <el-dialog draggable width="1350px" class="cn-operate-dialog" v-model="dialogVisible" :title="title">
        <div style="display: flex">
            <div :style="height1" class="mr10 box" style="width: 500px">
                <vxe-table
                    height="auto"
                    :data="TableData"
                    v-bind="defaultAttribute"
                    ref="tableRef"
                    :row-config="{ isCurrent: true, isHover: true }"
                    @current-change="currentChangeEvent"
                >
                    <vxe-column type="seq" title="序号" width="60px"></vxe-column>
                    <vxe-column field="date" title="日期"></vxe-column>
                    <vxe-column field="bdName" title="所属电站(场站)" width="120px"></vxe-column>
                    <vxe-column field="monitorName" title="监测点名称" width="120px"></vxe-column>
                    <vxe-column field="timeSum" title="告警时间(分钟)" width="80px"></vxe-column>
                </vxe-table>
            </div>

            <div :style="height" style="width: 820px" v-loading="loading1">
                <vxe-table
                    height="auto"
                    :data="TableData1.slice((pageNum - 1) * pageSize, pageNum * pageSize)"
                    v-bind="defaultAttribute"
                >
                    <vxe-column type="seq" title="序号" width="80px">
                        <template #default="{ rowIndex }">
                            <span>{{ (pageNum - 1) * pageSize + rowIndex + 1 }}</span>
                        </template>
                    </vxe-column>
                    <vxe-column field="time" title="时间" :formatter="formatter" ></vxe-column>
                    <vxe-column
                        field="targetName"
                        title="指标类型"
                        min-width="100px"
                    ></vxe-column>
                    <vxe-column field="phaseType" title="相别" width="80px"></vxe-column>

                    <vxe-column field="type" title="数据类型" width="105px" :formatter="formatter"></vxe-column>
                    <vxe-column field="val" title="值" width="85px" :formatter="formatter"></vxe-column>
                </vxe-table>
                <div class="table-pagination">
                    <el-pagination
                        v-model:currentPage="pageNum"
                        v-model:page-size="pageSize"
                        :page-sizes="[10, 20, 50, 100, 200]"
                        background
                        layout="sizes,total, ->, prev, pager, next, jumper"
                        :total="TableData1.length"
                    ></el-pagination>
                </div>
            </div>
        </div>
    </el-dialog>
</template>
<script lang="ts" setup>
import { ref, inject } from 'vue'
import { useDictData } from '@/stores/dictData'
import { defaultAttribute } from '@/components/table/defaultAttribute'
import { ElMessage } from 'element-plus'
import { monitorLimitTable, monitorLimitTableDetail } from '@/api/device-boot/dataVerify'
import { mainHeight } from '@/utils/layout'
const dictData = useDictData()
const StatisList = dictData.getBasicData('Steady_Statis')
const dialogVisible = ref(false)
const height1 = mainHeight(-110, 2)
const height = mainHeight(10, 2)
const tableRef = ref()
const title = ref('')
const loading1 = ref(false)
const TableData = ref([])
const TableData1 = ref([])
const pageNum = ref(1)
const pageSize = ref(20)
const numKey = ref(0)
const targetKey = ref('')
const clickRow = ref({})
const open = (data: anyObj, time: string[], num: number) => {
    // title.value = (num == 0 ? data.targetName : data.monitorName) + '_告警详情展示'
    title.value = '告警监测点详情'
    numKey.value = num
    targetKey.value = data.key
    TableData.value = []
    monitorLimitTable({
        monitorIds: num == 0 ? data.ids : [data.monitorId],
        targetKey: num == 0 ? data.key : '',
        searchBeginTime: time[0],
        searchEndTime: time[1]
    }).then(res => {
        TableData.value = res.data
        tableRef.value.setCurrentRow(TableData.value[0])
        currentChangeEvent()
    })
    dialogVisible.value = true
}
const currentChangeEvent = () => {
    loading1.value = true
    clickRow.value = tableRef.value.getCurrentRecord()
    TableData1.value = []
    monitorLimitTableDetail({
        monitorIds: [clickRow.value.monitorId],
        searchBeginTime: clickRow.value.date,
        targetKey: numKey.value == 0 ? targetKey.value : ''
    })
        .then(res => {
            TableData1.value = res.data
            loading1.value = false
            pageNum.value = 1
        })
        .catch(() => {
            loading1.value = false
        })
}
const formatter = (row: any) => {
    if (row.column.field == 'time') {
        return clickRow.value.date + ' ' + row.cellValue
    } else if (row.column.field == 'type') {
        return row.cellValue === 'null' ? '/' : row.cellValue
    } else {
        return row.cellValue == null ? '/' : (row.cellValue - 0).toFixed(2)
    }
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
.table-pagination {
    height: 58px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    background-color: var(--ba-bg-color-overlay);
    padding: 13px 15px;
    border-left: 1px solid #e4e7e9;
    border-right: 1px solid #e4e7e9;
    border-bottom: 1px solid #e4e7e9;
}
:deep(.box) {
    .row--current {
        background-color: var(--el-color-primary-light-8) !important;
    }
}
</style>
