addEditor.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 { CONTRACT_ADDITION_EDITING } from "@hooks/useApi"
  20. const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
  21. const props = defineProps({
  22. formJson: { required: true },
  23. formValue: { required: true },
  24. });
  25. const formFormRef = ref(null)
  26. const formVal = ref({})
  27. function onSubmit() {
  28. formFormRef.value.getJsonData().then((res) => {
  29. if(!res.data) {
  30. return
  31. }
  32. toastLoading('保存中', 0)
  33. requests.post(CONTRACT_ADDITION_EDITING, { ...props.formValue, ...res.data }).then(() => {
  34. toastSuccess('保存成功')
  35. setTimeout(() => {
  36. history.back();
  37. }, 2000)
  38. }).catch(() => {
  39. toastFail('保存失败')
  40. })
  41. })
  42. }
  43. useLifecycle({
  44. load: () => {
  45. formVal.value = props.formValue
  46. },
  47. init: () => {
  48. formVal.value = props.formValue
  49. }
  50. });
  51. onActivated(() => {
  52. })
  53. </script>
  54. <style lang='scss' scoped>
  55. /* 样式代码 */
  56. </style>