|
@@ -10,7 +10,7 @@
|
|
<BasicForm @register="registerForm" />
|
|
<BasicForm @register="registerForm" />
|
|
</BasicModal>
|
|
</BasicModal>
|
|
</template>
|
|
</template>
|
|
-<script lang="ts">
|
|
|
|
|
|
+<script lang="ts" setup>
|
|
import { defineComponent, ref, computed, unref } from 'vue';
|
|
import { defineComponent, ref, computed, unref } from 'vue';
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
|
@@ -26,7 +26,7 @@
|
|
} from '/@/api/system/department';
|
|
} from '/@/api/system/department';
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
const { t } = useI18n();
|
|
const { t } = useI18n();
|
|
- export const formSchema: FormSchema[] = [
|
|
|
|
|
|
+ const formSchema: FormSchema[] = [
|
|
{
|
|
{
|
|
field: 'name',
|
|
field: 'name',
|
|
label: t('组织名称'),
|
|
label: t('组织名称'),
|
|
@@ -124,78 +124,66 @@
|
|
},
|
|
},
|
|
];
|
|
];
|
|
|
|
|
|
- export default defineComponent({
|
|
|
|
- name: 'DeptDrawer',
|
|
|
|
- components: { BasicModal, BasicForm },
|
|
|
|
- emits: ['success', 'register'],
|
|
|
|
- setup(_, { emit }) {
|
|
|
|
- const isUpdate = ref(true);
|
|
|
|
- const { notification } = useMessage();
|
|
|
|
- const rowId = ref('');
|
|
|
|
|
|
+ const emit = defineEmits(['success', 'register']);
|
|
|
|
|
|
- const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
|
|
|
|
- labelWidth: 100,
|
|
|
|
- schemas: formSchema,
|
|
|
|
- showActionButtonGroup: false,
|
|
|
|
- baseColProps: { lg: 12, md: 24 },
|
|
|
|
- });
|
|
|
|
- const [registerDrawer, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
|
|
|
- resetFields();
|
|
|
|
- setModalProps({ confirmLoading: false });
|
|
|
|
- isUpdate.value = !!data?.isUpdate;
|
|
|
|
|
|
+ const isUpdate = ref(true);
|
|
|
|
+ const { notification } = useMessage();
|
|
|
|
+ const rowId = ref('');
|
|
|
|
+
|
|
|
|
+ const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
|
|
|
|
+ labelWidth: 100,
|
|
|
|
+ schemas: formSchema,
|
|
|
|
+ showActionButtonGroup: false,
|
|
|
|
+ baseColProps: { lg: 12, md: 24 },
|
|
|
|
+ });
|
|
|
|
+ const [registerDrawer, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
|
|
|
+ resetFields();
|
|
|
|
+ setModalProps({ confirmLoading: false });
|
|
|
|
+ isUpdate.value = !!data?.isUpdate;
|
|
|
|
|
|
- const treeData = await getDepartmentTree();
|
|
|
|
- updateSchema({
|
|
|
|
- field: 'parentId',
|
|
|
|
- componentProps: { treeData },
|
|
|
|
- });
|
|
|
|
- if (unref(isUpdate)) {
|
|
|
|
- rowId.value = data.record.id;
|
|
|
|
|
|
+ const treeData = await getDepartmentTree();
|
|
|
|
+ updateSchema({
|
|
|
|
+ field: 'parentId',
|
|
|
|
+ componentProps: { treeData },
|
|
|
|
+ });
|
|
|
|
+ if (unref(isUpdate)) {
|
|
|
|
+ rowId.value = data.record.id;
|
|
|
|
|
|
- const _data = await getDepartment(data.record.id);
|
|
|
|
|
|
+ const _data = await getDepartment(data.record.id);
|
|
|
|
|
|
- setFieldsValue({
|
|
|
|
- ..._data,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ setFieldsValue({
|
|
|
|
+ ..._data,
|
|
});
|
|
});
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- const getTitle = computed(() => (!unref(isUpdate) ? t('新增组织') : t('编辑组织')));
|
|
|
|
|
|
+ const getTitle = computed(() => (!unref(isUpdate) ? t('新增组织') : t('编辑组织')));
|
|
|
|
|
|
- async function handleSubmit() {
|
|
|
|
- try {
|
|
|
|
- const values = await validate();
|
|
|
|
|
|
+ async function handleSubmit() {
|
|
|
|
+ try {
|
|
|
|
+ const values = await validate();
|
|
|
|
|
|
- setModalProps({ confirmLoading: true });
|
|
|
|
- // TODO custom api
|
|
|
|
- if (!unref(isUpdate)) {
|
|
|
|
- //false 新增
|
|
|
|
- await addDepartment(values);
|
|
|
|
- notification.success({
|
|
|
|
- message: t('提示'),
|
|
|
|
- description: t('新增成功'),
|
|
|
|
- }); //提示消息
|
|
|
|
- } else {
|
|
|
|
- values.id = rowId.value;
|
|
|
|
- await updateDepartment(values);
|
|
|
|
- notification.success({
|
|
|
|
- message: t('提示'),
|
|
|
|
- description: t('编辑成功'),
|
|
|
|
- }); //提示消息
|
|
|
|
- }
|
|
|
|
- closeModal();
|
|
|
|
- emit('success');
|
|
|
|
- } catch (error) {
|
|
|
|
- setModalProps({ confirmLoading: false });
|
|
|
|
- }
|
|
|
|
|
|
+ setModalProps({ confirmLoading: true });
|
|
|
|
+ // TODO custom api
|
|
|
|
+ if (!unref(isUpdate)) {
|
|
|
|
+ //false 新增
|
|
|
|
+ await addDepartment(values);
|
|
|
|
+ notification.success({
|
|
|
|
+ message: t('提示'),
|
|
|
|
+ description: t('新增成功'),
|
|
|
|
+ }); //提示消息
|
|
|
|
+ } else {
|
|
|
|
+ values.id = rowId.value;
|
|
|
|
+ await updateDepartment(values);
|
|
|
|
+ notification.success({
|
|
|
|
+ message: t('提示'),
|
|
|
|
+ description: t('编辑成功'),
|
|
|
|
+ }); //提示消息
|
|
}
|
|
}
|
|
-
|
|
|
|
- return {
|
|
|
|
- registerDrawer,
|
|
|
|
- registerForm,
|
|
|
|
- getTitle,
|
|
|
|
- handleSubmit,
|
|
|
|
- };
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
|
|
+ closeModal();
|
|
|
|
+ emit('success');
|
|
|
|
+ } catch (error) {
|
|
|
|
+ setModalProps({ confirmLoading: false });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
</script>
|
|
</script>
|