<template>
|
<BasicDrawer
|
v-bind="$attrs"
|
@register="registerDrawer"
|
showFooter
|
:title="getTitle"
|
width="600px"
|
@ok="handleSubmit"
|
>
|
<BasicForm @register="registerForm" />
|
</BasicDrawer>
|
</template>
|
<script lang="ts" setup>
|
import { ref, computed, unref, onMounted } from 'vue';
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
import { useGlobSetting } from '/@/hooks/setting';
|
import { SaveRegion } from '/@/api/tigerapi/wms/region';
|
import { fetchJson } from '/@/api/tigerapi/system';
|
|
const emit = defineEmits(['success', 'register']);
|
const globSetting = useGlobSetting();
|
const isUpdate = ref(true);
|
const formSchema = ref([]);
|
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
labelWidth: 120,
|
schemas: formSchema as unknown as FormSchema[],
|
actionColOptions: {
|
span: 24,
|
},
|
showActionButtonGroup: false,
|
});
|
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
resetFields();
|
setDrawerProps({ confirmLoading: false });
|
isUpdate.value = !!data?.isUpdate;
|
|
if (unref(isUpdate)) {
|
setFieldsValue({
|
...data.record,
|
});
|
}
|
});
|
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增储区' : '编辑储区'));
|
|
onMounted(async () => {
|
formSchema.value = await fetchJson(`${globSetting.downloadUrl}/LowCode/addEditform.json`);
|
});
|
async function handleSubmit() {
|
try {
|
const values = await validate();
|
setDrawerProps({ confirmLoading: true });
|
// TODO custom api
|
//保存储区
|
const apiAction = SaveRegion(values, unref(isUpdate));
|
apiAction.then((action) => {
|
if (action.IsSuccessed) {
|
closeDrawer();
|
emit('success');
|
}
|
});
|
} finally {
|
setDrawerProps({ confirmLoading: false });
|
}
|
}
|
</script>
|