<template>
    <div class="default-main">
        <div>
            <TableHeader ref="TableHeaderRef">
                <template #select>
                    <el-form-item label="icd名称">
                        <el-input
                            v-model="tableStore.table.params.searchValue"
                            maxlength="32"
                            show-word-limit
                            clearable
                            placeholder="请输入任务名称"
                        />
                    </el-form-item>
                </template>
                <template #operation>
                    <el-button icon="el-icon-Plus" type="primary" @click="add">新增</el-button>
                </template>
            </TableHeader>
            <Table ref="tableRef" />
        </div>
        <!-- 新增 -->
        <taskForm ref="taskFormRef" @submit="tableStore.index()" />
        <!-- 补招 -->
        <el-dialog v-model="dialogVisible" title="选择补招时间" width="500">
            <el-date-picker
                v-model="formDate.date"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="选择日期"
            ></el-date-picker>
            <template #footer>
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="okRun">确认</el-button>
            </template>
        </el-dialog>
    </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 taskForm from './form.vue'
import { formatDate } from '@/utils/formatTime'
import { ElMessage, ElMessageBox, ElDatePicker } from 'element-plus'
import { timerRun, runTimer, deleteTimer, stop, start } from '@/api/system-boot/csDictData'
defineOptions({
    name: 'icd'
})
const formDate = ref({
    date: '',
    id: ''
})
const taskFormRef = ref()
const dialogVisible = ref(false)
const tableStore: any = new TableStore({
    url: '/system-boot/timer/list',
    method: 'POST',
    isWebPaging: true,
    column: [
        { field: 'timerName', title: '文件名' },
        { field: 'actionClass', title: '存储地址' },
        { field: 'cron', title: '更新时间' },

        {
            title: '操作',
            width: '220',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton',

                    click: async row => {
                        taskFormRef.value.open('编辑icd文件', row)
                    }
                },

                {
                    name: 'del',
                    text: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除？'
                    },
                    click: row => {
                        deleteTimer([row.id]).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],

    loadCallback: () => {}
})
tableStore.table.params.searchValue = ''
tableStore.table.params.searchState = ''

provide('tableStore', tableStore)

const add = () => {
    setTimeout(() => {
        taskFormRef.value.open('新增icd文件')
    }, 10)
}
const okRun = () => {
    runTimer(formDate.value).then(res => {
        ElMessage.success('操作成功')
        dialogVisible.value = false
        tableStore.index()
    })
}
onMounted(() => {
    tableStore.index()
})
</script>
