<template>
    <my-table url="/api/v1/jobs" rowKey="jobId" :addBtn="addBtn" ref="table" noPage>
        <template #drawer>
            <Form ref="form" />
        </template>
        <!-- <template #search="{ query }">
            <a-form-model-item label="名称">
                <a-input v-model="query.jobName" />
            </a-form-model-item>
        </template> -->

        <a-table-column title="名称" data-index="jobName" />
        <a-table-column title="描述" data-index="jobDescription" />
        <a-table-column title="操作">
            <template #default="row">
                <a @click="() => view(row, 1)">编辑</a>
                <a-divider type="vertical" />
                <PopconfirmDelete :url="`/api/v1/jobs/${row.jobId}`" :cb="refreshTable" />
            </template>
        </a-table-column>
    </my-table>
</template>
<script>
import Form from './form.vue';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';
export default {
    components: { Form, PopconfirmDelete },
    data() {
        return {
            addBtn: { width: 600, onOk: () => this.$refs['form']?.submit() },
        };
    },
    methods: {
        refreshTable() {
            this.$refs['table']?.getData();
        },
        view(data, type) {
            this.$refs['table']?.show({ type });
            this.$nextTick(() => {
                this.$refs['form'].setData({ ...data }, type);
            });
        },
    },
};
</script>