FormPopup.vue.vm 5.3 KB

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