| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <template>
- <BasicModal
- v-bind="$attrs"
- destroyOnClose
- @register="registerModal"
- :title="getTitle"
- :width="width"
- @ok="handleSubmit"
- :showFooter="true"
- >
- <BasicForm @register="registerForm" layout="vertical" />
- </BasicModal>
- </template>
- <script lang="ts" setup>
- import { ref, computed, unref } from 'vue';
- import { BasicModal } from '/@/components/Modal';
- import { useModalInner } from '/@/components/Modal';
- import { BasicForm, useForm } from '/@/components/Form';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { dataFormSchema } from './data';
- import {
- archivesPatrolWardAdd,
- archivesPatrolWardEdit,
- archivesPatrolWardDetail,
- } from '/@/api/biz/archives/patrolWardApi';
- const emit = defineEmits(['success', 'register']);
- const getTitle = computed(() => (!unref(isUpdate) ? '新增查房' : '编辑查房'));
- const width = '45%';
- const isUpdate = ref(false);
- const rowId = ref();
- const { createMessage } = useMessage();
- const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
- labelWidth: 100,
- schemas: dataFormSchema,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 23,
- },
- });
- const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
- await resetFields();
- setModalProps({ confirmLoading: false });
- isUpdate.value = !!data?.isUpdate;
- if (unref(isUpdate)) {
- const resData = await archivesPatrolWardDetail(data.record.id);
- rowId.value = resData.id;
- await setFieldsValue({
- ...resData,
- });
- }
- });
- // 提交按钮事件
- async function handleSubmit() {
- try {
- const values = await validate();
- setModalProps({ confirmLoading: true });
- !unref(isUpdate)
- ? await archivesPatrolWardAdd({ ...values })
- : await archivesPatrolWardEdit({ ...values, id: rowId.value });
- !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
- closeModal();
- emit('success', {
- isUpdate: unref(isUpdate),
- values: { ...values, id: rowId.value },
- });
- } finally {
- setModalProps({ confirmLoading: false });
- }
- }
- </script>
|