addEditor.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { CONTACT_PERSON_ADDITION_EDITOR } 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. const url = props.formValue.id ? '/contacts/updateContacts' : CUSTOMER_ADDED_EDITOR
  34. requests.post(url, { ...props.formValue, ...res.data }).then(() => {
  35. toastSuccess('保存成功')
  36. setTimeout(() => {
  37. history.back();
  38. }, 2000)
  39. }).catch((err) => {
  40. toastFail('保存失败:' + err.msg)
  41. })
  42. })
  43. }
  44. useLifecycle({
  45. load: () => {
  46. formVal.value = props.formValue
  47. },
  48. init: () => {
  49. formVal.value = props.formValue
  50. }
  51. });
  52. onActivated(() => {
  53. })
  54. </script>
  55. <style lang='scss' scoped>
  56. /* 样式代码 */
  57. </style>