businessLaunch.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <el-drawer
  3. :close-on-click-modal="false"
  4. class="le-drawer"
  5. :title="record.processName"
  6. :model-value="modelValue"
  7. size="760px"
  8. @update:model-value="updateModelValue"
  9. >
  10. <div v-if="validateForm.loading" v-loading="true" class="local_loading"></div>
  11. <div class="info-wrap">
  12. <el-divider content-position="left">{{ record.processName }}表单</el-divider>
  13. <!-- 表单设计 -->
  14. <template v-if="record.formTemplate.type === 0">
  15. <div class="self-Everright-formEditor">
  16. <er-form-preview ref="EReditorRef" :is-show-complete-button="false" :file-upload-u-r-i="uploadFileApi" />
  17. </div>
  18. </template>
  19. <!-- vue自定义 -->
  20. <template v-if="record.formTemplate.type === 1">
  21. <component :is="dyVueComponent" ref="dyVueComponentRef" @form-valid="onSubmit"></component>
  22. </template>
  23. <el-divider content-position="left">审批流程</el-divider>
  24. <flow-trend ref="flowTrendRef" v-model="modelContentConfig"></flow-trend>
  25. <el-divider></el-divider>
  26. </div>
  27. <template #footer>
  28. <el-button @click="updateModelValue(false)">{{ $t('le.btn.cancel') }}</el-button>
  29. <el-button :disabled="validateForm.loading" type="primary" style="margin-left: 8px" @click="handleFormValid">{{
  30. $t('le.btn.confirm')
  31. }}</el-button>
  32. </template>
  33. </el-drawer>
  34. </template>
  35. <script setup lang="ts">
  36. import purchaseOrder from '@/api/test/purchaseOrder'
  37. import { ElMessage } from 'element-plus'
  38. import { erFormPreview } from '@ER/formEditor'
  39. import FlowTrend from '@/components/Flow/FlowTrend.vue'
  40. import type { ModelContentConfig } from '@/views/approve/components/config.ts'
  41. import { nextTick, onMounted, ref, markRaw, defineAsyncComponent, provide } from 'vue'
  42. type Props = {
  43. modelValue: boolean
  44. record: { processId: string; processName: string; [key: string]: any }
  45. }
  46. // 当前form 表单数据字符串
  47. let cur_processForm_str = '{}'
  48. const updateModelValue = (bool: boolean) => emit('update:modelValue', bool)
  49. const refreshComponent = (bool: boolean) => emit('refreshEv', bool)
  50. const props = defineProps<Props>()
  51. const emit = defineEmits<{
  52. 'update:modelValue': [bool: boolean] // 具名元组语法
  53. update: [value: string]
  54. refreshEv: [value: boolean] // 告诉父组件刷新
  55. }>()
  56. const validateForm = ref({ loading: false })
  57. const { VITE_APP_BASE_API } = import.meta.env
  58. const uploadFileApi = ref(`${VITE_APP_BASE_API}/v1/oss/upload`)
  59. const EReditorRef = ref()
  60. const modelContentConfig = ref<ModelContentConfig | any>({})
  61. const dyVueComponent = ref(undefined)
  62. const dyVueComponentRef = ref()
  63. const flowTrendRef = ref()
  64. const dyVueForm = ref({})
  65. provide('dyVueForm', dyVueForm) // 这里主要是存放动态的form的属性值
  66. /**
  67. * 1、校验表单
  68. * 1.1 type=1 校验系统表单
  69. * 1.2 type=0 校验表单设计
  70. * 2、提交API
  71. */
  72. const handleFormValid = () => {
  73. const { type } = props.record.formTemplate
  74. if (type) {
  75. dyVueComponentRef.value.validateForm()
  76. } else {
  77. validateDesignForm()
  78. }
  79. }
  80. // 校验表单设计
  81. const validateDesignForm = () => {
  82. const form = EReditorRef.value.getSelfFormRef()
  83. form.validate((valid: any) => {
  84. if (!valid) return false
  85. // 提交数据
  86. onSubmit()
  87. })
  88. }
  89. const onSubmit = async () => {
  90. const processId = props.record.processId
  91. const { type } = props.record.formTemplate
  92. // 这里要从子节点获取流程图信息 进行保存
  93. const _assigneeMap = flowTrendRef.value.getAssigneeMap()
  94. const assigneeMap_ = Object.keys(_assigneeMap).reduce((obj, nodeKey: string) => {
  95. const _o = _assigneeMap[nodeKey]
  96. obj[nodeKey] = {
  97. assigneeList: _o.assignees,
  98. type: _o.type
  99. }
  100. return obj
  101. }, {} as { [nodeKey: string]: any })
  102. const paramCommon = {
  103. id: props.record.rowId,
  104. test: '', // 系统表单JSON内容
  105. processStart: {
  106. processId, // 流程ID
  107. processForm: '', // 设计表单JSON内容
  108. assigneeMap: assigneeMap_
  109. }
  110. }
  111. validateForm.value.loading = true
  112. // type: 0 设计表单 1 vue系统表单
  113. if (type) {
  114. const testData = {
  115. formStructure: '@/views/flow/test/test1.vue',
  116. formData: dyVueComponentRef.value.getComponentData()
  117. }
  118. paramCommon.test = JSON.stringify(testData)
  119. } else {
  120. const formData = EReditorRef.value.getData()
  121. let processForm = JSON.parse(cur_processForm_str)
  122. processForm = { ...processForm, formData }
  123. paramCommon.processStart.processForm = JSON.stringify(processForm)
  124. }
  125. purchaseOrder
  126. .postlaunchApi(paramCommon)
  127. .then(res => {
  128. ElMessage.success('提交成功')
  129. updateModelValue(false)
  130. refreshComponent(true)
  131. })
  132. .finally(() => {
  133. validateForm.value.loading = false
  134. })
  135. }
  136. // 获取当前表单中的详情
  137. const getDetailInfo = () => {
  138. validateForm.value.loading = true
  139. let modelContent_config = {}
  140. const modelContent = JSON.parse(props.record.modelContent) // modelContent 这个是后台返回来的
  141. modelContent_config = modelContent.nodeConfig ?? modelContent.childNode
  142. modelContentConfig.value = modelContent_config
  143. const { content, type } = props.record.formTemplate
  144. if (!type) {
  145. // type: 0 表单设计 1 vue自定义表单
  146. cur_processForm_str = `{"formStructure":${content}}` || '{}' // processForm 这个是后台返回来的
  147. const { formStructure } = JSON.parse(cur_processForm_str)
  148. EReditorRef.value.setData(formStructure)
  149. } else {
  150. // dyVueForm.value = {
  151. // dy: {
  152. // name: '测试名字',
  153. // region: 1,
  154. // delivery: true,
  155. // type: ['1'],
  156. // resource: 'Sponsor',
  157. // desc: '啦啦啦'
  158. // }
  159. // }
  160. dyVueComponent.value = markRaw(defineAsyncComponent(() => import('@/views/flow/test/test1.vue')))
  161. }
  162. validateForm.value.loading = false
  163. }
  164. onMounted(() => {
  165. nextTick(() => {
  166. getDetailInfo()
  167. })
  168. })
  169. </script>
  170. <style scoped lang="scss">
  171. .info-wrap {
  172. .form-wrap {
  173. flex: 1;
  174. }
  175. // 修改everright 表单的样式
  176. .self-Everright-formEditor {
  177. :deep(.Everright-formEditor-selectElement) {
  178. padding: 0px 16px;
  179. }
  180. }
  181. }
  182. </style>