planModal.vue
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<div>
<BasicModal
v-bind="$attrs"
width="30rem"
:title="getTitle"
@register="register"
@cancel="handleCancel"
@ok="handleOk"
destroyOnClose
>
<div>
<BasicForm @register="registerForm" />
</div>
</BasicModal>
</div>
</template>
<script setup lang="ts">
import {BasicModal, useModalInner} from "/@/components/Modal";
import {BasicForm, useForm} from "/@/components/Form";
import {computed, ref, unref} from "vue";
import {useI18n} from "/@/hooks/web/useI18n";
import {schemas} from "../index";
import {equipmentPlanCategory} from "/@/api/equipment/chenkPlan";
import {useMessage} from "/@/hooks/web/useMessage";
const { t } = useI18n();
const { createMessage } = useMessage();
const emit = defineEmits(['handleReload', 'register']);
const recordInfo = ref<any>({});
const isUpdate = ref<Boolean>(false);
const getTitle = computed(() =>
!unref(isUpdate)
? t('equipment.checkPlan.createCategoryText')
: t('equipment.checkPlan.editCategoryText')
);
const [registerForm, { getFieldsValue, setFieldsValue, validate }] = useForm({
labelWidth: 140,
schemas,
actionColOptions: {
span: 14,
},
showActionButtonGroup: false,
});
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false, loading: true });
isUpdate.value = data?.isUpdate;
recordInfo.value = data?.record;
if (data?.record) {
setFieldsValue(data?.record);
}
setModalProps({ loading: false });
});
const handleCancel = () => {
closeModal();
};
const handleOk = async () => {
await validate();
let values = getFieldsValue();
if (unref(isUpdate)) {
values = { ...values, id: unref(recordInfo).id };
}
await equipmentPlanCategory(values);
createMessage.success(t('common.operationSuccessText'));
emit('handleReload');
handleCancel();
};
</script>