<template>
    <div>
        <TableHeader datePicker showExport>
            <template v-slot:select>
                <el-form-item label="关键字筛选">
                    <el-input maxlength="32" show-word-limit v-model.trim="tableStore.table.params.searchValue"
                        placeholder="请输入设备、监测点名称" />
                </el-form-item>
                <el-form-item label="级别">
                    <el-select v-model="levelFilter" multiple clearable collapse-tags placeholder="请选择级别">
                        <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>
        <Table ref="tableRef" :isGroup="true" />
    </div>
</template>
<script setup lang="ts">
import { Plus } from '@element-plus/icons-vue'
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'

defineOptions({
    name: 'govern/log/debug'
})
const rankOptions = ref([
    // {
    //     value: '1',
    //     label: '1级'
    // },
    // {
    //     value: '2',
    //     label: '2级'
    // },
    // {
    //     value: '3',
    //     label: '3级'
    // },
    // {
    //     value: '3',
    //     label: '3级'
    // },
    {
        value: '4',
        label: 'DEBUG'
    },
    {
        value: '5',
        label: 'NORMAL'
    },
    {
        value: '6',
        label: 'WARN'
    },
    {
        value: '7',
        label: 'ERROR'
    }

])
const levelFilter = ref<string[]>([])
const tableStore = new TableStore({
    url: '/cs-harmonic-boot/event/getFrontDebugLogs',
    method: 'POST',
    publicHeight: 65,
    column: [
        {
            field: 'index',
            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, width: 180 },
        { title: '设备名称', field: 'deviceName', align: 'center', width: 180 },
        {
            title: '监测点名称', field: 'lineName', align: 'center', width: 180, formatter: (row: any) => {
                return row.cellValue ? row.cellValue : '/'
            }
        },

        // { title: '操作用户', field: 'operatorName', align: 'center' },
        {
            title: '调试内容',
            field: 'event',
            align: 'center',
            minWidth: 250,

        },
        {
            title: '级别',
            field: 'level',
            width: 110,
            render: 'tag',
            custom: {
                // 1:Ⅰ级 2:Ⅱ级 3:Ⅲ级 4:DEBUG 5:NORMAL 6:WARN 7:ERROR

                // 1: 'danger',
                // 2: 'warning',
                // 3: 'success',
                4: 'success',
                5: 'success',
                6: 'warning',
                7: 'danger'
            },
            replaceValue: {
                // 1: '1级',
                // 2: '2级',
                // 3: '3级',
                4: 'DEBUG',
                5: 'NORMAL',
                6: 'WARN',
                7: 'ERROR'
            }
        }
        // {
        //     title: '结束时间',
        //     field: 'endTime',
        //     align: 'center',
        //     sortable: true,
        //     formatter: (row: any) => {
        //         return row.cellValue || '/'
        //     }
        // }
    ],

    beforeSearchFun: () => {
        tableStore.table.params.level = levelFilter.value.length ? levelFilter.value.join(',') : ''
    },
    resetCallback: () => {
        levelFilter.value = []
    },
    loadCallback: () => {
        tableStore.table.data.forEach((item: any) => {
            item.result = item.result === 1 ? '成功' : '失败'
            // for (let key in item) {
            //     if (typeof item[key] !== 'number') {
            //         item[key] = item[key] || '/'
            //     }
            // }
        })
    }
})

provide('tableStore', tableStore)
tableStore.table.params.searchState = 0
tableStore.table.params.sortBy = ''
tableStore.table.params.orderBy = ''
tableStore.table.params.searchValue = ''
onMounted(() => {
    tableStore.index()
})
tableStore.table.params.level = ''
const addMenu = () => { }
</script>
