<template>
    <div>
        <div>
            <TableHeader datePicker ref="TableHeaderRef">
                <template #select>
                    <el-form-item label="筛选数据">
                        <el-input
                            v-model="tableStore.table.params.searchValue"
                            clearable
                            placeholder="请选择筛选数据"
                        ></el-input>
                    </el-form-item>

                    <el-form-item label="事务类型:">
                        <el-select v-model="tableStore.table.params.type" clearable placeholder="请选择事务类型">
                            <el-option
                                v-for="item in affairs"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属流程:">
                        <el-select v-model="tableStore.table.params.searchState" placeholder="请选择所属流程">
                            <el-option
                                v-for="item in process"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </template>
                <template #operation>
                    <el-button icon="el-icon-Plus" type="primary" @click="add">新建</el-button>
                    <el-button icon="el-icon-Plus" type="primary" @click="add">上传模板</el-button>
                </template>
            </TableHeader>
            <Table ref="tableRef" />
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { mainHeight } from '@/utils/layout'
import { useDictData } from '@/stores/dictData'
import { addUse, updateUse, removeUse } from '@/api/advance-boot/bearingCapacity'

const dictData = useDictData()
const process = [
    {
        name: '开始',
        id: '0'
    },
    {
        name: '预/告警单下发',
        id: '1'
    },
    {
        name: '反馈单上传',
        id: '2'
    },
    {
        name: '现场测试',
        id: '3'
    },
    {
        name: '整改通知单下发',
        id: '4'
    },
    {
        name: '整改通知单反馈',
        id: '5'
    },
    {
        name: '完结',
        id: '6'
    }
]
const affairs = [
    {
        name: '预警单',
        id: '0'
    },
    {
        name: '告警单',
        id: '1'
    }
]
const dialogVisible = ref(false)
const TableHeaderRef = ref()
const title = ref('')

const ruleFormRef = ref()
const tableStore = new TableStore({
    url: '/system-boot/area/areaSelect',
    publicHeight: 65,
    method: 'POST',
    column: [
        { field: 'name', title: '名称' },
        {
            field: 'grade',
            title: '等级'
        },
        { field: 'bigType', title: '策略选择' },
        { field: 'updateBy', title: '更新人员' },
        { field: 'updateTime', title: '更新时间' },
        {
            field: 'state',
            title: '状态',
            activeValue: '2',
            inactiveValue: '1',
            render: 'switch',
            onChangeField: (row: any, value) => {
                console.log('🚀 ~ row:', 444123, value)
            }
        },

        {
            title: '操作',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '绑定',
                    type: 'primary',

                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {}
                },
                {
                    name: 'edit',
                    title: '编辑',
                    type: '',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: async row => {}
                },
                {
                    name: 'del',
                    text: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除？'
                    },
                    click: row => {
                        removeUse({ userIds: row.userId }).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],

    loadCallback: () => {
        tableStore.table.data = []
    }
})

tableStore.table.params.searchState = ''
tableStore.table.params.searchValue = ''
tableStore.table.params.type = ''

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

// 新增
const add = () => {
    title.value = '新增告警单'
    dialogVisible.value = true
}
</script>
