| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <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 { CUSTOMER_ADDED_EDITOR } from "@hooks/useApi"
- import { routingInfos, getRouterImg } from "@utility/generalVariables.js";
- import useRouterStore from "@store/useRouterStore.js";
- import commonUtil from "@utility/commonUtil"
- const router = useRouterStore()
- 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)
- requests.post(CUSTOMER_ADDED_EDITOR, { ...commonUtil.getFromValue({ ...props.formValue, ...res.data }) }).then(() => {
- toastSuccess('保存成功')
- const currentPages = router.$state.currentPages || []
- const parentRoute = (currentPages[currentPages.length - 2] || {}).pathName
- const jumpTo = routingInfos['customer']
- setTimeout(() => {
- if(parentRoute == 'home') {
- router.redirectTo({
- pathName: 'moduleList',
- success: () => {
- router.eventEmit('moduleListRefreshData', {})
- router.emit('moduleListDetailParameter', {
- row: JSON.stringify(jumpTo)
- })
- }
- })
- } else {
- router.navigateBack({
- success: () => {
- router.eventEmit('moduleListRefreshData', {})
- }
- })
- }
- }, 2000)
- // setTimeout(() => {
- // router.navigateBack({
- // success: () => {
- // router.eventEmit('moduleListRefreshData', {})
- // }
- // })
- // }, 2000)
- }).catch(() => {
- toastFail('保存失败')
- })
- })
- }
- useLifecycle({
- load: () => {
- formVal.value = props.formValue
- },
- init: () => {
- formVal.value = props.formValue
- }
- });
- onActivated(() => {
-
- })
- </script>
- <style lang='scss' scoped>
- /* 样式代码 */
- </style>
|