a24b291201ddbcbee8dcaafc2d9ff8fea3a1d102.svn-base 5.0 KB

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