a516926fcc2ad226fa8219a237f8e828e2b98c28.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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-model ref="form" :model="model" :rules="validatorRules">
  13. <#list columns as po><#rt/>
  14. <#if po.fieldName !='id'><#rt/>
  15. <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="${po.fieldName}" label="${po.filedComment}">
  16. <#if po.fieldType =='date'>
  17. <a-date-picker v-model="model.${po.fieldName}"/>
  18. <#elseif po.fieldType =='datetime'>
  19. <a-date-picker showTime valueFormat='YYYY-MM-DD HH:mm:ss' v-model="model.${po.fieldName}" />
  20. <#elseif "int,decimal,double,"?contains(po.fieldType)>
  21. <a-input-number v-model="model.${po.fieldName}"/>
  22. <#else>
  23. <a-input placeholder="请输入${po.filedComment}" v-model="model.${po.fieldName}" />
  24. </#if>
  25. </a-form-model-item>
  26. </#if>
  27. </#list>
  28. </a-form-model>
  29. </a-spin>
  30. </j-modal>
  31. </template>
  32. <script>
  33. import { httpAction } from '@/api/manage'
  34. import moment from "moment"
  35. export default {
  36. name: "${entityName}Modal",
  37. data () {
  38. return {
  39. title:"操作",
  40. visible: false,
  41. model: {},
  42. labelCol: {
  43. xs: { span: 24 },
  44. sm: { span: 5 },
  45. },
  46. wrapperCol: {
  47. xs: { span: 24 },
  48. sm: { span: 16 },
  49. },
  50. confirmLoading: false,
  51. validatorRules:{
  52. <#list columns as po>
  53. <#if po.fieldName !='id'>
  54. <#if po.nullable =='N'>
  55. ${po.fieldName}:[{ required: true, message: '请输入${po.filedComment}!' }],
  56. </#if>
  57. </#if>
  58. </#list>
  59. },
  60. url: {
  61. add: "/${entityPackage}/${entityName?uncap_first}/add",
  62. edit: "/${entityPackage}/${entityName?uncap_first}/edit",
  63. },
  64. }
  65. },
  66. created () {
  67. },
  68. methods: {
  69. add () {
  70. //初始化默认值
  71. this.edit({});
  72. },
  73. edit (record) {
  74. this.model = Object.assign({}, record);
  75. this.visible = true;
  76. },
  77. close () {
  78. this.$emit('close');
  79. this.visible = false;
  80. this.$refs.form.clearValidate();
  81. },
  82. handleOk () {
  83. const that = this;
  84. // 触发表单验证
  85. this.$refs.form.validate(valid => {
  86. if (valid) {
  87. that.confirmLoading = true;
  88. let httpurl = '';
  89. let method = '';
  90. if(!this.model.id){
  91. httpurl+=this.url.add;
  92. method = 'post';
  93. }else{
  94. httpurl+=this.url.edit;
  95. method = 'post';
  96. }
  97. httpAction(httpurl,this.model,method).then((res)=>{
  98. if(res.success){
  99. that.$message.success(res.message);
  100. that.$emit('ok');
  101. }else{
  102. that.$message.warning(res.message);
  103. }
  104. }).finally(() => {
  105. that.confirmLoading = false;
  106. that.close();
  107. })
  108. }else{
  109. return false;
  110. }
  111. })
  112. },
  113. handleCancel () {
  114. this.close()
  115. },
  116. }
  117. }
  118. </script>
  119. <style lang="less" scoped>
  120. </style>