<template>
    <a-modal ref="drawerRef" :visible="visible" title="新增组织" @ok="submit" @cancel="close">
        <a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm">
            <a-form-model-item label="组织" prop="catalogValue">
                <OrganizationTree v-model="form.catalogValue" :disabled="isView" />
            </a-form-model-item>
        </a-form-model>
    </a-modal>
</template>

<script>
import FormMixin from '@/components/FormMixin';
import Api from '@/api/oceanus';
import OrganizationTree from './OrganizationTree.vue';

export default {
    components: { OrganizationTree },
    props: {
        afterSubmit: Function,
        parentNodeId: [String, Number],
    },
    watch: {
        parentNodeId(val) {
            this.parentId = val;
        },
    },
    mixins: [FormMixin],
    data() {
        return {
            visible: false,
            parentId: undefined,
            form: {},
            rules: {
                catalogValue: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
            },
            Api,
        };
    },
    async mounted() {},
    methods: {
        open() {
            this.form = {};
            this.visible = true;
        },
        async add() {
            const data = {
                ...this.form,
                catalogType: 'ORGANIZATION',
                parentCatalogId: this.parentId + '',
            };
            await Api.addEquipmentsTree({ catalogForm: data });
            this.close();
            this.afterSubmit && this.afterSubmit();
        },
        close() {
            this.form = {};
            this.visible = false;
        },
    },
};
</script>
