365083af66ace9eb70e62af27849f90e49263829.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <#include "/common/utils.ftl">
  2. <template>
  3. <a-spin :spinning="confirmLoading">
  4. <#assign form_popup = false>
  5. <#assign form_cat_tree = false>
  6. <#assign form_cat_back = "">
  7. <#assign form_span = 24>
  8. <a-tabs v-model="activeKey" @change="handleChangeTabs">
  9. <!--主表区域 -->
  10. <a-tab-pane tab="${tableVo.ftlDescription}" :key="refKeys[0]" :forceRender="true">
  11. <a-form-model ref="form" :model="model" :rules="validatorRules">
  12. <a-row>
  13. <#list columns as po>
  14. <#if po.isShow =='Y' && po.fieldName != 'id'>
  15. <#assign form_field_dictCode="">
  16. <#if po.dictTable?default("")?trim?length gt 1 && po.dictText?default("")?trim?length gt 1 && po.dictField?default("")?trim?length gt 1>
  17. <#assign form_field_dictCode="${po.dictTable},${po.dictText},${po.dictField}">
  18. <#elseif po.dictField?default("")?trim?length gt 1>
  19. <#assign form_field_dictCode="${po.dictField}">
  20. </#if>
  21. <#if po.classType =='textarea'>
  22. <a-col :span="24">
  23. <a-form-model-item label="${po.filedComment}" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="${autoStringSuffixForModel(po)}">
  24. <#else>
  25. <a-col :xs="24" :sm="12">
  26. <a-form-model-item label="${po.filedComment}" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="${autoStringSuffixForModel(po)}">
  27. </#if>
  28. <#if po.classType =='date'>
  29. <j-date placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" style="width: 100%" <#if po.readonly=='Y'>disabled</#if>/>
  30. <#elseif po.classType =='datetime'>
  31. <j-date placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" <#if po.readonly=='Y'>disabled</#if>/>
  32. <#elseif po.classType =='time'>
  33. <j-time placeholder="请选择${po.filedComment}" v-model="model.${po.fieldName}" style="width: 100%" <#if po.readonly=='Y'>disabled</#if>/>
  34. <#elseif po.classType =='popup'>
  35. <#assign form_popup=true>
  36. <j-popup
  37. v-model="model.${po.fieldName}"
  38. field="${po.fieldName}"
  39. org-fields="${po.dictField}"
  40. dest-fields="${Format.underlineToHump(po.dictText)}"
  41. code="${po.dictTable}"
  42. :multi="${po.extendParams.popupMulti?c}"
  43. @input="popupCallback"
  44. <#if po.readonly=='Y'>disabled</#if>/>
  45. <#elseif po.classType =='sel_depart'>
  46. <j-select-depart v-model="model.${po.fieldName}" multi <#if po.readonly=='Y'>disabled</#if>/>
  47. <#elseif po.classType =='switch'>
  48. <j-switch v-model="model.${po.fieldName}" <#if po.dictField!= 'is_open'>:options="${po.dictField}"</#if> <#if po.readonly=='Y'>disabled</#if>></j-switch>
  49. <#elseif po.classType =='pca'>
  50. <j-area-linkage type="cascader" v-model="model.${po.fieldName}" placeholder="请输入省市区" <#if po.readonly=='Y'>disabled</#if>/>
  51. <#elseif po.classType =='markdown'>
  52. <j-markdown-editor v-model="model.${autoStringSuffixForModel(po)}" id="${po.fieldName}"></j-markdown-editor>
  53. <#elseif po.classType =='password'>
  54. <a-input-password v-model="model.${po.fieldName}" placeholder="请输入${po.filedComment}" <#if po.readonly=='Y'>disabled</#if>/>
  55. <#elseif po.classType =='sel_user'>
  56. <j-select-user-by-dep v-model="model.${po.fieldName}" <#if po.readonly=='Y'>disabled</#if>/>
  57. <#elseif po.classType =='textarea'>
  58. <a-textarea v-model="model.${autoStringSuffixForModel(po)}" rows="4" placeholder="请输入${po.filedComment}" <#if po.readonly=='Y'>disabled</#if>/>
  59. <#elseif po.classType=='list' || po.classType=='radio'>
  60. <j-dict-select-tag type="${po.classType}" v-model="model.${po.fieldName}" dictCode="${form_field_dictCode}" placeholder="请选择${po.filedComment}" <#if po.readonly=='Y'>disabled</#if>/>
  61. <#elseif po.classType=='list_multi' || po.classType=='checkbox'>
  62. <j-multi-select-tag type="${po.classType}" v-model="model.${po.fieldName}" dictCode="${form_field_dictCode}" placeholder="请选择${po.filedComment}" <#if po.readonly=='Y'>disabled</#if>/>
  63. <#elseif po.classType=='sel_search'>
  64. <j-search-select-tag v-model="model.${po.fieldName}" dict="${form_field_dictCode}" <#if po.readonly=='Y'>disabled</#if>/>
  65. <#elseif po.classType=='cat_tree'>
  66. <#assign form_cat_tree = true>
  67. <j-category-select v-model="model.${po.fieldName}" pcode="${po.dictField?default("")}" placeholder="请选择${po.filedComment}" <#if po.dictText?default("")?trim?length gt 1>back="${dashedToCamel(po.dictText)}" @change="handleCategoryChange"</#if> <#if po.readonly=='Y'>disabled</#if>/>
  68. <#if po.dictText?default("")?trim?length gt 1>
  69. <#assign form_cat_back = "${po.dictText}">
  70. </#if>
  71. <#elseif po.fieldDbType=='int' || po.fieldDbType=='double' || po.fieldDbType=='BigDecimal'>
  72. <a-input-number v-model="model.${po.fieldName}" placeholder="请输入${po.filedComment}" style="width: 100%" <#if po.readonly=='Y'>disabled</#if>/>
  73. <#elseif po.classType=='file'>
  74. <j-upload v-model="model.${po.fieldName}" <#if po.readonly=='Y'>disabled</#if> <#if po.uploadnum??>:number=${po.uploadnum}</#if>></j-upload>
  75. <#elseif po.classType=='image'>
  76. <j-image-upload isMultiple <#if po.uploadnum??>:number=${po.uploadnum}</#if> v-model="model.${po.fieldName}" <#if po.readonly=='Y'>disabled</#if>></j-image-upload>
  77. <#elseif po.classType=='umeditor'>
  78. <j-editor v-model="model.${po.fieldName}" <#if po.readonly=='Y'>disabled</#if>/>
  79. <#elseif po.classType == 'sel_tree'>
  80. <j-tree-select
  81. ref="treeSelect"
  82. placeholder="请选择${po.filedComment}"
  83. v-model="model.${po.fieldName}"
  84. <#if po.dictText??>
  85. <#if po.dictText?split(',')[2]?? && po.dictText?split(',')[0]??>
  86. dict="${po.dictTable},${po.dictText?split(',')[2]},${po.dictText?split(',')[0]}"
  87. <#elseif po.dictText?split(',')[1]??>
  88. pidField="${po.dictText?split(',')[1]}"
  89. <#elseif po.dictText?split(',')[3]??>
  90. hasChildField="${po.dictText?split(',')[3]}"
  91. </#if>
  92. </#if>
  93. pidValue="${po.dictField}"
  94. <#if po.readonly=='Y'>disabled</#if>>
  95. </j-tree-select>
  96. <#else>
  97. <a-input v-model="model.${autoStringSuffixForModel(po)}" placeholder="请输入${po.filedComment}" <#if po.readonly=='Y'>disabled</#if>></a-input>
  98. </#if>
  99. </a-form-model-item>
  100. </a-col>
  101. </#if>
  102. </#list>
  103. </a-row>
  104. </a-form-model>
  105. </a-tab-pane>
  106. <!--子表单区域 -->
  107. <#list subTables as sub><#rt/>
  108. <#if sub.foreignRelationType =='1'>
  109. <a-tab-pane tab="${sub.ftlDescription}" :key="refKeys[${sub_index+1}]" :forceRender="true">
  110. <${Format.humpToShortbar(sub.entityName)}-form ref="${sub.entityName?uncap_first}Form" @validateError="validateError"></${Format.humpToShortbar(sub.entityName)}-form>
  111. </a-tab-pane>
  112. <#else>
  113. <a-tab-pane tab="${sub.ftlDescription}" :key="refKeys[${sub_index+1}]" :forceRender="true">
  114. <j-editable-table
  115. :ref="refKeys[${sub_index+1}]"
  116. :loading="${sub.entityName?uncap_first}Table.loading"
  117. :columns="${sub.entityName?uncap_first}Table.columns"
  118. :dataSource="${sub.entityName?uncap_first}Table.dataSource"
  119. :maxHeight="300"
  120. :rowNumber="true"
  121. :rowSelection="true"
  122. :actionButton="true"/>
  123. </a-tab-pane>
  124. </#if>
  125. </#list>
  126. </a-tabs>
  127. </a-spin>
  128. </j-modal>
  129. </template>
  130. <script>
  131. import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  132. import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  133. import { validateDuplicateValue } from '@/utils/util'
  134. import { VALIDATE_NO_PASSED, validateFormModelAndTables } from '@/utils/JEditableTableUtil'
  135. <#list subTables as sub>
  136. <#if sub.foreignRelationType =='1'>
  137. import ${sub.entityName}Form from './${sub.entityName}Form.vue'
  138. </#if>
  139. </#list>
  140. export default {
  141. name: '${entityName}Forml',
  142. mixins: [JEditableTableModelMixin],
  143. components: {
  144. <#list subTables as sub>
  145. <#if sub.foreignRelationType =='1'>
  146. ${sub.entityName}Form,
  147. </#if>
  148. </#list>
  149. },
  150. data() {
  151. return {
  152. labelCol: {
  153. xs: { span: 24 },
  154. sm: { span: 6 },
  155. },
  156. wrapperCol: {
  157. xs: { span: 24 },
  158. sm: { span: 16 },
  159. },
  160. labelCol2: {
  161. xs: { span: 24 },
  162. sm: { span: 3 },
  163. },
  164. wrapperCol2: {
  165. xs: { span: 24 },
  166. sm: { span: 20 },
  167. },
  168. // 新增时子表默认添加几行空数据
  169. addDefaultRowNum: 1,
  170. model:{
  171. <#include "/common/init/initValue.ftl">
  172. },
  173. <#include "/common/validatorRulesTemplate/main.ftl">
  174. refKeys: ['${tableVo.entityName?uncap_first}',<#list subTables as sub>'${sub.entityName?uncap_first}', </#list>],
  175. <#assign hasOne2Many = false>
  176. tableKeys:[<#list subTables as sub><#if sub.foreignRelationType =='0'>'${sub.entityName?uncap_first}', <#assign hasOne2Many = true></#if></#list>],
  177. activeKey: '${tableVo.entityName?uncap_first}',
  178. <#list subTables as sub><#rt/>
  179. // ${sub.ftlDescription}
  180. ${sub.entityName?uncap_first}Table: {
  181. loading: false,
  182. dataSource: [],
  183. columns: [
  184. <#if sub.foreignRelationType =='0'>
  185. <#assign popupBackFields = "">
  186. <#-- 循环子表的列 开始 -->
  187. <#list sub.colums as col><#rt/>
  188. <#if col.isShow =='Y'>
  189. <#if col.filedComment !='外键' >
  190. {
  191. title: '${col.filedComment}',
  192. key: '${autoStringSuffixForModel(col)}',
  193. <#if col.classType =='date'>
  194. type: FormTypes.date,
  195. <#if col.readonly=='Y'>
  196. disabled:true,
  197. </#if>
  198. <#elseif col.classType =='datetime'>
  199. type: FormTypes.datetime,
  200. <#if col.readonly=='Y'>
  201. disabled:true,
  202. </#if>
  203. <#elseif "int,decimal,double,"?contains(col.classType)>
  204. type: FormTypes.inputNumber,
  205. <#if col.readonly=='Y'>
  206. disabled:true,
  207. </#if>
  208. <#elseif col.classType =='list' || col.classType =='radio'>
  209. type: FormTypes.select,
  210. <#if col.dictTable?default("")?trim?length gt 1>
  211. dictCode:"${col.dictTable},${col.dictText},${col.dictField}",
  212. <#else>
  213. dictCode:"${col.dictField}",
  214. </#if>
  215. <#if col.readonly=='Y'>
  216. disabled:true,
  217. </#if>
  218. <#elseif col.classType =='list_multi' || col.classType =='checkbox'>
  219. type: FormTypes.list_multi,
  220. <#if col.dictTable?default("")?trim?length gt 1>
  221. dictCode:"${col.dictTable},${col.dictText},${col.dictField}",
  222. <#else>
  223. dictCode:"${col.dictField}",
  224. </#if>
  225. <#if col.readonly=='Y'>
  226. disabled:true,
  227. </#if>
  228. <#elseif col.classType =='sel_search'>
  229. type: FormTypes.sel_search,
  230. <#if col.dictTable?default("")?trim?length gt 1>
  231. dictCode:"${col.dictTable},${col.dictText},${col.dictField}",
  232. <#else>
  233. dictCode:"${col.dictField}",
  234. </#if>
  235. <#if col.readonly=='Y'>
  236. disabled:true,
  237. </#if>
  238. <#elseif col.classType =='switch'>
  239. type: FormTypes.checkbox,
  240. <#if col.dictField == 'is_open'>
  241. customValue: ['Y', 'N'],
  242. <#else>
  243. customValue: ${col.dictField},
  244. </#if>
  245. <#if col.readonly=='Y'>
  246. disabled:true,
  247. </#if>
  248. <#elseif col.classType =='image'>
  249. type: FormTypes.image,
  250. token:true,
  251. responseName:"message",
  252. <#if col.readonly=='Y'>
  253. disabled:true,
  254. </#if>
  255. <#if col.uploadnum??>
  256. number: ${col.uploadnum},
  257. </#if>
  258. <#elseif col.classType =='file'>
  259. type: FormTypes.file,
  260. token:true,
  261. responseName:"message",
  262. <#if col.readonly=='Y'>
  263. disabled:true,
  264. </#if>
  265. <#if col.uploadnum??>
  266. number: ${col.uploadnum},
  267. </#if>
  268. <#elseif col.classType =='popup'>
  269. <#if popupBackFields?length gt 0>
  270. <#assign popupBackFields = "${popupBackFields}"+","+"${col.dictText}">
  271. <#else>
  272. <#assign popupBackFields = "${col.dictText}">
  273. </#if>
  274. type: FormTypes.popup,
  275. popupCode:"${col.dictTable}",
  276. destFields:"${Format.underlineToHump(col.dictText)}",
  277. orgFields:"${col.dictField}",
  278. <#if col.readonly=='Y'>
  279. disabled:true,
  280. </#if>
  281. <#elseif col.fieldDbType=='int' || col.fieldDbType=='double' || col.fieldDbType=='BigDecimal'>
  282. type: FormTypes.inputNumber,
  283. <#if col.readonly=='Y'>
  284. disabled:true,
  285. </#if>
  286. <#else>
  287. type: FormTypes.input,
  288. <#if col.readonly=='Y'>
  289. disabled:true,
  290. </#if>
  291. </#if>
  292. <#if col.classType =='list_multi' || col.classType =='checkbox'>
  293. width:"250px",
  294. <#else>
  295. width:"200px",
  296. </#if>
  297. <#if col.classType =='file'>
  298. placeholder: '请选择文件',
  299. <#else>
  300. placeholder: '请输入${'$'}{title}',
  301. </#if>
  302. <#if col.defaultVal??>
  303. <#if col.fieldDbType=="BigDecimal" || col.fieldDbType=="double" || col.fieldDbType=="int">
  304. defaultValue:${col.defaultVal},
  305. <#else>
  306. defaultValue:"${col.defaultVal}",
  307. </#if>
  308. <#else>
  309. defaultValue:'',
  310. </#if>
  311. <#-- 子表的校验 -->
  312. <#assign subFieldValidType = col.fieldValidType!''>
  313. <#-- 非空校验 -->
  314. <#if col.nullable == 'N' || subFieldValidType == '*'>
  315. validateRules: [{ required: true, message: '${'$'}{title}不能为空' }],
  316. <#-- 其他情况下,只要有值就被认为是正则校验 -->
  317. <#elseif subFieldValidType?length gt 0>
  318. <#assign subMessage = '格式不正确'>
  319. <#if subFieldValidType == 'only' >
  320. <#assign subMessage = '不能重复'>
  321. </#if>
  322. validateRules: [{ pattern: "${subFieldValidType}", message: "${'$'}{title}${subMessage}" }],
  323. </#if>
  324. },
  325. </#if>
  326. </#if>
  327. </#list>
  328. <#-- 循环子表的列 结束 -->
  329. <#-- 处理popup的隐藏列 -->
  330. <#if popupBackFields?length gt 0>
  331. <#list popupBackFields?split(",") as item>
  332. <#if item?length gt 0>
  333. <#assign tempItemFlag = true>
  334. <#list sub.colums as col>
  335. <#if col.isShow =='Y' && col.fieldName == item>
  336. <#assign tempItemFlag = false>
  337. </#if>
  338. </#list>
  339. <#if tempItemFlag>
  340. {
  341. title: '${item}',
  342. key: '${item}',
  343. type:"hidden"
  344. },
  345. </#if>
  346. </#if>
  347. </#list>
  348. </#if>
  349. </#if>
  350. ]
  351. },
  352. </#list>
  353. url: {
  354. add: "/${entityPackage}/${entityName?uncap_first}/add",
  355. edit: "/${entityPackage}/${entityName?uncap_first}/edit",
  356. ${tableVo.entityName?uncap_first}: {
  357. list: '/${entityPackage}/${entityName?uncap_first}/queryById'
  358. },
  359. <#list subTables as sub><#rt/>
  360. ${sub.entityName?uncap_first}: {
  361. list: '/${entityPackage}/${entityName?uncap_first}/query${sub.entityName}ByMainId'
  362. },
  363. </#list>
  364. }
  365. }
  366. },
  367. methods: {
  368. getAllTable() {
  369. <#if hasOne2Many==true>
  370. let values = this.tableKeys.map(key => getRefPromise(this, key))
  371. return Promise.all(values)
  372. <#else>
  373. return new Promise(resolve => {
  374. resolve([]);
  375. })
  376. </#if>
  377. },
  378. /** 调用完edit()方法之后会自动调用此方法 */
  379. editAfter() {
  380. this.$nextTick(() => {
  381. <#list subTables as sub><#rt/>
  382. <#if sub.foreignRelationType =='1'>
  383. this.$refs.${sub.entityName?uncap_first}Form.initFormData(this.url.${sub.entityName?uncap_first}.list,this.model.id)
  384. </#if>
  385. </#list>
  386. })
  387. // 加载子表数据
  388. if (this.model.id) {
  389. let params = { id: this.model.id }
  390. <#list subTables as sub><#rt/>
  391. <#if sub.foreignRelationType =='0'>
  392. this.requestSubTableData(this.url.${sub.entityName?uncap_first}.list, params, this.${sub.entityName?uncap_first}Table)
  393. </#if>
  394. </#list>
  395. }
  396. },
  397. //校验所有一对一子表表单
  398. validateSubForm(allValues){
  399. return new Promise((resolve,reject)=>{
  400. Promise.all([
  401. <#list subTables as sub><#rt/>
  402. <#if sub.foreignRelationType =='1'>
  403. this.$refs.${sub.entityName?uncap_first}Form.validate(${sub_index}),
  404. </#if>
  405. </#list>
  406. ]).then(() => {
  407. resolve(allValues)
  408. }).catch(e => {
  409. reject(e)
  410. })
  411. })
  412. },
  413. /** 整理成formData */
  414. classifyIntoFormData(allValues) {
  415. let main = Object.assign(this.model, allValues.formValue)
  416. return {
  417. ...main, // 展开
  418. <#assign subManyIndex = 0>
  419. <#list subTables as sub><#rt/>
  420. <#if sub.foreignRelationType =='0'>
  421. ${sub.entityName?uncap_first}List: allValues.tablesValue[${subManyIndex}].values,
  422. <#assign subManyIndex = subManyIndex+1>
  423. <#else>
  424. ${sub.entityName?uncap_first}List: this.$refs.${sub.entityName?uncap_first}Form.getFormData(),
  425. </#if>
  426. </#list>
  427. }
  428. },
  429. /** 确定按钮点击事件 */
  430. handleOk() {
  431. /** 触发表单验证 */
  432. this.getAllTable().then(tables => {
  433. return validateFormModelAndTables(this.$refs.form,this.model, tables)
  434. }).then(allValues => {
  435. /** 一次性验证一对一的所有子表 */
  436. return this.validateSubForm(allValues)
  437. }).then(allValues => {
  438. if (typeof this.classifyIntoFormData !== 'function') {
  439. throw this.throwNotFunction('classifyIntoFormData')
  440. }
  441. console.log("this.classifyIntoFormData",typeof this.classifyIntoFormData)
  442. let formData = this.classifyIntoFormData(allValues)
  443. // 发起请求
  444. return this.request(formData)
  445. }).catch(e => {
  446. if (e.error === VALIDATE_NO_PASSED) {
  447. // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
  448. this.activeKey = e.index == null ? this.refKeys[0] : this.refKeys[e.index+1]
  449. } else {
  450. console.error(e)
  451. }
  452. })
  453. },
  454. validateError(msg){
  455. this.$message.error(msg)
  456. },
  457. close() {
  458. this.visible = false
  459. this.$emit('close')
  460. this.$refs.form.clearValidate();
  461. },
  462. <#if form_popup>
  463. popupCallback(value,row){
  464. this.model = Object.assign(this.model, row);
  465. },
  466. </#if>
  467. <#if form_cat_tree>
  468. handleCategoryChange(value,backObj){
  469. this.model = Object.assign(this.model, backObj);
  470. }
  471. </#if>
  472. }
  473. }
  474. </script>
  475. <style scoped>
  476. </style>