<template>
    <TableHeader datePicker ref="refheader" showExport>
        <template v-slot:select>
            <!-- <el-form-item label="数据来源">
                <el-cascader v-model.trim="tableStore.table.params.cascader" filterable placeholder="请选择数据来源"
                    @change="sourceChange" :options="deviceTreeOptions" :show-all-levels="false"
                    :props="{ checkStrictly: true, value: 'id', label: 'name' }" clearable></el-cascader>
            </el-form-item> -->
            <el-form-item label="关键字筛选">
                    <el-input maxlength="32" show-word-limit style="width: 240px"
                        v-model.trim="tableStore.table.params.searchValue" clearable placeholder="请输入监测点名称" />
                </el-form-item>
            <!-- <el-form-item label="级别">
                <el-select v-model.trim="tableStore.table.params.level" placeholder="请选择级别" clearable>
                    <el-option
                        v-for="item in rankOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item> -->
        </template>
    </TableHeader>
    <!-- <div style="height: 300px;"> -->
    <Table ref="tableRef" :isGroup="true" />
    <!-- </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 { mainHeight } from '@/utils/layout'

const props = defineProps(['deviceTree'])

const refheader = ref()
const deviceTree = ref([])
const tabsList = ref([
    {
        label: '设备告警',
        name: 3
    },
    {
        label: '稳态越限告警',
        name: 1
    },
    {
        label: '暂态事件',
        name: 0
    }
])
const rankOptions = ref([
    {
        value: '1',
        label: '1级'
    },
    {
        value: '2',
        label: '2级'
    },
    {
        value: '3',
        label: '3级'
    }
])

const tableStore = new TableStore({
    url: '/cs-harmonic-boot/eventUser/queryEventpageWeb',
    method: 'POST',
    exportName: '稳态越限告警',
    publicHeight: 65,
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '发生时刻', field: 'startTime', align: 'center', sortable: true, minWidth: 180, },
        { title: '监测点名称', field: 'lineName', align: 'center', minWidth: 150,formatter: (row: any) => {
                return row.cellValue ? row.cellValue : '/'
            } },
        { title: '设备名称', field: 'equipmentName', align: 'center', minWidth: 150, },
        { title: '项目名称', field: 'projectName', align: 'center', minWidth: 150, },
        { title: '工程名称', field: 'engineeringName', align: 'center', minWidth: 150, },


        { title: '事件描述', field: 'showName', align: 'center', minWidth: 250, }
    ],
    beforeSearchFun: () => { }
})

provide('tableStore', tableStore)
//   "target": [],
//   "type": "",
//   "userId": ""
tableStore.table.params.searchValue = ''
// tableStore.table.params.engineeringid = ''
// tableStore.table.params.deviceTypeId = ''
// tableStore.table.params.projectId = ''
// tableStore.table.params.deviceId = ''
tableStore.table.params.type = 1
// tableStore.table.params.eventIds = []
// tableStore.table.params.status = ''
// tableStore.table.params.target = []
// tableStore.table.params.userId = ''
// tableStore.table.params.cascader = ''
// tableStore.table.params.deviceTypeName = ''
// tableStore.table.params.level=''

const deviceTreeOptions = ref<any>(props.deviceTree)
deviceTreeOptions.value.map((item: any, index: any) => {
    if (item?.children.length == 0) {
        deviceTreeOptions.value.splice(index, 1)
    }
})
const sourceChange = (e: any) => {
    tableStore.table.params.deviceTypeId = ''
    tableStore.table.params.engineeringid = ''
    tableStore.table.params.projectId = ''
    tableStore.table.params.deviceId = ''
    if (e) {
        let name = deviceTreeOptions.value.filter((item: any) => {
            return item.id == e[0]
        })[0].name
        tableStore.table.params.deviceTypeName = name
        if (name == '便携式设备') {
            tableStore.table.params.deviceTypeId = e[0] || ''
            tableStore.table.params.deviceId = e[1] || ''
        } else {
            tableStore.table.params.deviceTypeId = e[0] || ''
            tableStore.table.params.engineeringid = e[1] || ''
            tableStore.table.params.projectId = e[2] || ''
            tableStore.table.params.deviceId = e[3] || ''
        }
    }
}
onMounted(() => {
    tableStore.index()
})
setTimeout(() => {
    tableStore.table.height = mainHeight(200).height as any
}, 0)
const addMenu = () => { }
</script>
<style></style>
