index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <Page :title="`${currentRoutingInformation?.name}${addOrEdit ? '编辑' : '新增'}`">
  3. <template v-slot:body>
  4. <div class="w-full h-full">
  5. <van-skeleton title :row="10" v-if="pageLoading" class="w-full h-full" />
  6. <template v-if="!pageLoading">
  7. <!-- 商机 -->
  8. <template v-if="currentRoutingInformation?.key == 'business'">
  9. <Business :formJson="formJson" :formValue="formValue" />
  10. </template>
  11. <!-- 线索 -->
  12. <template v-if="currentRoutingInformation?.key == 'thread'">
  13. <Thread :formJson="formJson" :formValue="formValue" />
  14. </template>
  15. <!-- 客户 -->
  16. <template v-if="currentRoutingInformation?.key == 'customer'">
  17. <Customer :formJson="formJson" :formValue="formValue" />
  18. </template>
  19. <!-- 联系人 -->
  20. <template v-if="currentRoutingInformation?.key == 'contacts'">
  21. <Contacts :formJson="formJson" :formValue="formValue" />
  22. </template>
  23. <!-- 任务 -->
  24. <template v-if="currentRoutingInformation?.key == 'tasks'">
  25. <Tasks :formJson="formJson" :formValue="formValue" />
  26. </template>
  27. <!-- 产品管理 -->
  28. <template v-if="currentRoutingInformation?.key == 'product'">
  29. <Product :formJson="formJson" :formValue="formValue" />
  30. </template>
  31. <!-- 合同管理 -->
  32. <template v-if="currentRoutingInformation?.key == 'contract'">
  33. <Contract :formJson="formJson" :formValue="formValue" />
  34. </template>
  35. <!-- 销售订单 -->
  36. <template v-if="currentRoutingInformation?.key == 'order'">
  37. <Order :formJson="formJson" :formValue="formValue" />
  38. </template>
  39. </template>
  40. </div>
  41. </template>
  42. </Page>
  43. </template>
  44. <script setup>
  45. import { ref } from 'vue';
  46. import { useLifecycle } from '@hooks/useCommon.js';
  47. import { GET_CUSTOM_FORM_JSON } from '@hooks/useApi.js';
  48. import requests from "@common/requests";
  49. import useRouterStore from "@store/useRouterStore.js";
  50. import useFixedData from "@store/useFixedData.js";
  51. import Business from "@pages/pageComponents/business/addEditor.vue"
  52. import Thread from "@pages/pageComponents/thread/addEditor.vue"
  53. import Customer from "@pages/pageComponents/customer/addEditor.vue"
  54. import Contacts from "@pages/pageComponents/contacts/addEditor.vue"
  55. import Tasks from "@pages/pageComponents/tasks/addEditor.vue"
  56. import Product from "@pages/pageComponents/product/addEditor.vue"
  57. import Contract from "@pages/pageComponents/contract/addEditor.vue"
  58. import Order from "@pages/pageComponents/order/addEditor.vue"
  59. const router = useRouterStore()
  60. const fixedData = useFixedData()
  61. const currentRoutingInformation = ref({})
  62. const formJson = ref({})
  63. const formValue = ref({})
  64. const addOrEdit = ref(false)
  65. const pageLoading = ref(true)
  66. function reloadListData(data) {
  67. const { routerInfo = '', filedValue = '' } = data
  68. const info = JSON.parse(routerInfo)
  69. currentRoutingInformation.value = JSON.parse(routerInfo)
  70. pageLoading.value = true
  71. formValue.value = (filedValue && Object.keys(JSON.parse(filedValue)).length)
  72. ? JSON.parse(filedValue)
  73. : {}
  74. addOrEdit.value = (filedValue && Object.keys(JSON.parse(filedValue)).length) ? true : false
  75. if (fixedData.formJson[info.key]) {
  76. formJson.value = fixedData.formJson[info.key]
  77. closeLoading()
  78. return
  79. } else {
  80. getCustomFormJson(info)
  81. }
  82. }
  83. function getCustomFormJson(info) {
  84. requests.get(`${GET_CUSTOM_FORM_JSON}/${info.key}`).then(res => {
  85. const { data = [] } = res
  86. formJson.value = JSON.parse(data[0].config)
  87. fixedData.updateState({
  88. formJson: {
  89. ...fixedData.formJson,
  90. [info.key]: JSON.parse(data[0].config)
  91. }
  92. })
  93. }).finally(() => {
  94. closeLoading()
  95. })
  96. }
  97. function closeLoading() {
  98. setTimeout(() => {
  99. pageLoading.value = false
  100. }, 500)
  101. }
  102. useLifecycle({
  103. load: () => {
  104. router.on('addEditorParameter', (data) => {
  105. reloadListData(data)
  106. })
  107. }
  108. });
  109. </script>
  110. <style lang='scss' scoped>
  111. /* 样式代码 */
  112. </style>