<template>
    <div class="default-main">
        <TableHeader datePicker ref="refheader" showExport>
            <template v-slot:select></template>
        </TableHeader>
        <Table ref="tableRef" />
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { queryByCode, queryByid, queryCsDictTree } from '@/api/system-boot/dictTree'
const refheader = ref()
const devModelOptions: any = ref([])
queryByCode('Device_Type').then(res => {
    queryByid(res.data.id).then(res => {
        devModelOptions.value = res.data.map((item: any) => {
            return {
                value: item.id,
                label: item.name,
                ...item
            }
        })
    })
    tableStore.index()
})
const tableStore = new TableStore({
    url: '/cs-harmonic-boot/statisticsData/halfMonthReport',
    method: 'POST',
    isWebPaging: true,
    exportName: '半月报功能',
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '工程名称', field: 'engineeringName' },
        { title: '项目名称', field: 'projectName' },
        { title: '设备名称', field: 'devName' },
        {
            title: '设备型号',
            field: 'devType',
            formatter: row => {
                return devModelOptions.value.filter((item: any) => item.value == row.cellValue)[0]?.label
            }
        },
        { title: 'Mac地址', field: 'mac' },
        { title: '监测点名称', field: 'lineName' },
        {
            title: '运行状态',
            field: 'operationalStatus',
            render: 'tag',
            custom: {
                停运: 'danger',
                在运: 'success'
            },
            replaceValue: {
                在运: '在运',
                停运: '停运'
            }
        },
        {
            title: '通讯状态',
            field: 'communicationStatus',
            width: 100,
            render: 'tag',
            custom: {
                离线: 'danger',
                在线: 'success'
            },
            replaceValue: {
                离线: '离线',
                在线: '在线'
            }
        },
        {
            title: '投运时间',
            field: 'operationalTime',
            width: 160
        },
        {
            title: '数据更新时间',
            field: 'latestTime',
            width: 160,
            formatter: (row: any) => {
                return row.cellValue || '/'
            }
        },
        { title: '在线率(%)', field: 'onlineRate' },
        { title: '完整性(%)', field: 'integrity' }
    ],
    beforeSearchFun: () => {}
})

provide('tableStore', tableStore)
//   "target": [],
//   "type": "",
//   "userId": ""

onMounted(() => {})
setTimeout(() => {
    // tableStore.table.height = mainHeight(200).height as any
}, 0)
const addMenu = () => {}
</script>
<style></style>
