9c49531c497596a48f4a90873fdb701b5a43fd63.svn-base 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <#list subTables as subTab>
  2. #segment#${subTab.entityName}Modal.vue
  3. <template>
  4. <j-modal
  5. :title="title"
  6. :width="800"
  7. :visible="visible"
  8. :okButtonProps="{ props: {disabled: disableSubmit} }"
  9. :confirmLoading="confirmLoading"
  10. switchFullscreen
  11. @ok="handleOk"
  12. @cancel="handleCancel"
  13. cancelText="关闭">
  14. <a-spin :spinning="confirmLoading">
  15. <a-form :form="form">
  16. <#list subTab.colums as po><#rt/>
  17. <#if po.fieldName !='id'><#rt/>
  18. <a-form-item
  19. :labelCol="labelCol"
  20. :wrapperCol="wrapperCol"
  21. label="${po.filedComment}"
  22. <#if subTab.foreignKeys[0]?uncap_first == po.fieldName>
  23. :hidden="hiding"
  24. </#if>
  25. hasFeedback>
  26. <#if po.fieldType =='date'>
  27. <a-date-picker v-decorator="[ '${po.fieldName}', <#if po.nullable =='N'>validatorRules.${po.fieldName} <#else>{}</#if>]" />
  28. <#elseif po.fieldType =='datetime'>
  29. <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ '${po.fieldName}', <#if po.nullable =='N'>validatorRules.${po.fieldName} <#else>{}</#if>]" />
  30. <#elseif "int,decimal,double,"?contains(po.fieldType)>
  31. <a-input-number v-decorator="[ '${po.fieldName}', <#if po.nullable =='N'>validatorRules.${po.fieldName} <#else>{}</#if>]" />
  32. <#else>
  33. <#if subTab.foreignKeys[0]?uncap_first == po.fieldName>
  34. <a-input placeholder="请输入${po.filedComment}" v-decorator="['${po.fieldName}', {'initialValue':this.mainId}]" />
  35. <#else>
  36. <a-input placeholder="请输入${po.filedComment}" v-decorator="['${po.fieldName}', <#if po.nullable =='N'>validatorRules.${po.fieldName} <#else>{}</#if>]" />
  37. </#if>
  38. </#if>
  39. </a-form-item>
  40. </#if>
  41. </#list>
  42. </a-form>
  43. </a-spin>
  44. </j-modal>
  45. </template>
  46. <script>
  47. import {httpAction} from '@/api/manage'
  48. import pick from 'lodash.pick'
  49. import moment from 'moment'
  50. import JDate from '@/components/jeecg/JDate'
  51. export default {
  52. components: {
  53. JDate
  54. },
  55. name: '${subTab.entityName}Modal',
  56. data() {
  57. return {
  58. title: '操作',
  59. visible: false,
  60. model: {},
  61. labelCol: {
  62. xs: {span: 24},
  63. sm: {span: 5}
  64. },
  65. wrapperCol: {
  66. xs: {span: 24},
  67. sm: {span: 16}
  68. },
  69. moment,
  70. format: 'YYYY-MM-DD HH:mm:ss',
  71. disableSubmit: false,
  72. mainId: '',
  73. hiding: false,
  74. confirmLoading: false,
  75. form: this.$form.createForm(this),
  76. validatorRules: {
  77. <#list subTab.colums as po>
  78. <#if po.fieldName !='id' && subTab.foreignKeys[0]?uncap_first != po.fieldName>
  79. <#if po.nullable =='N'>
  80. ${po.fieldName}: { rules: [{ required: true, message: '请输入${po.filedComment}!' }] },
  81. </#if>
  82. </#if>
  83. </#list>
  84. },
  85. url: {
  86. add: '/${entityPackage}/${entityName?uncap_first}/add${subTab.entityName}',
  87. edit: '/${entityPackage}/${entityName?uncap_first}/edit${subTab.entityName}'
  88. }
  89. }
  90. },
  91. created() {
  92. },
  93. methods: {
  94. add(mainId) {
  95. if (mainId) {
  96. this.edit({mainId}, '')
  97. } else {
  98. this.$message.warning('请选择一条数据')
  99. }
  100. },
  101. detail(record) {
  102. this.edit(record, 'd')
  103. },
  104. edit(record, v) {
  105. if (v == 'e') {
  106. this.hiding = false;
  107. this.disableSubmit = false;
  108. } else if (v == 'd') {
  109. this.hiding = false;
  110. this.disableSubmit = true;
  111. } else {
  112. this.hiding = true;
  113. this.disableSubmit = false;
  114. }
  115. this.form.resetFields();
  116. this.mainId = record.mainId;
  117. this.model = Object.assign({}, record);
  118. this.visible = true;
  119. this.$nextTick(() => {
  120. this.form.setFieldsValue(pick(this.model, <#list subTab.colums as col>'${col.fieldName}', </#list>))
  121. // 时间格式化
  122. <#list subTab.colums as col><#rt/>
  123. <#if col.fieldName !='id' && (col.fieldType =='date' || col.fieldType =='datetime')>
  124. this.form.setFieldsValue({ ${col.fieldName}: this.model.${col.fieldName} ? moment(this.model.${col.fieldName}) : null })
  125. </#if>
  126. </#list>
  127. })
  128. },
  129. close() {
  130. this.$emit('close');
  131. this.visible = false;
  132. },
  133. handleOk() {
  134. const that = this;
  135. // 触发表单验证
  136. this.form.validateFields((err, values) => {
  137. if (!err) {
  138. that.confirmLoading = true;
  139. let httpurl = '';
  140. let method = '';
  141. if (!this.model.id) {
  142. httpurl += this.url.add;
  143. method = 'post';
  144. } else {
  145. httpurl += this.url.edit;
  146. method = 'post';
  147. }
  148. let formData = Object.assign(this.model, values);
  149. //时间格式化
  150. <#list subTab.colums as po>
  151. <#if po.fieldName !='id' && po.fieldType =='date'>
  152. formData.${po.fieldName} = formData.${po.fieldName}?formData.${po.fieldName}.format():null;
  153. <#elseif po.fieldName !='id' && po.fieldType =='datetime'>
  154. formData.${po.fieldName} = formData.${po.fieldName}?formData.${po.fieldName}.format('YYYY-MM-DD HH:mm:ss'):null;
  155. </#if>
  156. </#list>
  157. httpAction(httpurl, formData, method).then((res) => {
  158. if (res.success) {
  159. that.$message.success(res.message);
  160. that.$emit('ok');
  161. } else {
  162. that.$message.warning(res.message);
  163. }
  164. }).finally(() => {
  165. that.confirmLoading = false;
  166. that.close();
  167. })
  168. }
  169. })
  170. },
  171. handleCancel() {
  172. this.close();
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped>
  178. </style>
  179. </#list>