<template>
    <my-table url="/api/v1/schedules" rowKey="taskId" :addBtn="addBtn" ref="table">
        <template #drawer>
            <Form ref="form" />
        </template>
        <a-table-column title="任务名称" data-index="taskName" />
        <a-table-column title="调度规则" data-index="taskRule" />
        <a-table-column title="实现类" data-index="implementClass" />
        <a-table-column title="说明" data-index="remark" />
        <a-table-column title="操作">
            <template #default="row">
                <ActionButton :buttons="buttons" :row="row" />
            </template>
        </a-table-column>
    </my-table>
</template>

<script>
import ActionButton from '@/components/action_button/index.vue';
import Form from './form.vue';

export default {
    components: { ActionButton, Form },
    data() {
        return {
            addBtn: {},
            buttons: [
                {
                    label: '查看',
                    click: row => {
                        this.showDrawer(2, true);
                        this.$nextTick(() => {
                            this.$refs['form'].setData(row, 2);
                        });
                    },
                },
                {
                    label: '编辑',
                    click: row => {
                        this.showDrawer(1);
                        this.$nextTick(() => {
                            this.$refs['form'].setData(row, 1);
                        });
                    },
                },
                {
                    type: 'confirm',
                    label: '失效',
                    title: '确认是否失效?',
                    url: row => `/api/v1/schedules/${row.taskId}`,
                    after: () => this.refreshTable(),
                },
                {
                    type: 'confirm',
                    url: row => `/api/v1/schedules/${row.taskId}`,
                    after: () => this.refreshTable(),
                },
            ],
        };
    },
    methods: {
        refreshTable() {
            this.$refs.table.getData();
        },
        showDrawer(type, noFooter) {
            this.$refs['table'].show({ type, noFooter });
        },
    },
};
</script>
