<template>
    <Wraper :hidden="hidden" :refresh="refresh" :onOk="submit">
        <a-form-model layout="vertical" :model="form" :rules="rules" ref="form">
            <a-form-model-item :label="$t('system.jobName')" prop="jobName">
                <a-input v-model="form.jobName" />
            </a-form-model-item>
            <a-form-model-item :label="$t('table.describe')" prop="jobDescription">
                <a-textarea v-model="form.jobDescription" :rows="4" />
            </a-form-model-item>
        </a-form-model>
    </Wraper>
</template>

<script>
import JobsApi from '@/api/organization';
import { WraperMixins } from '@/components/table';

export default {
    mixins: [WraperMixins],
    data() {
        return {
            rules: {
                jobName: [{ required: true, message: this.$t('system.jobName.add'), trigger: 'change' }],
                jobDescription: [
                    { required: true, message: this.$t('table.describe.add'), trigger: 'change' },
                ],
            },
        };
    },
    mounted() {
        if (this.row) {
            this.form = { ...this.row };
        }
    },
    computed: {
        isEdit() {
            return this.type === 'edit';
        },
        isAdd() {
            return this.type === null;
        },
    },
    methods: {
        async submit() {
            await this.$refs.form.validate();
            if (this.isAdd) return JobsApi.addJobs({ ...this.form });
            if (this.isEdit) return JobsApi.updateJobs({ ...this.form });
        },
    },
};
</script>
