3 天以前 de1bcb5dc30787d33fedb4479e8ece45809ced1b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
  <!-- 基于 Element UI 新增和修改弹窗 -->
  <el-dialog
    :title="!dataForm.${pk.attrname} ? '添加-ADD' : '修改-EDITE'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <!-- 新增和创建表单表单 -->
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataSubmit()" label-width="80px">
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
    <el-form-item label="${column.comments}" prop="${column.attrname}">
      <el-input v-model="dataForm.${column.attrname}" placeholder="${column.comments}"></el-input>
    </el-form-item>
#end
#end
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
  import * as api from './.${pathName}api.js'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
#foreach($column in $columns)
#if($column.columnName == $pk.columnName)
          ${column.attrname}: 0,
#else
          ${column.attrname}: '' #if($velocityCount != $columns.size()), #end
 
#end
#end
        },
        dataRule: {
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
          ${column.attrname}: [
            { required: true, message: '${column.comments}  为必填项', trigger: 'blur' }
          ]#if($velocityCount != $columns.size()),#end
 
#end
#end
        }
      }
    },
    methods: {
      init (id) { // 初始化表单验证规则
        this.dataForm.${pk.attrname} = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.${pk.attrname}) {
            api.${pathName}DetailApi(${pk.attrname}).then(res => {
                this.dataForm = res;
            })
          }
        })
      },
      // 表单数据提交
      dataSubmit () {
        #[[this.$refs['dataForm'].validate((valid) => {]]#
          if (valid) {
                  api.${className}CreateApi().then(res =>{
                      // TODO 保存数据
                  });
          }
        })
      }
    }
  }
</script>