form.vue.vm 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. #parse("PublicMacro/AppFormMarco.vm")
  2. <template>
  3. <view class="jnpf-wrap jnpf-wrap-form dynamicModel-form-v" v-if="!loading">
  4. <u-form :model="${context.formModel}" :rules="${context.formRules}" ref="${context.formModel}" :errorType="['toast']"
  5. #set($position='left')
  6. #if(${context.labelPosition}=='top')
  7. #set($position='top')
  8. #end
  9. #set($align='left')
  10. #if(${context.labelPosition}=='right')
  11. #set($align='right')
  12. #end
  13. label-position="${position}" label-align="${align}" :label-width="labelwidth" class="jnpf-form">
  14. #AppFormRendering()
  15. </u-form>
  16. #if(${isFlow}==false)
  17. #if(${context.webType}=='1')
  18. <view class="buttom-actions">
  19. <u-button class="buttom-btn" @click="resetForm">{{$t('common.resetText','重置')}}</u-button>
  20. <u-button class="buttom-btn" type="primary" @click="submitForm" :loading="btnLoading">{{$t('common.okText','确定')}}</u-button>
  21. </view>
  22. #else
  23. <view class="buttom-actions" v-if="jurisdictionType != 'btn_detail'" >
  24. <CustomButton class="u-flex buttom-btn-left-inner" :btnText="$t('common.cancelText')" btnIcon="icon-ym icon-ym-add-cancel" customIcon />
  25. <u-button class="buttom-btn" type="primary" @click="submitForm" :loading="btnLoading">{{$t('common.okText','确定')}}</u-button>
  26. </view>
  27. <u-action-sheet @click="handleAction" :list="actionList" :tips="{ text: '更多操作' , color: '#000' , fontSize: 30 }" v-model="showAction">
  28. </u-action-sheet>
  29. #end
  30. #end
  31. <u-modal v-model="show" :content="content" width='70%' border-radius="16" :content-style="{fontSize: '28rpx',padding: '20rpx',lineHeight: '44rpx',textAlign: 'left'}"
  32. :titleStyle="{padding: '20rpx'}" :confirm-style="{height: '80rpx',lineHeight: '80rpx'}" :title="title" confirm-text="确定">
  33. <view class="slot-content">
  34. <rich-text :nodes="content"></rich-text>
  35. </view>
  36. </u-modal>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. getDictionaryDataSelector,
  42. getDataInterfaceRes
  43. } from '@/api/common'
  44. #if(${isFlow})
  45. import comMixin from '../mixin'
  46. #end
  47. import {
  48. getDateDay,
  49. getLaterData,
  50. getBeforeData,
  51. getBeforeTime,
  52. getLaterTime
  53. } from '@/components/index.js'
  54. import request from '@/utils/request'
  55. import {
  56. useBaseStore
  57. } from '@/store/modules/base'
  58. import CustomButton from '@/components/CustomButton'
  59. export default {
  60. components:{
  61. CustomButton
  62. },
  63. #if(${isFlow})
  64. mixins: [comMixin],
  65. #end
  66. data(){
  67. return{
  68. idList: [],
  69. index:0,
  70. actionList: [],
  71. actionListLength: false,
  72. showAction: false,
  73. btnLoading: false,
  74. loading: false,
  75. isNumLimit:false,
  76. label: '',
  77. tableKey:'',
  78. numLimit:1,
  79. timeKey : +new Date(),
  80. ${context.formModel}:{
  81. ${pKeyName}:"",
  82. #foreach($fieLdsModel in ${context.fields})
  83. #set($html = $fieLdsModel.formColumnModel.fieLdsModel)
  84. #set($vModel = "${html.vModel}")
  85. #set($config = $html.config)
  86. #set($jnpfkey = "${config.jnpfKey}")
  87. #if($vModel)
  88. #if($!config.valueType=='String')
  89. $!{vModel} : '$!{config.defaultValue}',
  90. #elseif($!config.valueType=='undefined')
  91. $!{vModel} : undefined,
  92. #else
  93. $!{vModel} : $!{config.defaultValue},
  94. #end
  95. #end
  96. #end
  97. #foreach($masetkey in $mastTableList.entrySet())
  98. #set($fieldsAll = $masetkey.value)
  99. #foreach($fieLdsModel in ${fieldsAll})
  100. #set($mastTableModel = $fieLdsModel.formMastTableModel)
  101. #set($html = $fieLdsModel.formMastTableModel.mastTable.fieLdsModel)
  102. #set($vModel = "${mastTableModel.vModel}")
  103. #set($config = $html.config)
  104. #set($jnpfkey = "${config.jnpfKey}")
  105. #if($vModel)
  106. #if($!config.valueType=='String')
  107. $!{vModel} : '$!{config.defaultValue}',
  108. #elseif($!config.valueType=='undefined')
  109. $!{vModel} : undefined,
  110. #else
  111. $!{vModel} : $!{config.defaultValue},
  112. #end
  113. #end
  114. #end
  115. #end
  116. #foreach($child in ${context.children})
  117. #set($className = "${child.className}")
  118. ${className}List:[],
  119. #end
  120. },
  121. ${context.formRules}:{
  122. #foreach($fields in ${context.fields})
  123. #set($fieLdsModel = $fields.formColumnModel.fieLdsModel)
  124. #appRule($fieLdsModel)
  125. #end
  126. #foreach($masetkey in $mastTableList.entrySet())
  127. #set($fieldsAll = $masetkey.value)
  128. #foreach($fields in ${fieldsAll})
  129. #set($fieLdsModel = $fields.formMastTableModel.mastTable.fieLdsModel)
  130. #appRule($fieLdsModel)
  131. #end
  132. #end
  133. },
  134. #foreach($fields in ${context.fields})
  135. #set($fieLdsModel = $fields.formColumnModel.fieLdsModel)
  136. #list($fieLdsModel,'')
  137. #end
  138. #foreach($masetkey in $mastTableList.entrySet())
  139. #set($fieldsAll = $masetkey.value)
  140. #foreach($fields in ${fieldsAll})
  141. #set($fieLdsModel = $fields.formMastTableModel.mastTable.fieLdsModel)
  142. #list($fieLdsModel,'')
  143. #end
  144. #end
  145. #foreach($child in ${context.children})
  146. #set($className = "${child.className}")
  147. #foreach($childList in ${child.childList})
  148. #set($fieLdsModel = $childList.fieLdsModel)
  149. #list($fieLdsModel,$className)
  150. #end
  151. #end
  152. #foreach($fieLdsModel in ${context.form})
  153. #set($jnpfkey = "${fieLdsModel.jnpfKey}")
  154. #set($isEnd = "${fieLdsModel.isEnd}")
  155. #set($formModel = ${fieLdsModel.formModel})
  156. #set($model = "${formModel.model}")
  157. #set($outermost = ${formModel.outermost})
  158. #set($children = ${formModel.children})
  159. #if(${layoutList.contains($jnpfkey)})
  160. #if(${isEnd}=='0')
  161. #if(${outermost}=='0')
  162. #if($jnpfkey=='collapse')
  163. ${model}active: #if($formModel.accordion) '${formModel.active}' #else ${formModel.active} #end,
  164. #end
  165. ${model}Current:${formModel.activeIndex},
  166. ${model}Data:[
  167. #foreach($childrenList in $children)
  168. {
  169. title: #if(${childrenList.titleI18nCode}) this.$t('${childrenList.titleI18nCode}')#else "${childrenList.title}" #end
  170. },
  171. #end
  172. ],
  173. #end
  174. #end
  175. #end
  176. #end
  177. labelwidth:${context.labelWidth}*1.5,
  178. menuId:'',
  179. jurisdictionType:'',
  180. ruleList:{
  181. #foreach($child in ${context.children})
  182. #set($className = "${child.className}")
  183. #set($childLable = "${child.label}")
  184. ${className}List:{
  185. #foreach($html in ${child.childList})
  186. #set($fieLdsModel = ${html.fieLdsModel})
  187. #set($vModel = "${fieLdsModel.vModel}")
  188. #set($config = ${fieLdsModel.config})
  189. #set($jnpfkey = "${config.jnpfKey}")
  190. #set($label = "${config.label}")
  191. #if($config.required==true)
  192. #if($jnpfkey!='switch')
  193. '${vModel}' : '${childLable}-${label}不能为空',
  194. #end
  195. #end
  196. #end
  197. },
  198. #end
  199. },
  200. ableRelation:{
  201. #foreach($html in ${context.fields})
  202. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  203. #ableRelation($fieLdsModel,'')
  204. #end
  205. #foreach($masetkey in $mastTableList.entrySet())
  206. #set($fieldsAll = $masetkey.value)
  207. #foreach($html in ${fieldsAll})
  208. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  209. #ableRelation($fieLdsModel,'')
  210. #end
  211. #end
  212. #foreach($child in ${context.children})
  213. #set($className = "${child.className}")
  214. #foreach($childList in ${child.childList})
  215. #set($fieLdsModel = $childList.fieLdsModel)
  216. #ableRelation($fieLdsModel,$className)
  217. #end
  218. #end
  219. },
  220. interfaceRes:{
  221. #foreach($html in ${context.fields})
  222. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  223. #faceRes($fieLdsModel,'')
  224. #end
  225. #foreach($masetkey in $mastTableList.entrySet())
  226. #set($fieldsAll = $masetkey.value)
  227. #foreach($html in ${fieldsAll})
  228. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  229. #faceRes($fieLdsModel,'')
  230. #end
  231. #end
  232. #foreach($child in ${context.children})
  233. #set($className = "${child.className}")
  234. #foreach($childList in ${child.childList})
  235. #set($fieLdsModel = $childList.fieLdsModel)
  236. #faceRes($fieLdsModel,$className)
  237. #end
  238. #end
  239. },
  240. maskConfig:{
  241. #foreach($html in ${context.fields})
  242. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  243. #maskConfig($fieLdsModel,'')
  244. #end
  245. #foreach($masetkey in $mastTableList.entrySet())
  246. #set($fieldsAll = $masetkey.value)
  247. #foreach($html in ${fieldsAll})
  248. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  249. #maskConfig($fieLdsModel,'')
  250. #end
  251. #end
  252. #foreach($child in ${context.children})
  253. #set($className = "${child.className}")
  254. #foreach($childList in ${child.childList})
  255. #set($fieLdsModel = $childList.fieLdsModel)
  256. #maskConfig($fieLdsModel,$className)
  257. #end
  258. #end
  259. },
  260. locationScope:{
  261. #foreach($html in ${context.fields})
  262. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  263. #locationScope($fieLdsModel,'')
  264. #end
  265. #foreach($masetkey in $mastTableList.entrySet())
  266. #set($fieldsAll = $masetkey.value)
  267. #foreach($html in ${fieldsAll})
  268. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  269. #locationScope($fieLdsModel,'')
  270. #end
  271. #end
  272. #foreach($child in ${context.children})
  273. #set($className = "${child.className}")
  274. #foreach($childList in ${child.childList})
  275. #set($fieLdsModel = $childList.fieLdsModel)
  276. #locationScope($fieLdsModel,$className)
  277. #end
  278. #end
  279. },
  280. regList:{
  281. #foreach($child in ${context.children})
  282. #set($className = "${child.className}")
  283. #set($childLable = "${child.label}")
  284. ${className}List:{
  285. #foreach($html in ${child.childList})
  286. #set($fieLdsModel = ${html.fieLdsModel})
  287. #set($vModel = "${fieLdsModel.vModel}")
  288. #set($config = ${fieLdsModel.config})
  289. #set($listSize=$!{config.regList})
  290. #set($jnpfkey = "${config.jnpfKey}")
  291. #set($label = "${config.label}")
  292. #if($vModel)
  293. ${vModel}: [
  294. #if($listSize && $listSize.size()>0)
  295. #foreach($regList in ${config.regList})
  296. {
  297. pattern: ${regList.pattern},
  298. message: '${childLable}-${label}${regList.message}',
  299. },
  300. #end
  301. #end
  302. ],
  303. #end
  304. #end
  305. },
  306. #end
  307. },
  308. ableAll:{
  309. #foreach($html in ${context.fields})
  310. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  311. #appableAll($fieLdsModel,'')
  312. #end
  313. #foreach($masetkey in $mastTableList.entrySet())
  314. #set($fieldsAll = $masetkey.value)
  315. #foreach($html in ${fieldsAll})
  316. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  317. #appableAll($fieLdsModel,'')
  318. #end
  319. #end
  320. #foreach($child in ${context.children})
  321. #set($className = "${child.className}")
  322. #foreach($childList in ${child.childList})
  323. #set($fieLdsModel = $childList.fieLdsModel)
  324. #appableAll($fieLdsModel,$className)
  325. #end
  326. #end
  327. },
  328. childIndex:-1,
  329. dataValue:{},
  330. isEdit:false,
  331. userInfo:{},
  332. content:'',
  333. title:'',
  334. show:false,
  335. formatType: {
  336. 'yyyy': 'yyyy',
  337. 'yyyy-MM': 'yyyy-mm',
  338. 'yyyy-MM-dd': 'yyyy-mm-dd',
  339. 'yyyy-MM-dd HH:mm': 'yyyy-mm-dd hh:MM',
  340. 'yyyy-MM-dd HH:mm:ss': 'yyyy-mm-dd hh:MM:ss',
  341. 'HH:mm:ss': 'hh:MM:ss',
  342. "HH:mm": "hh:MM",
  343. 'YYYY': 'yyyy',
  344. 'YYYY-MM': 'yyyy-mm',
  345. 'YYYY-MM-DD': 'yyyy-mm-dd',
  346. 'YYYY-MM-DD HH:mm': 'yyyy-mm-dd hh:MM',
  347. 'YYYY-MM-DD HH:mm:ss': 'yyyy-mm-dd hh:MM:ss',
  348. },
  349. }
  350. },
  351. created(){
  352. uni.$on('linkPageConfirm', (subVal) => {
  353. if (this.tableKey) {
  354. let selectedData = JSON.parse(JSON.stringify(subVal));
  355. if (this.isNumLimit) {
  356. const remaining = this.numLimit - this.${context.formModel}[this.tableKey].length;
  357. #set($toast='$'+"u.toast")
  358. if (remaining <= 0) return this.$toast(`${this.label}超出条数限制}`);
  359. selectedData = selectedData.slice(0, remaining);
  360. }
  361. for (let i = 0; i < selectedData.length; i++) {
  362. let t = subVal[i]
  363. if (this['get' + this.tableKey]) {
  364. this['get' + this.tableKey](t)
  365. }
  366. }
  367. this.childIndex = -1
  368. this.collapse()
  369. }
  370. })
  371. uni.$on('initCollapse', () => {
  372. //初始化折叠面板高度高度
  373. this.collapse()
  374. })
  375. },
  376. onLoad(option) {
  377. this.jurisdictionType = option.jurisdictionType
  378. this.menuId=option.menuId
  379. this.userInfo = uni.getStorageSync('userInfo') || {}
  380. this.${context.formModel}.${pKeyName} = option.id || ''
  381. let _title = ""
  382. if(option.jurisdictionType =='btn_edit'){
  383. _title = this.$t('common.editText','编辑')
  384. }
  385. if(option.jurisdictionType =='btn_detail'){
  386. _title = this.$t('common.detailText','详情')
  387. }
  388. if(option.jurisdictionType =='btn_add'){
  389. _title = this.$t('common.add2Text','新增')
  390. }
  391. if(_title){
  392. uni.setNavigationBarTitle({
  393. title: _title
  394. })
  395. }
  396. this.selfInit()
  397. this.initDefaultData()
  398. this.dataAll()
  399. this.initData()
  400. this.dataValue = JSON.parse(JSON.stringify(this.${context.formModel}))
  401. this.idList = option.idList?option.idList.split(","):[]
  402. for(let i=0;i<this.idList.length;i++){
  403. if(this.idList[i]==option.id){
  404. this.index = i;
  405. }
  406. }
  407. #if($context.hasConfirmAndAddBtn)
  408. if (!option.id) {
  409. this.actionList.push({
  410. text: this.$t('common.continueAndAddText','确定并新增'),
  411. id: 'save_add'
  412. })
  413. } else {
  414. let upper={
  415. text: this.$t('common.prevRecord','上一条'),
  416. id: 'upper',
  417. disabled: this.index==0?true:false
  418. }
  419. this.actionList.push(upper)
  420. let lower={
  421. text: this.$t('common.nextRecord','下一条'),
  422. id: 'lower',
  423. disabled: this.index==this.idList.length-1?true:false
  424. }
  425. this.actionList.push(lower)
  426. this.actionList.push( {
  427. text: this.$t('common.continueText','确定并继续'),
  428. id: 'save_proceed'
  429. })
  430. this.collapse()
  431. }
  432. #end
  433. setTimeout(() => {
  434. uni.$emit('initCollapse')
  435. }, 50)
  436. uni.$on('initCollapse', () => {
  437. //初始化折叠面板高度高度
  438. this.collapse()
  439. })
  440. },
  441. onReady() {
  442. #set($rulesAll = "this."+${context.formRules})
  443. this.$nextTick(()=>{
  444. setTimeout(()=>{
  445. this.$refs.${context.formModel}.setRules(${rulesAll});
  446. },100)
  447. })
  448. },
  449. watch:{
  450. dataForm: {
  451. handler(val, oldVal) {
  452. #foreach($child in ${context.children})
  453. #set($className = "${child.className}")
  454. this.${className}()
  455. #end
  456. },
  457. deep: true
  458. }
  459. },
  460. methods:{
  461. handleAction(index) {
  462. if (this.actionList[index].id === 'save_add' || this.actionList[index].id === 'save_proceed') {
  463. this.submitForm(1)
  464. } else {
  465. this.calculation(this.actionList[index].id, index)
  466. }
  467. },
  468. onCollapseChange() {
  469. uni.$emit('initCollapse')
  470. },
  471. checkNumLimit() {
  472. if(this.isNumLimit && this.${context.formModel}[this.tableKey].length>=this.numLimit){
  473. #set($toast='$'+"u.toast")
  474. this.$toast(`${this.label}超出条数限制`);
  475. return true;
  476. }
  477. return false;
  478. },
  479. calculation(type, index) {
  480. if (type === 'upper') {
  481. this.index--
  482. this.actionList[index + 1].disabled = false
  483. if (this.index == 0) this.actionList[index].disabled = true
  484. } else {
  485. this.index++
  486. this.actionList[index - 1].disabled = false
  487. if (this.index == this.idList.length - 1) this.actionList[index].disabled = true
  488. }
  489. this.${context.formModel}.${pKeyName} = this.idList[this.index]
  490. this.initData()
  491. },
  492. changeData(model, index) {
  493. this.isEdit = false
  494. this.childIndex = index
  495. let modelAll = model.split("-");
  496. let faceMode = "";
  497. for (let i = 0; i < modelAll.length; i++) {
  498. faceMode += modelAll[i];
  499. }
  500. for(let key in this.ableRelation){
  501. if(key == faceMode && this.ableRelation[key]){
  502. let valueAll = this.ableRelation[key].split("-")
  503. if(valueAll.length>1){
  504. let value = this.${context.formModel}[valueAll[0]+"List"][index][valueAll[1]]
  505. if(Array.isArray(value)){
  506. this.${context.formModel}[valueAll[0]+"List"][index][valueAll[1]] = []
  507. }else{
  508. this.${context.formModel}[valueAll[0]+"List"][index][valueAll[1]] = undefined
  509. }
  510. }else{
  511. let value = this.${context.formModel}[this.ableRelation[key]]
  512. if(Array.isArray(value)){
  513. this.${context.formModel}[this.ableRelation[key]] = []
  514. }else{
  515. this.${context.formModel}[this.ableRelation[key]] = undefined
  516. }
  517. }
  518. }
  519. }
  520. for (let key in this.interfaceRes) {
  521. if (key != faceMode) {
  522. let faceReList = this.interfaceRes[key]
  523. for (let i = 0; i < faceReList.length; i++) {
  524. let relationField = faceReList[i].relationField
  525. let sourceType = faceReList[i].sourceType
  526. if (relationField == model && sourceType == 1) {
  527. let options = 'get' + key + 'Options';
  528. if(this[options]){
  529. this[options]()
  530. }
  531. this.changeData(key, index)
  532. }
  533. }
  534. }
  535. }
  536. },
  537. changeDataFormData(type, data, model,index,defaultValue ,edit) {
  538. if(!edit) {
  539. if (type == 2) {
  540. for (let i = 0; i < this.${context.formModel}[data].length; i++) {
  541. if (index == -1) {
  542. this.${context.formModel}[data][i][model] = defaultValue
  543. } else if (index == i) {
  544. this.${context.formModel}[data][i][model] = defaultValue
  545. }
  546. }
  547. } else {
  548. this.${context.formModel}[data] = defaultValue
  549. }
  550. }
  551. },
  552. clickIcon(label,tipLabel) {
  553. this.content = tipLabel
  554. this.title = label
  555. this.show = true
  556. },
  557. exist() {
  558. let title = [];
  559. let _ruleList = this.ruleList
  560. for (let k in _ruleList) {
  561. let childData = this.${context.formModel}[k]
  562. childData.forEach((item, index) => {
  563. for (let model in _ruleList[k]) {
  564. if (item[model] instanceof Array) {
  565. if (item[model].length == 0) {
  566. title.push(_ruleList[k][model])
  567. }
  568. } else if (!item[model] && item[model]!==0) {
  569. title.push(_ruleList[k][model])
  570. }
  571. }
  572. })
  573. }
  574. let _regList = this.regList
  575. for (let k in _regList) {
  576. let childData = this.${context.formModel}[k]
  577. for(let n in _regList[k]){
  578. for(let i=0;i<_regList[k][n].length;i++){
  579. const element = _regList[k][n][i]
  580. if (element.pattern) {
  581. element.pattern = element.pattern.toString()
  582. let start = element.pattern.indexOf('/')
  583. let stop = element.pattern.lastIndexOf('/')
  584. let str = element.pattern.substring(start + 1, stop)
  585. let reg = new RegExp(str)
  586. element.pattern = reg
  587. }
  588. childData.forEach((item, index) => {
  589. if(item[n] && !element.pattern.test(item[n])){
  590. title.push(element.message)
  591. }
  592. })
  593. }
  594. }
  595. }
  596. if (title.length > 0) {
  597. return title[0]
  598. }
  599. },
  600. resetForm(){
  601. #if(${context.webType}=='1')
  602. this.${context.formModel} = JSON.parse(JSON.stringify(this.dataValue))
  603. #foreach($fieLdsModel in ${context.form})
  604. #set($jnpfkey = "${fieLdsModel.jnpfKey}")
  605. #set($isEnd = "${fieLdsModel.isEnd}")
  606. #set($formModel = ${fieLdsModel.formModel})
  607. #set($model = "${formModel.model}")
  608. #set($outermost = ${formModel.outermost})
  609. #set($children = ${formModel.children})
  610. #if(${layoutList.contains($jnpfkey)})
  611. #if(${isEnd}=='0')
  612. #if(${outermost}=='0')
  613. this.${model}Current=${formModel.activeIndex}
  614. #end
  615. #end
  616. #end
  617. #end
  618. this.dataAll()
  619. #else
  620. uni.navigateBack()
  621. #end
  622. },
  623. dataAll(){
  624. #foreach($html in ${context.fields})
  625. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  626. #options($fieLdsModel,'')
  627. #end
  628. #foreach($masetkey in $mastTableList.entrySet())
  629. #set($fieldsAll = $masetkey.value)
  630. #foreach($html in ${fieldsAll})
  631. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  632. #options($fieLdsModel,'')
  633. #end
  634. #end
  635. #foreach($child in ${context.children})
  636. #set($className = "${child.className}")
  637. #foreach($childList in ${child.childList})
  638. #set($fieLdsModel = $childList.fieLdsModel)
  639. #options($fieLdsModel,$className)
  640. #end
  641. #end
  642. this.collapse()
  643. },
  644. dateTime(timeRule, timeType, timeTarget, timeValueData, dataValue) {
  645. let timeDataValue = null;
  646. let timeValue = Number(timeValueData)
  647. if (timeRule) {
  648. if (timeType == 1) {
  649. timeDataValue = timeValueData?timeValue:null
  650. } else if (timeType == 2) {
  651. timeDataValue = dataValue
  652. } else if (timeType == 3) {
  653. timeDataValue = new Date().getTime()
  654. } else if (timeType == 4) {
  655. let previousDate = '';
  656. if (timeTarget == 1 || timeTarget == 2) {
  657. previousDate = getDateDay(timeTarget, timeType, timeValue)
  658. timeDataValue = new Date(previousDate).getTime()
  659. } else if (timeTarget == 3) {
  660. previousDate = getBeforeData(timeValue)
  661. timeDataValue = new Date(previousDate).getTime()
  662. } else {
  663. timeDataValue = getBeforeTime(timeTarget, timeValue).getTime()
  664. }
  665. } else if (timeType == 5) {
  666. let previousDate = '';
  667. if (timeTarget == 1 || timeTarget == 2) {
  668. previousDate = getDateDay(timeTarget, timeType, timeValue)
  669. timeDataValue = new Date(previousDate).getTime()
  670. } else if (timeTarget == 3) {
  671. previousDate = getLaterData(timeValue)
  672. timeDataValue = new Date(previousDate).getTime()
  673. } else {
  674. timeDataValue = getLaterTime(timeTarget, timeValue).getTime()
  675. }
  676. }
  677. }
  678. return timeDataValue;
  679. },
  680. time(timeRule, timeType, timeTarget, timeValue, formatType, dataValue) {
  681. let format = formatType == 'HH:mm' ? 'HH:mm:00' : formatType
  682. let timeDataValue = null
  683. if (timeRule) {
  684. if (timeType == 1 && timeValue) {
  685. timeDataValue = timeValue || '00:00:00'
  686. if (timeDataValue.split(':').length == 3) {
  687. timeDataValue = timeDataValue
  688. } else {
  689. timeDataValue = timeDataValue + ':00'
  690. }
  691. } else if (timeType == 2) {
  692. timeDataValue = dataValue
  693. } else if (timeType == 3) {
  694. timeDataValue = this.jnpf.toDate(new Date(), format)
  695. } else if (timeType == 4) {
  696. let previousDate = '';
  697. previousDate = getBeforeTime(timeTarget, timeValue)
  698. timeDataValue = this.jnpf.toDate(previousDate, format)
  699. } else if (timeType == 5) {
  700. let previousDate = '';
  701. previousDate = getLaterTime(timeTarget, timeValue)
  702. timeDataValue = this.jnpf.toDate(previousDate, format)
  703. }
  704. }
  705. return timeDataValue;
  706. },
  707. #foreach($fields in ${context.fields})
  708. #set($fieLdsModel = $fields.formColumnModel.fieLdsModel)
  709. #optionsData($fieLdsModel,'')
  710. #end
  711. #foreach($masetkey in $mastTableList.entrySet())
  712. #set($fieldsAll = $masetkey.value)
  713. #foreach($fields in ${fieldsAll})
  714. #set($fieLdsModel = $fields.formMastTableModel.mastTable.fieLdsModel)
  715. #optionsData($fieLdsModel,'')
  716. #end
  717. #end
  718. #foreach($child in ${context.children})
  719. #set($className = "${child.className}")
  720. ${className}(){
  721. let table = this.${context.formModel}.${className}List
  722. let summaryField =${child.summaryField}
  723. let summaryFieldName =${child.summaryFieldName}
  724. #if($useFormPermission)
  725. for(let i=0;i<summaryField.length;i++){
  726. if(!this.${setPermission}.hasFormP("${tableModel}-"+summaryField[i],this.menuId)){
  727. summaryField.splice(i)
  728. }
  729. }
  730. #end
  731. let data ={}
  732. let thousandsField = ${child.thousandsField}
  733. for (let i in summaryField) {
  734. let map = {}
  735. let val = 0
  736. for (let j = 0; j < table.length; j++) {
  737. let summary = table[j][summaryField[i]];
  738. if (summary) {
  739. let data = isNaN(summary) ? 0 : Number(summary)
  740. val += data
  741. }
  742. }
  743. map.id = summaryField[i];
  744. map.name = summaryFieldName[summaryField[i]+"_i18n"] ? this.$t(summaryFieldName[summaryField[i]+"_i18n"]):summaryFieldName[summaryField[i]];
  745. map.val = (thousandsField.includes(summaryField[i]))? Number(val).toLocaleString('zh', {
  746. maximumFractionDigits: '2',
  747. minimumFractionDigits: '2'
  748. }): val.toFixed(2);
  749. data[summaryField[i]]=map;
  750. }
  751. return data;
  752. },
  753. #foreach($childList in ${child.childList})
  754. #set($className = "${child.className}")
  755. #set($fieLdsModel = $childList.fieLdsModel)
  756. #optionsData($fieLdsModel,$className)
  757. #end
  758. #end
  759. #foreach($fieLdsModel in ${context.form})
  760. #set($jnpfkey = "${fieLdsModel.jnpfKey}")
  761. #set($isEnd = "${fieLdsModel.isEnd}")
  762. #set($formModel = ${fieLdsModel.formModel})
  763. #set($outermost = ${formModel.outermost})
  764. #if($jnpfkey=='tab' || $jnpfkey=='steps')
  765. #if(${isEnd}=='0')
  766. #if(${outermost}=='0')
  767. ${formModel.model}(index) {
  768. this.${formModel.model}Current = index;
  769. this.timeKey = +new Date()
  770. #if($jnpfkey=='tab')
  771. this.collapse()
  772. setTimeout(() => {
  773. uni.$emit('initCollapse')
  774. }, 50)
  775. #end
  776. },
  777. #end
  778. #end
  779. #end
  780. #end
  781. initData(){
  782. #set($nextTick='$'+"nextTick")
  783. this.$nextTick(function(){
  784. if (this.${context.formModel}.${pKeyName}) {
  785. this.loading = true
  786. request({
  787. url: '/api/${context.module}/${context.className}/'+this.${context.formModel}.${pKeyName},
  788. method: 'get',
  789. }).then(res => {
  790. this.dataInfo(res.data)
  791. this.loading = false
  792. })
  793. }else {
  794. this.initDefaultData()
  795. }
  796. })
  797. },
  798. beforeSubmit(){
  799. const _data =this.dataList()
  800. return _data
  801. },
  802. #if($isFlow==false)
  803. submitForm(type){
  804. var _data = this.dataList()
  805. #set($refs = '$'+"refs")
  806. this.${refs}.${context.formModel}.validate(valid => {
  807. if (!valid) return
  808. #set($ruls='$'+"u")
  809. if (!!this.exist()) return this.${ruls}.toast(
  810. this.exist()
  811. )
  812. this.btnLoading = true
  813. if (this.${context.formModel}.${pKeyName}) {
  814. request({
  815. url: '/api/${context.module}/${context.className}/' + this.${context.formModel}.${pKeyName},
  816. method: 'put',
  817. data: _data,
  818. }).then(res => {
  819. uni.showToast({
  820. title: res.msg,
  821. complete: () => {
  822. setTimeout(() => {
  823. if(type!=1){
  824. uni.$emit('refresh')
  825. uni.navigateBack()
  826. }
  827. this.btnLoading = false
  828. }, 1500)
  829. }
  830. })
  831. }).catch(() => {
  832. this.btnLoading = false
  833. })
  834. }else {
  835. request({
  836. url: '/api/${context.module}/${context.className}',
  837. method: 'post',
  838. data: _data,
  839. }).then(res => {
  840. uni.showToast({
  841. title: res.msg,
  842. complete: () => {
  843. setTimeout(() => {
  844. if(type==1){
  845. this.${context.formModel} = JSON.parse(JSON.stringify(this.dataValue))
  846. this.initDefaultData()
  847. }else{
  848. uni.$emit('refresh')
  849. uni.navigateBack()
  850. }
  851. this.btnLoading = false
  852. }, 1500)
  853. }
  854. })
  855. }).catch(() => {
  856. this.btnLoading = false
  857. })
  858. }
  859. });
  860. },
  861. #end
  862. initDefaultData() {
  863. #foreach($html in ${context.fields})
  864. #set($fieLdsModel = $html.formColumnModel.fieLdsModel)
  865. #set($formModel='this.'+${context.formModel})
  866. #formDefaultData('mast',$fieLdsModel,${formModel})
  867. #end
  868. #foreach($masetkey in $mastTableList.entrySet())
  869. #set($fieldsAll = $masetkey.value)
  870. #foreach($html in ${fieldsAll})
  871. #set($fieLdsModel = $html.formMastTableModel.mastTable.fieLdsModel)
  872. #set($formModel='this.'+${context.formModel})
  873. #formDefaultData('mastTable',$fieLdsModel,${formModel})
  874. #end
  875. #end
  876. },
  877. selfInit() {
  878. useBaseStore().updateRelationData({})
  879. #if($isFlow)
  880. this.dataAll()
  881. this.initDefaultData()
  882. this.collapse()
  883. #end
  884. },
  885. selfGetInfo(dataForm){
  886. this.${context.formModel}.id = this.${context.formModel}.${pKeyName}
  887. this.dataInfo(dataForm)
  888. },
  889. #foreach($child in ${context.children})
  890. #set($className = "${child.className}")
  891. #set($isNumLimit = "${child.isNumLimit}")
  892. #set($numLimit = "${child.numLimit}")
  893. #set($label = "${child.label}")
  894. add${className}List(btnvalue){
  895. this.tableKey = '${className}List';
  896. this.isNumLimit = ${isNumLimit};
  897. this.numLimit = ${numLimit};
  898. this.label = '${label}';
  899. if (this.checkNumLimit()) return;
  900. let actionConfigMap ={
  901. #foreach($footerList in ${child.footerBtnsList})
  902. #set($btnvalue = "$footerList.value")
  903. #set($btnlabel = "$footerList.label")
  904. #set($btnshow = $footerList.show)
  905. #set($btnType = "$footerList.btnType")
  906. #set($btnIcon = "$footerList.btnIcon")
  907. #set($actionConfig = "$footerList.actionConfig")
  908. #if($btnvalue!='add' && $btnvalue!='batchRemove')
  909. "$btnvalue":$actionConfig,
  910. #end
  911. #end
  912. }
  913. if(btnvalue == 'add'){
  914. let value={
  915. #foreach($childData in ${child.childList})
  916. #set($fieLdsModel = ${childData.fieLdsModel})
  917. #set($vModel = "${fieLdsModel.vModel}")
  918. #set($config = ${fieLdsModel.config})
  919. #set($dataType = "${config.dataType}")
  920. #if($vModel)
  921. #if($!config.valueType=='String')
  922. $!{vModel} : '$!{config.defaultValue}',
  923. #elseif($!config.valueType=='undefined')
  924. $!{vModel} : undefined,
  925. #else
  926. $!{vModel} : $!{config.defaultValue},
  927. #end
  928. #if(${dataType}=='dictionary' || ${dataType}=='dynamic')
  929. ${vModel}Options:[],
  930. #end
  931. #end
  932. #end
  933. }
  934. if(this.tableKey) {
  935. #foreach($childData in ${child.childList})
  936. #set($fieLdsModel = ${childData.fieLdsModel})
  937. #set($formModel="value")
  938. #formDefaultData('table',$fieLdsModel,${formModel})
  939. #end
  940. }
  941. this.get${className}List(value)
  942. this.childIndex = -1
  943. this.collapse()
  944. }else {
  945. const data = {
  946. actionConfig: actionConfigMap[btnvalue],
  947. formData: this.${context.formModel}
  948. }
  949. uni.navigateTo({
  950. url: '/pages/apply/tableLinkage/index?data=' + encodeURIComponent(JSON.stringify(data))
  951. })
  952. }
  953. },
  954. del${className}List(index,showConfirm=false) {
  955. const handleRemove = ()=>{
  956. this.${context.formModel}.${className}List.splice(index, 1);
  957. this.collapse()
  958. }
  959. if(!showConfirm) return handleRemove()
  960. uni.showModal({
  961. title: '提示',
  962. content: '确认删除该条信息吗?',
  963. success: (res)=> {
  964. if (res.confirm) handleRemove()
  965. }
  966. })
  967. },
  968. copy${className}List(index) {
  969. this.tableKey = '${className}List';
  970. this.isNumLimit = ${isNumLimit};
  971. this.numLimit = ${numLimit};
  972. this.label = '${label}';
  973. if (this.checkNumLimit()) return;
  974. let tableField = '$child.tableModel'
  975. let result = {}
  976. let item = {
  977. #foreach($childData in ${child.childFieldList})
  978. #set($fieLdsModel = ${childData.fieLdsModel})
  979. #set($vModel = "${fieLdsModel.vModel}")
  980. #set($config = ${fieLdsModel.config})
  981. #set($jnpfkey = ${config.jnpfKey})
  982. #if(!${systemJnpfKey.contains(${jnpfkey})})
  983. #set($dataType = "${config.dataType}")
  984. #if($vModel)
  985. #if($!config.valueType=='String')
  986. $!{vModel} : '$!{config.defaultValue}',
  987. #elseif($!config.valueType=='undefined')
  988. $!{vModel} : undefined,
  989. #else
  990. $!{vModel} : $!{config.defaultValue},
  991. #end
  992. #if(${dataType}=='dictionary' || ${dataType}=='dynamic')
  993. ${vModel}Options:[],
  994. #end
  995. #end
  996. #end
  997. #end
  998. }
  999. let data = JSON.parse(JSON.stringify(this.${context.formModel}.${className}List[index]))
  1000. for(let key in item){
  1001. result[key] = data[key]
  1002. }
  1003. this.${context.formModel}.${className}List.push(result)
  1004. this.collapse()
  1005. },
  1006. get${className}List(value){
  1007. let item = {
  1008. #foreach($childData in ${child.childList})
  1009. #set($fieLdsModel = ${childData.fieLdsModel})
  1010. #set($vModel = "${fieLdsModel.vModel}")
  1011. #set($config = ${fieLdsModel.config})
  1012. #set($dataType = "${config.dataType}")
  1013. #if($vModel)
  1014. #if($!config.valueType=='String')
  1015. $!{vModel} : '$!{config.defaultValue}',
  1016. #elseif($!config.valueType=='undefined')
  1017. $!{vModel} : undefined,
  1018. #else
  1019. $!{vModel} : $!{config.defaultValue},
  1020. #end
  1021. #if(${dataType}=='dictionary' || ${dataType}=='dynamic')
  1022. ${vModel}Options:[],
  1023. #end
  1024. #end
  1025. #end
  1026. }
  1027. if(this.tableKey){
  1028. #foreach($childData in ${child.childList})
  1029. #set($fieLdsModel = ${childData.fieLdsModel})
  1030. #set($formModel="item")
  1031. #formDefaultData('table',$fieLdsModel,${formModel})
  1032. #end
  1033. }
  1034. let result = {...item,...value}
  1035. this.${context.formModel}.${className}List.push(result)
  1036. this.childIndex=this.${context.formModel}.${className}List.length-1
  1037. this.isEdit = true
  1038. #foreach($childList in ${child.childList})
  1039. #set($fieLdsModel = $childList.fieLdsModel)
  1040. #set($vModel = "${fieLdsModel.vModel}")
  1041. #set($field = "${fieLdsModel.vModel}")
  1042. #set($config = ${fieLdsModel.config})
  1043. #set($dataType = "${config.dataType}")
  1044. #if(${dataType}=='dynamic')
  1045. this.get${className}${vModel}Options()
  1046. #end
  1047. #end
  1048. this.isEdit = false
  1049. setTimeout(() => {
  1050. uni.$emit('initCollapse')
  1051. }, 50)
  1052. },
  1053. #end
  1054. dataList(){
  1055. var _data = this.${context.formModel};
  1056. return _data;
  1057. },
  1058. dataInfo(dataAll){
  1059. let dataList = JSON.parse(JSON.stringify(dataAll))
  1060. #foreach($child in ${context.children})
  1061. #set($className = "${child.className}")
  1062. let $className = JSON.parse(JSON.stringify(dataList.${className}List))
  1063. dataList.${className}List = []
  1064. #end
  1065. this.${context.formModel}=dataList
  1066. this.isEdit = true
  1067. this.dataAll()
  1068. this.isEdit = false
  1069. #foreach($child in ${context.children})
  1070. #set($className = "${child.className}")
  1071. for (let i = 0; i < ${className}.length; i++) {
  1072. this.get${className}List(${className}[i])
  1073. }
  1074. #end
  1075. this.childIndex=-1
  1076. this.collapse()
  1077. setTimeout(() => {
  1078. uni.$emit('initCollapse')
  1079. }, 50)
  1080. },
  1081. collapse(){
  1082. setTimeout(()=> {
  1083. #foreach($fieLdsModel in ${context.form})
  1084. #set($jnpfkey = "${fieLdsModel.jnpfKey}")
  1085. #set($isEnd = "${fieLdsModel.isEnd}")
  1086. #set($formModel = ${fieLdsModel.formModel})
  1087. #set($outermost = ${formModel.outermost})
  1088. #set($config=$formModel.config)
  1089. #if(${layoutList.contains($jnpfkey)})
  1090. #if(${config.app}==true)
  1091. #if(${isEnd}=='0')
  1092. #if(${outermost}=='0')
  1093. this.$refs.${formModel.model}Current && this.$refs.${formModel.model}Current.init()
  1094. #end
  1095. #end
  1096. #end
  1097. #end
  1098. #end
  1099. }, 50);
  1100. },
  1101. },
  1102. }
  1103. </script>
  1104. <style>
  1105. page{
  1106. background-color: #f0f2f6;
  1107. }
  1108. </style>