68 lines
2.3 KiB
Vue
68 lines
2.3 KiB
Vue
<template>
|
|
<BasicModal @register="registerModal" :title="title" @ok="handleSubmit">
|
|
<BasicForm @register="registerForm" />
|
|
</BasicModal>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import BasicForm from '/@/components/Form/src/BasicForm.vue';
|
|
import { useForm } from '/@/components/Form';
|
|
import { managerSchema } from '/@/views/emergency/emergencyManage/emergencyManage.data';
|
|
import BasicModal from '/@/components/Modal/src/BasicModal.vue';
|
|
import { useModalInner } from '/@/components/Modal';
|
|
import { ref } from 'vue';
|
|
import { addCenterAdminApi, updateAdminApi } from '/@/views/emergency/emergencyManage/emergencyManage.api';
|
|
import { dealParams } from '/@/views/system/user/user.data';
|
|
|
|
const emit = defineEmits(['success']);
|
|
const title = ref('');
|
|
|
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
|
await resetFields();
|
|
await setFieldsValue({ ...data.record });
|
|
await clearValidate();
|
|
if (data.isUpdate) {
|
|
await updateSchema({
|
|
field: 'username',
|
|
componentProps: () => {
|
|
return {
|
|
disabled: true,
|
|
};
|
|
},
|
|
});
|
|
} else {
|
|
await updateSchema({
|
|
field: 'username',
|
|
componentProps: () => {
|
|
return {
|
|
disabled: false,
|
|
};
|
|
},
|
|
});
|
|
}
|
|
title.value = data.title;
|
|
});
|
|
|
|
const [registerForm, { setFieldsValue, validate, resetFields, clearValidate, updateSchema }] = useForm({
|
|
schemas: managerSchema,
|
|
showActionButtonGroup: false,
|
|
});
|
|
|
|
async function handleSubmit() {
|
|
try {
|
|
const values = await validate();
|
|
setModalProps({ confirmLoading: true });
|
|
if (values?.id) {
|
|
await updateAdminApi(values);
|
|
} else {
|
|
await addCenterAdminApi(dealParams(values));
|
|
}
|
|
setModalProps({ confirmLoading: false });
|
|
emit('success');
|
|
closeModal();
|
|
} catch {
|
|
setModalProps({ confirmLoading: false });
|
|
}
|
|
}
|
|
</script>
|
|
<style scoped lang="less"></style>
|