<template>
    <div class="default-main">
        <TableHeader date-picker>
            <template #operation>
                <el-button :icon="Plus" type="primary" @click="addMenu" class="ml10">新增</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
        <detail ref="detail"></detail>
    </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 Detail from './detail.vue'
import { ElMessage } from 'element-plus'
import { deleteUser } from '@/api/cs-device-boot/sensitiveLoadMange'
import { Plus } from '@element-plus/icons-vue'
import { useDictData } from '@/stores/dictData'

defineOptions({
    name: 'govern/device/sensitiveLoadMange'
})
const detail = ref()

const dictData = useDictData()
const interferenceType = dictData.getBasicData('Sensitive_User_Type')

const tableStore: any = new TableStore({
    url: '/cs-harmonic-boot/pqSensitiveUser/getList',
    method: 'POST',
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '所属厂站名称', field: 'substationName', minWidth: 180 },
        { title: '敏感用户名称', field: 'name', minWidth: 180 },
        {
            title: '敏感负荷类型',
            field: 'loadType',
            minWidth: 120,
            formatter: row => {
                return interferenceType.filter(item => item.id == row.cellValue)[0]?.name
            }
        },
        { title: '用户协议容量(MVA)', field: 'userAgreementCapacity', minWidth: 100 },
        { title: '装机容量(MW)', field: 'installedCapacity', minWidth: 100 },
        {
            title: '操作',
            align: 'center',
            width: '180',
            fixed: 'right',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton',
                    click: row => {
                        detail.value.open('编辑', row)
                    }
                },
                {
                    name: 'del',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除吗？'
                    },
                    click: row => {
                        deleteUser([row.id]).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],
    loadCallback: () => {}
})

tableStore.table.params.searchValue = ''
provide('tableStore', tableStore)
onMounted(() => {
    tableStore.index()
})

const addMenu = () => {
    detail.value.open('新增')
}
</script>
