addEditor.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="w-full h-full flex flex-col">
  3. <div class="flex-1 overflow-y-auto">
  4. <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
  5. </div>
  6. <div class="mar-20px ">
  7. <van-button type="primary" @click="onSubmit" class="w-full">
  8. {{ Object.keys(formVal).length > 0 ? '确定修改' : '确定添加' }}
  9. </van-button>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup>
  14. import { ref, onActivated } from 'vue';
  15. import { useLifecycle } from '@hooks/useCommon.js';
  16. import CustomerForm from '@components/common/formForm/formView.vue'
  17. import requests from "@common/requests";
  18. import useToast from "@hooks/useToast"
  19. import { CUSTOMER_ADDED_EDITOR } from "@hooks/useApi"
  20. import useRouterStore from "@store/useRouterStore.js";
  21. const router = useRouterStore()
  22. const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
  23. const props = defineProps({
  24. formJson: { required: true },
  25. formValue: { required: true },
  26. });
  27. const formFormRef = ref(null)
  28. const formVal = ref({})
  29. function onSubmit() {
  30. formFormRef.value.getJsonData().then((res) => {
  31. if(!res.data) {
  32. return
  33. }
  34. toastLoading('保存中', 0)
  35. requests.post(CUSTOMER_ADDED_EDITOR, { ...props.formValue, ...res.data }).then(() => {
  36. toastSuccess('保存成功')
  37. setTimeout(() => {
  38. router.navigateBack({
  39. success: () => {
  40. router.eventEmit('moduleListRefreshData', {})
  41. }
  42. })
  43. }, 2000)
  44. }).catch(() => {
  45. toastFail('保存失败')
  46. })
  47. })
  48. }
  49. useLifecycle({
  50. load: () => {
  51. formVal.value = props.formValue
  52. },
  53. init: () => {
  54. formVal.value = props.formValue
  55. }
  56. });
  57. onActivated(() => {
  58. })
  59. </script>
  60. <style lang='scss' scoped>
  61. /* 样式代码 */
  62. </style>