01aaba0006da5fbe67e8243803d319b34859dac4.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. switchFullscreen
  8. @ok="handleOk"
  9. @cancel="handleCancel"
  10. cancelText="关闭">
  11. <a-spin :spinning="confirmLoading">
  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 pick from 'lodash.pick'
  38. import moment from "moment"
  39. export default {
  40. name: "${entityName}Modal",
  41. data () {
  42. return {
  43. title:"操作",
  44. visible: false,
  45. model: {},
  46. labelCol: {
  47. xs: { span: 24 },
  48. sm: { span: 5 },
  49. },
  50. wrapperCol: {
  51. xs: { span: 24 },
  52. sm: { span: 16 },
  53. },
  54. confirmLoading: false,
  55. form: this.$form.createForm(this),
  56. validatorRules:{
  57. <#list columns as po>
  58. <#if po.fieldName !='id'>
  59. <#if po.nullable =='N'>
  60. ${po.fieldName}:{rules: [{ required: true, message: '请输入${po.filedComment}!' }]},
  61. </#if>
  62. </#if>
  63. </#list>
  64. },
  65. url: {
  66. add: "/${entityPackage}/${entityName?uncap_first}/add",
  67. edit: "/${entityPackage}/${entityName?uncap_first}/edit",
  68. },
  69. }
  70. },
  71. created () {
  72. },
  73. methods: {
  74. add () {
  75. this.edit({});
  76. },
  77. edit (record) {
  78. this.form.resetFields();
  79. this.model = Object.assign({}, record);
  80. this.visible = true;
  81. this.$nextTick(() => {
  82. this.form.setFieldsValue(pick(this.model<#list columns as po><#if po.fieldName !='id' && po.fieldType?index_of("date")==-1>,'${po.fieldName}'</#if></#list>))
  83. //时间格式化
  84. <#list columns as po>
  85. <#if po.fieldName !='id' && po.fieldType?index_of("date")!=-1>
  86. this.form.setFieldsValue({${po.fieldName}:this.model.${po.fieldName}?moment(this.model.${po.fieldName}):null})
  87. </#if>
  88. </#list>
  89. });
  90. },
  91. close () {
  92. this.$emit('close');
  93. this.visible = false;
  94. },
  95. handleOk () {
  96. const that = this;
  97. // 触发表单验证
  98. this.form.validateFields((err, values) => {
  99. if (!err) {
  100. that.confirmLoading = true;
  101. let httpurl = '';
  102. let method = '';
  103. if(!this.model.id){
  104. httpurl+=this.url.add;
  105. method = 'post';
  106. }else{
  107. httpurl+=this.url.edit;
  108. method = 'post';
  109. }
  110. let formData = Object.assign(this.model, values);
  111. //时间格式化
  112. <#list columns as po>
  113. <#if po.fieldName !='id' && po.fieldType =='date'>
  114. formData.${po.fieldName} = formData.${po.fieldName}?formData.${po.fieldName}.format():null;
  115. <#elseif po.fieldName !='id' && po.fieldType =='datetime'>
  116. formData.${po.fieldName} = formData.${po.fieldName}?formData.${po.fieldName}.format('YYYY-MM-DD HH:mm:ss'):null;
  117. </#if>
  118. </#list>
  119. console.log(formData)
  120. httpAction(httpurl,formData,method).then((res)=>{
  121. if(res.success){
  122. that.$message.success(res.message);
  123. that.$emit('ok');
  124. }else{
  125. that.$message.warning(res.message);
  126. }
  127. }).finally(() => {
  128. that.confirmLoading = false;
  129. that.close();
  130. })
  131. }
  132. })
  133. },
  134. handleCancel () {
  135. this.close()
  136. },
  137. }
  138. }
  139. </script>
  140. <style lang="less" scoped>
  141. </style>