form.vue.vm 34 KB

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