Form.vue.vm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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, update, getInfo } from './helper/api';
  19. import { reactive, toRefs, nextTick, ref, unref, computed,toRaw, inject } from 'vue';
  20. #if(${context.popupType}=="fullScreen")
  21. import { BasicPopup, usePopup } from '@jnpf/ui/popup';
  22. #end
  23. #if(${context.popupType}=="general")
  24. import { BasicModal, useModal } from '@jnpf/ui/modal';
  25. #end
  26. #if(${context.popupType}=="drawer")
  27. import { BasicDrawer, useDrawer } from '@jnpf/ui/drawer';
  28. #end
  29. import { JnpfRelationForm } from '@jnpf/ui';
  30. import { useMessage ,usePermission} from '@jnpf/hooks';
  31. import { $t } from '#/locales';
  32. import { useUserStore } from '@vben/stores';
  33. import type { FormInstance } from 'ant-design-vue';
  34. #if($isSelectDialog == true)
  35. import SelectModal from '#/components/InputTable/src/components/SelectModal.vue';
  36. #end
  37. import { thousandsFormat , getDateTimeUnit, getTimeUnit,buildUUID} from '@jnpf/utils';
  38. import { getDictionaryDataSelector } from '#/api/systemData/dictionary';
  39. import { getDataInterfaceRes } from '#/api/systemData/dataInterface';
  40. import dayjs from 'dayjs';
  41. // 表单权限
  42. import { cloneDeep } from 'lodash-es';
  43. import { CaretRightOutlined } from '@ant-design/icons-vue';
  44. interface State {
  45. #createStateParam("any")
  46. title: string;
  47. #if(${context.hasConfirmAndAddBtn})continueText: string; #end
  48. allList: any[];
  49. currIndex: number;
  50. isContinue: boolean;
  51. submitType: number;
  52. showContinueBtn: boolean;
  53. }
  54. const emit = defineEmits(['reload']);
  55. const getLeftTreeActiveInfo: (() => any) | null = inject('getLeftTreeActiveInfo', null);
  56. const userStore = useUserStore();
  57. const userInfo:any = userStore.getUserInfo;
  58. const { createMessage, createConfirm } = useMessage();
  59. #if(${context.popupType}=="fullScreen")
  60. const [registerPopup, { openPopup, setPopupProps }] = usePopup();
  61. #end
  62. #if(${context.popupType}=="general")
  63. const [registerModal, { openModal, setModalProps }] = useModal();
  64. #end
  65. #if(${context.popupType}=="drawer")
  66. const [registerDrawer, { openDrawer, setDrawerProps }] = useDrawer();
  67. #end
  68. const formRef = ref<FormInstance>();
  69. #if($isSelectDialog == true)
  70. // 子表弹窗数据
  71. const selectModal = ref(null);
  72. #end
  73. #GetChildTableColumns()
  74. const state = reactive<State>({
  75. #createStateParam()
  76. title: "",
  77. #if(${context.hasConfirmAndAddBtn}) continueText: "", #end
  78. allList: [],
  79. currIndex: 0,
  80. isContinue: false,
  81. submitType: 0,
  82. showContinueBtn: #if(${context.hasConfirmAndAddBtn}) true #else false #end,
  83. });
  84. const { title, #if(${context.hasConfirmAndAddBtn}) continueText, #end showContinueBtn, dataRule, dataForm, optionsObj, ableAll, maskConfig,submitType } = toRefs(state);
  85. const getPrevDisabled = computed(() => state.currIndex === 0);
  86. const getNextDisabled = computed(() => state.currIndex === state.allList.length - 1);
  87. // 表单权限
  88. const { hasFormP } = usePermission();
  89. defineExpose({ init });
  90. function init(data) {
  91. state.submitType = 0;
  92. state.isContinue = false;
  93. state.title = !data.id ? $t('common.add2Text','新增') : $t('common.editText','编辑');
  94. #if(${context.hasConfirmAndAddBtn}) state.continueText = !data.id ? $t('common.continueAndAddText','确定并新增') : $t('common.continueText','确定并继续'); #end
  95. setFormProps({ continueLoading: false });
  96. state.dataForm.id = data.id;
  97. #if(${context.popupType}=="fullScreen")
  98. openPopup();
  99. #end
  100. #if(${context.popupType}=="general")
  101. openModal();
  102. #end
  103. #if(${context.popupType}=="drawer")
  104. openDrawer();
  105. #end
  106. state.allList = data.allList;
  107. state.currIndex = state.allList.length && data.id ? state.allList.findIndex((item) => item.id === data.id) : 0;
  108. nextTick(() => {
  109. getForm().resetFields();
  110. #foreach($child in ${context.children})
  111. state.dataForm.${child.aliasLowName}List = [];
  112. #end
  113. setTimeout(initData, 0);
  114. });
  115. }
  116. function initData() {
  117. changeLoading(true);
  118. #InitActiveValue()
  119. if (state.dataForm.id) {
  120. getData(state.dataForm.id);
  121. } else {
  122. //初始化options
  123. #EditGetOption(false)
  124. // 设置默认值
  125. state.dataForm={
  126. #CreateDataform()
  127. };
  128. if (getLeftTreeActiveInfo) state.dataForm = {...state.dataForm, ...(getLeftTreeActiveInfo() || {}) };
  129. state.childIndex = -1;
  130. changeLoading(false);
  131. }
  132. }
  133. function getForm() {
  134. const form = unref(formRef);
  135. if (!form) {
  136. throw new Error('form is null!');
  137. }
  138. return form;
  139. }
  140. function getData(id) {
  141. getInfo(id).then((res) => {
  142. state.dataForm = res.data || {};
  143. ## 初始化options
  144. #EditGetOption(true)
  145. state.childIndex = -1;
  146. changeLoading(false);
  147. });
  148. }
  149. async function handleSubmit(type) {
  150. try {
  151. const values = await getForm()?.validate();
  152. if (!values) return;
  153. ### 非流程子表字段验证
  154. #if(!$context.isFlow)
  155. #foreach($itemModel in ${context.children})
  156. if(!$!{itemModel.aliasLowName}Exist()) return;
  157. #end
  158. #end
  159. setFormProps({ confirmLoading: true });
  160. const formMethod = state.dataForm.id ? update : create;
  161. formMethod(state.dataForm)
  162. .then((res) => {
  163. createMessage.success(res.msg);
  164. setFormProps({ confirmLoading: false });
  165. if (state.submitType == 1) {
  166. initData();
  167. state.isContinue = true;
  168. } else {
  169. setFormProps({ open: false });
  170. emit('reload');
  171. }
  172. })
  173. .catch(() => {
  174. setFormProps({ confirmLoading: false });
  175. });
  176. } catch (_) {}
  177. }
  178. function handlePrev() {
  179. state.currIndex--;
  180. handleGetNewInfo();
  181. }
  182. function handleNext() {
  183. state.currIndex++;
  184. handleGetNewInfo();
  185. }
  186. function handleGetNewInfo() {
  187. changeLoading(true);
  188. getForm().resetFields();
  189. const id = state.allList[state.currIndex].id;
  190. getData(id);
  191. }
  192. function setFormProps(data) {
  193. #if(${context.popupType}=="fullScreen")
  194. setPopupProps(data);
  195. #end
  196. #if(${context.popupType}=="general")
  197. setModalProps(data);
  198. #end
  199. #if(${context.popupType}=="drawer")
  200. setDrawerProps(data);
  201. #end
  202. }
  203. function changeLoading(loading) {
  204. #if(${context.popupType}=="fullScreen")
  205. setPopupProps({ loading });
  206. #end
  207. #if(${context.popupType}=="general")
  208. setModalProps({ loading });
  209. #end
  210. #if(${context.popupType}=="drawer")
  211. setDrawerProps({ loading });
  212. #end
  213. }
  214. async function onClose() {
  215. if (state.isContinue) emit('reload');
  216. return true;
  217. }
  218. ##合计方法
  219. #if($childSummary==true)
  220. //子表合计方法
  221. function getCmpValOfRow(row, key, summaryField) {
  222. if (!summaryField.length) return '';
  223. const isSummary = key => summaryField.includes(key);
  224. const target = row[key];
  225. if (!target) return '';
  226. let data = isNaN(target) ? 0 : Number(target);
  227. if (isSummary(key)) return data || 0;
  228. return '';
  229. }
  230. #end
  231. ##数据联动changeData方法
  232. #ChangeData()
  233. ##子表其他方法
  234. #CreateChildTableMethod()
  235. ##子表弹窗数据方法
  236. #if($isSelectDialog == true)
  237. #ChildDialogMethod()
  238. #end
  239. ##数据选项--数据字典和远端数据初始化方法
  240. #GetDataOptionsMethod()
  241. ##动态时间处理
  242. #GetRelationDate()
  243. </script>
  244. <template>
  245. ## 全屏弹窗
  246. #if(${context.popupType}=="fullScreen")
  247. ##<!-- 全屏弹窗 -->
  248. <BasicPopup v-bind="$attrs" @register="registerPopup" showOkBtn destroyOnClose
  249. #if(${context.cancelButtonText} || ${context.cancelButtonTextI18nCode})
  250. #if(${context.cancelButtonTextI18nCode}):cancelText="$t('${context.cancelButtonTextI18nCode}','${context.cancelButtonText}')"
  251. #else cancelText="${context.CancelButton}"#end
  252. #end
  253. #if(${context.confirmButtonText} || ${context.confirmButtonTextI18nCode})
  254. #if(${context.confirmButtonTextI18nCode}):okText="$t('${context.confirmButtonTextI18nCode}','${context.confirmButtonText}')"
  255. #else okText="${context.confirmButtonText}"#end
  256. #end
  257. @ok="handleSubmit" :closeFunc="onClose">
  258. <template #title>
  259. <a-space :size="10">
  260. <div class="text-16px font-medium">{{ title }}</div>
  261. ## <!-- 分组和树形不展示 -->
  262. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  263. <a-space-compact size="small" block v-if="dataForm.id">
  264. <a-tooltip :title="$t('common.prevRecord')">
  265. <a-button size="small" :disabled="getPrevDisabled" @click="handlePrev">
  266. <i class="icon-ym icon-ym-caret-left text-10px"></i>
  267. </a-button>
  268. </a-tooltip>
  269. <a-tooltip :title="$t('common.nextRecord')">
  270. <a-button size="small" :disabled="getNextDisabled" @click="handleNext">
  271. <i class="icon-ym icon-ym-caret-right text-10px"></i>
  272. </a-button>
  273. </a-tooltip>
  274. </a-space-compact>
  275. #end
  276. </a-space>
  277. </template>
  278. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  279. ## <!-- 分组和树形不展示 -->
  280. <template #insertToolbar>
  281. <JnpfCheckboxSingle v-model:value="submitType" :label="continueText" v-if="showContinueBtn" />
  282. </template>
  283. ## <!-- 分组和树形不展示 -->
  284. #end
  285. <a-row class="p-[10px] dynamic-form ${context.formStyle}" :style="{ margin: '0 auto', width: '${context.fullScreenWidth}' }">
  286. <a-form :colon="false" size="${context.size}" layout=#if(${context.labelPosition}=="top") "vertical" #else "horizontal" #end
  287. labelAlign=#if(${context.labelPosition}=="right") "right" #else "left" #end
  288. #if(${context.labelPosition}!="top") :labelCol="{ style: { width: '${context.labelWidth}px' } }" #end
  289. :model="dataForm" :rules="dataRule" ref="formRef" >
  290. <a-row :gutter="#if(${context.formStyle}=='word-form')0#else${context.gutter}#end">
  291. <!-- 具体表单 -->
  292. #FormRendering()
  293. <!-- 表单结束 -->
  294. </a-row>
  295. </a-form>
  296. </a-row>
  297. </BasicPopup>
  298. ##<!-- 全屏弹窗 -->
  299. #end
  300. ## 普通弹窗
  301. #if(${context.popupType}=="general")
  302. ##<!-- 普通弹窗 -->
  303. <BasicModal v-bind="$attrs" @register="registerModal" width="${context.generalWidth}"
  304. :minHeight="100"
  305. #if(${context.cancelButtonText} || ${context.cancelButtonTextI18nCode})
  306. #if(${context.cancelButtonTextI18nCode}):cancelText="$t('${context.cancelButtonTextI18nCode}','${context.cancelButtonText}')"
  307. #else cancelText="${context.CancelButton}"#end
  308. #end
  309. #if(${context.confirmButtonText} || ${context.confirmButtonTextI18nCode})
  310. #if(${context.confirmButtonTextI18nCode}):okText="$t('${context.confirmButtonTextI18nCode}','${context.confirmButtonText}')"
  311. #else okText="${context.confirmButtonText}"#end
  312. #end
  313. @ok="handleSubmit" :closeFunc="onClose">
  314. <template #title>
  315. <a-space :size="10">
  316. <div class="text-16px font-medium">{{ title }}</div>
  317. ## <!-- 分组和树形不展示 -->
  318. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  319. <a-space-compact size="small" block v-if="dataForm.id">
  320. <a-tooltip :title="$t('common.prevRecord')">
  321. <a-button size="small" :disabled="getPrevDisabled" @click="handlePrev">
  322. <i class="icon-ym icon-ym-caret-left text-10px"></i>
  323. </a-button>
  324. </a-tooltip>
  325. <a-tooltip :title="$t('common.nextRecord')">
  326. <a-button size="small" :disabled="getNextDisabled" @click="handleNext">
  327. <i class="icon-ym icon-ym-caret-right text-10px"></i>
  328. </a-button>
  329. </a-tooltip>
  330. </a-space-compact>
  331. #end
  332. </a-space>
  333. </template>
  334. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  335. ## <!-- 分组和树形不展示 -->
  336. <template #insertFooter>
  337. <div class="float-left mt-5px">
  338. <JnpfCheckboxSingle v-model:value="submitType" :label="continueText" />
  339. </div>
  340. </template>
  341. ## <!-- 分组和树形不展示 -->
  342. #end
  343. <a-row class="dynamic-form ${context.formStyle}">
  344. <a-form :colon="false" size="${context.size}" layout=#if(${context.labelPosition}=="top") "vertical" #else "horizontal" #end
  345. labelAlign=#if(${context.labelPosition}=="right") "right" #else "left" #end
  346. #if(${context.labelPosition}!="top") :labelCol="{ style: { width: '${context.labelWidth}px' } }" #end
  347. :model="dataForm" :rules="dataRule" ref="formRef">
  348. <a-row :gutter="#if(${context.formStyle}=='word-form')0#else${context.gutter}#end">
  349. <!-- 具体表单 -->
  350. #FormRendering()
  351. <!-- 表单结束 -->
  352. </a-row>
  353. </a-form>
  354. </a-row>
  355. </BasicModal>
  356. ##<!-- 普通弹窗 -->
  357. #end
  358. ## 右侧弹窗
  359. #if(${context.popupType}=="drawer")
  360. ##<!-- 右侧弹窗 -->
  361. <BasicDrawer v-bind="$attrs" @register="registerDrawer" width="${context.drawerWidth}" showFooter
  362. #if(${context.cancelButtonText} || ${context.cancelButtonTextI18nCode})
  363. #if(${context.cancelButtonTextI18nCode}):cancelText="$t('${context.cancelButtonTextI18nCode}','${context.cancelButtonText}')"
  364. #else cancelText="${context.CancelButton}"#end
  365. #end
  366. #if(${context.confirmButtonText} || ${context.confirmButtonTextI18nCode})
  367. #if(${context.confirmButtonTextI18nCode}):okText="$t('${context.confirmButtonTextI18nCode}','${context.confirmButtonText}')"
  368. #else okText="${context.confirmButtonText}"#end
  369. #end
  370. @ok="handleSubmit" :closeFunc="onClose">
  371. <template #title>
  372. <a-space :size="10">
  373. <div class="text-16px font-medium">{{ title }}</div>
  374. ## <!-- 分组和树形不展示 -->
  375. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  376. <a-space-compact size="small" block v-if="dataForm.id">
  377. <a-tooltip :title="$t('common.prevRecord')">
  378. <a-button size="small" :disabled="getPrevDisabled" @click="handlePrev">
  379. <i class="icon-ym icon-ym-caret-left text-10px"></i>
  380. </a-button>
  381. </a-tooltip>
  382. <a-tooltip :title="$t('common.nextRecord')">
  383. <a-button size="small" :disabled="getNextDisabled" @click="handleNext">
  384. <i class="icon-ym icon-ym-caret-right text-10px"></i>
  385. </a-button>
  386. </a-tooltip>
  387. </a-space-compact>
  388. #end
  389. </a-space>
  390. </template>
  391. #if(${context.hasConfirmAndAddBtn} && (!${context.groupTable} && !${context.treeTable}))
  392. ## <!-- 分组和树形不展示 -->
  393. <template #insertFooter>
  394. <div class="float-left mt-5px">
  395. <JnpfCheckboxSingle v-model:value="submitType" :label="continueText" />
  396. </div>
  397. </template>
  398. ## <!-- 分组和树形不展示 -->
  399. #end
  400. <a-row class="p-[10px] dynamic-form ${context.formStyle}">
  401. <!-- 表单 -->
  402. <a-form :colon="false" size="${context.size}" layout=#if(${context.labelPosition}=="top") "vertical" #else "horizontal" #end
  403. labelAlign=#if(${context.labelPosition}=="right") "right" #else "left" #end
  404. #if(${context.labelPosition}!="top") :labelCol="{ style: { width: '${context.labelWidth}px' } }" #end
  405. :model="dataForm" :rules="dataRule" ref="formRef" >
  406. <a-row :gutter="#if(${context.formStyle}=='word-form')0#else${context.gutter}#end">
  407. <!-- 具体表单 -->
  408. #FormRendering()
  409. <!-- 表单结束 -->
  410. </a-row>
  411. </a-form>
  412. </a-row>
  413. </BasicDrawer>
  414. ##<!-- 右侧弹窗 -->
  415. #end
  416. #if($isSelectDialog == true)
  417. <SelectModal :config="state.currTableConf" :formData="state.dataForm" ref="selectModal" @select="addForSelect"/>
  418. #end
  419. </template>