FormPopup.vue.vm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #parse("PublicMacro/FormMarco.vm")
  2. #foreach($fieLdsModel in ${context.form})
  3. #set($jnpfKey = "${fieLdsModel.jnpfKey}")
  4. #if($jnpfKey == 'table')
  5. #set($child = $fieLdsModel.childList)
  6. #if($child.showSummary)
  7. #set($childSummary=true)
  8. #end
  9. #if($child.footerBtnsList.size()>2)
  10. #set($isSelectDialog = true)
  11. #end
  12. #if($child.isNumLimit)
  13. #set($isNumLimitSwitch = true)
  14. #end
  15. #end
  16. #end
  17. <script lang="ts" setup>
  18. import { create } from './helper/api';
  19. import { reactive, toRefs, nextTick, ref, unref, computed, toRaw} from 'vue';
  20. import { BasicPopup, usePopupInner } from '@jnpf/ui/popup';
  21. import { useUserStore } from '@vben/stores';
  22. import type { FormInstance } from 'ant-design-vue';
  23. import { useMessage,usePermission } from '@jnpf/hooks';
  24. import { $t } from '#/locales';
  25. import { JnpfRelationForm } from '@jnpf/ui';
  26. #if($isSelectDialog == true)
  27. import SelectModal from '#/components/InputTable/src/components/SelectModal.vue';
  28. #end
  29. import { thousandsFormat , getDateTimeUnit, getTimeUnit, buildUUID} from '@jnpf/utils';
  30. import { getDictionaryDataSelector } from '#/api/systemData/dictionary';
  31. import { getDataInterfaceRes } from '#/api/systemData/dataInterface';
  32. import dayjs from 'dayjs';
  33. import { cloneDeep } from 'lodash-es';
  34. import { CaretRightOutlined } from '@ant-design/icons-vue';
  35. interface State {
  36. btnLoading: boolean;
  37. #createStateParam("any")
  38. }
  39. defineEmits(['register']);
  40. const userStore = useUserStore();
  41. const userInfo:any = userStore.getUserInfo;
  42. const { createMessage, createConfirm } = useMessage();
  43. const [registerPopup, { changeLoading }] = usePopupInner(init);
  44. const formRef = ref<FormInstance>();
  45. #if($isSelectDialog == true)
  46. // 子表弹窗数据
  47. const selectModal = ref(null);
  48. #end
  49. const state = reactive<State>({
  50. btnLoading: false,
  51. #createStateParam()
  52. });
  53. const { dataForm, dataRule, btnLoading, optionsObj, ableAll, maskConfig } = toRefs(state);
  54. // 表单权限
  55. const { hasFormP } = usePermission();
  56. #GetChildTableColumns()
  57. function init() {
  58. changeLoading(true);
  59. #EditGetOption(false)
  60. #InitActiveValue()
  61. nextTick(() => {
  62. changeLoading(false);
  63. });
  64. }
  65. async function handleSubmit() {
  66. try {
  67. const values = await getForm()?.validate();
  68. if (!values) return;
  69. ### 非流程子表字段验证
  70. #if(!$context.isFlow)
  71. #foreach($itemModel in ${context.children})
  72. if(!$!{itemModel.aliasLowName}Exist()) return;
  73. #end
  74. #end
  75. state.btnLoading = true;
  76. create(state.dataForm)
  77. .then(res => {
  78. createMessage.success(res.msg);
  79. state.btnLoading = false;
  80. handleReset();
  81. })
  82. .catch(() => {
  83. state.btnLoading = false;
  84. });
  85. } catch (_) {}
  86. }
  87. function handleReset() {
  88. getForm().resetFields();
  89. #foreach($child in ${context.children})
  90. state.dataForm.${child.aliasLowName}List = [];
  91. #end
  92. init();
  93. }
  94. function getForm() {
  95. const form = unref(formRef);
  96. if (!form) {
  97. throw new Error('form is null!');
  98. }
  99. return form;
  100. }
  101. ##数据联动changeData方法
  102. #ChangeData()
  103. ##子表其他方法
  104. #CreateChildTableMethod()
  105. ##子表弹窗数据方法
  106. #if($isSelectDialog == true)
  107. #ChildDialogMethod()
  108. #end
  109. ##合计方法
  110. #if($childSummary==true)
  111. //子表合计方法
  112. function getCmpValOfRow(row, key, summaryField) {
  113. if (!summaryField.length) return '';
  114. const isSummary = key => summaryField.includes(key);
  115. const target = row[key];
  116. if (!target) return '';
  117. let data = isNaN(target) ? 0 : Number(target);
  118. if (isSummary(key)) return data || 0;
  119. return '';
  120. }
  121. #end
  122. ##数据选项--数据字典和远端数据初始化方法
  123. #GetDataOptionsMethod()
  124. ##动态时间处理
  125. #GetRelationDate()
  126. </script>
  127. <template>
  128. <BasicPopup v-bind="$attrs" @register="registerPopup" :show-back-icon="false" :show-cancel-btn="false" title="${context.formModelName}">
  129. <template #insertToolbar>
  130. <a-button type="primary" @click="handleSubmit" :loading="btnLoading">{{$t('common.saveText','保存')}}</a-button>
  131. <a-button type="warning" class="ml-[10px]" @click="handleReset">{{$t('component.cropper.btn_reset','重置')}}</a-button>
  132. </template>
  133. <a-row class="p-[10px] dynamic-form ${context.formStyle}" :style="{ margin: '0 auto', width: '100%' }">
  134. <!-- 表单 -->
  135. <a-form :colon="false" size="${context.size}" layout=#if(${context.labelPosition}=="top") "vertical" #else "horizontal" #end
  136. labelAlign=#if(${context.labelPosition}=="right") "right" #else "left" #end
  137. #if(${context.labelPosition}!="top") :labelCol="{ style: { width: '${context.labelWidth}px' } }" #end
  138. :model="dataForm" :rules="dataRule" ref="formRef" >
  139. <a-row :gutter="#if(${context.formStyle}=='word-form')0#else${context.gutter}#end">
  140. <!-- 具体表单 -->
  141. #FormRendering()
  142. <!-- 表单结束 -->
  143. </a-row>
  144. </a-form>
  145. </a-row>
  146. #if($isSelectDialog == true)
  147. <SelectModal :config="state.currTableConf" :formData="state.dataForm" ref="selectModal" @select="addForSelect"/>
  148. #end
  149. </BasicPopup>
  150. </template>