123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <template>
- <div class="w-full h-full flex flex-col">
- <div class="flex-1 overflow-y-auto">
- <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
- </div>
- <div class="mar-20px ">
- <van-button type="primary" @click="onSubmit" class="w-full">
- {{ Object.keys(formVal).length > 0 ? '确定修改' : '确定添加' }}
- </van-button>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, onActivated } from 'vue';
- import { useLifecycle } from '@hooks/useCommon.js';
- import CustomerForm from '@components/common/formForm/formView.vue'
- import requests from "@common/requests";
- import useToast from "@hooks/useToast"
- import { CONTACT_PERSON_ADDITION_EDITOR } from "@hooks/useApi"
- const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
- const props = defineProps({
- formJson: { required: true },
- formValue: { required: true },
- });
- const formFormRef = ref(null)
- const formVal = ref({})
- function onSubmit() {
- formFormRef.value.getJsonData().then((res) => {
- if(!res.data) {
- return
- }
- toastLoading('保存中', 0)
- const url = props.formValue.id ? '/contacts/updateContacts' : CUSTOMER_ADDED_EDITOR
- requests.post(url, { ...props.formValue, ...res.data }).then(() => {
- toastSuccess('保存成功')
- setTimeout(() => {
- history.back();
- }, 2000)
- }).catch((err) => {
- toastFail('保存失败:' + err.msg)
- })
- })
- }
- useLifecycle({
- load: () => {
- formVal.value = props.formValue
- },
- init: () => {
- formVal.value = props.formValue
- }
- });
- onActivated(() => {
-
- })
- </script>
- <style lang='scss' scoped>
- /* 样式代码 */
- </style>
|