form.vue.stub 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
  7. #foreach($column in $columns)
  8. #if($column.columnName != $pk.columnName)
  9. <el-form-item label="${column.comments}" prop="${column.attrname}">
  10. <el-input v-model="dataForm.${column.attrname}" placeholder="${column.comments}"></el-input>
  11. </el-form-item>
  12. #end
  13. #end
  14. </el-form>
  15. <span slot="footer" class="dialog-footer">
  16. <el-button @click="visible = false">取消</el-button>
  17. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  18. </span>
  19. </el-dialog>
  20. </template>
  21. <script>
  22. export default {
  23. data () {
  24. return {
  25. visible: false,
  26. dataForm: {
  27. #foreach($column in $columns)
  28. #if($column.columnName == $pk.columnName)
  29. ${column.attrname}: 0,
  30. #else
  31. ${column.attrname}: ''#if($velocityCount != $columns.size()),#end
  32. #end
  33. #end
  34. },
  35. dataRule: {
  36. #foreach($column in $columns)
  37. #if($column.columnName != $pk.columnName)
  38. ${column.attrname}: [
  39. { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
  40. ]#if($velocityCount != $columns.size()),#end
  41. #end
  42. #end
  43. }
  44. }
  45. },
  46. methods: {
  47. init (id) {
  48. this.dataForm.${pk.attrname} = id || 0
  49. this.visible = true
  50. this.$nextTick(() => {
  51. this.$refs['dataForm'].resetFields()
  52. if (this.dataForm.${pk.attrname}) {
  53. this.$http({
  54. url: #[[this.$http.adornUrl]]#(`/${moduleName}/${pathName}/info/#[[$]]#{this.dataForm.${pk.attrname}}`),
  55. method: 'get',
  56. #[[params: this.$http.adornParams()]]#
  57. }).then(({data}) => {
  58. if (data && data.code === 0) {
  59. #foreach($column in $columns)
  60. #if($column.columnName != $pk.columnName)
  61. this.dataForm.${column.attrname} = data.${classname}.${column.attrname}
  62. #end
  63. #end
  64. }
  65. })
  66. }
  67. })
  68. },
  69. // 表单提交
  70. dataFormSubmit () {
  71. #[[this.$refs['dataForm'].validate((valid) => {]]#
  72. if (valid) {
  73. this.$http({
  74. url: #[[this.$http.adornUrl]]#(`/${moduleName}/${pathName}/${!this.dataForm.${pk.attrname} ? 'save' : 'update'}`),
  75. method: 'post',
  76. #[[data: this.$http.adornData({]]#
  77. #foreach($column in $columns)
  78. #if($column.columnName == $pk.columnName)
  79. '${column.attrname}': this.dataForm.${column.attrname} || undefined,
  80. #else
  81. '${column.attrname}': this.dataForm.${column.attrname}#if($velocityCount != $columns.size()),#end
  82. #end
  83. #end
  84. })
  85. }).then(({data}) => {
  86. if (data && data.code === 0) {
  87. #[[this.$message({]]#
  88. message: '操作成功',
  89. type: 'success',
  90. duration: 1500,
  91. onClose: () => {
  92. this.visible = false
  93. #[[this.$emit('refreshDataList')]]#
  94. }
  95. })
  96. } else {
  97. #[[this.$message.error(data.msg)]]#
  98. }
  99. })
  100. }
  101. })
  102. }
  103. }
  104. }
  105. </script>