<template>
    <div>
        <!--主要监测点列表 -->
        <TableHeader :showReset="false" ref="TableHeaderRef">
            <template v-slot:select>
                <el-form-item>
                    <el-input v-model="tableStore.table.params.searchValue" placeholder="请输入"></el-input>
                </el-form-item>
            </template>
        </TableHeader>
        <Table ref="tableRef" @cell-click="handleCellClick"></Table>
        <!-- 弹框组件 -->
        <el-dialog v-model="dialogVisible" title="详情信息" width="800px" append-to-body destroy-on-close>
            <p>行数据: {{ selectedRow }}</p>
            <p>列数据: {{ selectedColumn }}</p>
        </el-dialog>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, reactive, watch } from 'vue'

import TableStore from '@/utils/tableStore'
import Table from '@/components/table/indexClick.vue'
import TableHeader from '@/components/table/header/index.vue'
import { useDictData } from '@/stores/dictData'
import { getTimeOfTheMonth } from '@/utils/formatTime'
const prop = defineProps({
    width: { type: String },
    height: { type: String },
    timeKey: { type: String }
})
const dictData = useDictData()
const fontdveoption = dictData.getBasicData('Dev_Ops')
const dialogVisible = ref(false)
const selectedRow = ref(null)
const selectedColumn = ref(null)

const tableStore: any = new TableStore({
    url: '/device-boot/pqsTerminalLogs/getList',
    method: 'POST',
    column: [
        {
            field: 'index',
            title: '序号',
            width: '60',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '名称', field: 'createBy', width: '200', clickable: true },
        {
            title: '日志类型',
            field: 'logsType',
            width: '100',
            formatter: (row: any) => {
                return fontdveoption.find((item: any) => item.id == row.cellValue)?.name
            }
        },

        // {
        //     title: '更改人员',
        //     field: 'createBy',
        //     width: '100'
        // },
        {
            title: '更改时间',
            field: 'updateTime',
            width: '140'
        },

        { title: '描述', field: 'terminalDescribe' }
    ],
    beforeSearchFun: () => {
        const timeKey = prop.timeKey ?? ''
        tableStore.table.params.searchBeginTime = getTimeOfTheMonth(timeKey)[0]
        tableStore.table.params.searchEndTime = getTimeOfTheMonth(timeKey)[1]
    },
    loadCallback: () => {
        tableStore.table.height = `calc(${prop.height} - 80px)`
    }
})

const tableRef = ref()
provide('tableRef', tableRef)
tableStore.table.params.type = ''
tableStore.table.params.searchValue = ''
provide('tableStore', tableStore)

onMounted(() => {
    tableStore.index()
})

const handleCellClick = (row: any, column: any) => {
    selectedRow.value = row
    selectedColumn.value = column
    dialogVisible.value = true
}

watch(
    () => prop.timeKey,
    val => {
        tableStore.index()
    }
)
</script>
<style lang="scss" scoped></style>
