Ben Lin
2024-05-30 7e1c7ea9f47d6fe3fd669672a4bce51ec2758bc3
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
<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>