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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#set($excludeColumns = ["create_time","update_time","create_by","update_by"])
<template>
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false"
@close="closeDialog()"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
#foreach($column in $columns)
## 当列是主键 新增不显示,编辑(dataForm.id 有值)的时候显示单不能编辑
#if($column.columnName == $pk.columnName || $excludeColumns.contains($column.columnName))
<el-form-item label="${column.comments}" prop="${column.lowerAttrName}" v-if="dataForm.id">
<el-input v-model="dataForm.${column.lowerAttrName}" placeholder="${column.comments}" disabled></el-input>
</el-form-item>
#else
<el-form-item label="${column.comments}" prop="${column.lowerAttrName}">
<el-input v-model="dataForm.${column.lowerAttrName}" 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="dataFormSubmit()" v-if="canSubmit">确定</el-button>
</span>
</el-dialog>
</template>
<script>
import {getObj, addObj, putObj} from '@/api/${pathName}'
export default {
data () {
return {
visible: false,
canSubmit: false,
dataForm: {
#foreach($column in $columns)
${column.lowerAttrName}: ''#if($velocityCount != $columns.size()),#end
#end
},
dataRule: {
#foreach($column in $columns)
#if($column.columnName != $pk.columnName && !$excludeColumns.contains($column.columnName))
${column.lowerAttrName}: [
{ required: true, message: '${column.comments}不能为空', trigger: 'blur' }
]#if($velocityCount != $columns.size()),#end
#end
#end
}
}
},
methods: {
init (id) {
this.visible = true;
this.canSubmit = true;
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (id) {
getObj(id).then(response => {
this.dataForm = response.data.data
})
}
})
},
// 表单提交
dataFormSubmit () {
#[[this.$refs['dataForm'].validate((valid) => {]]#
if (valid) {
this.canSubmit = false;
if (this.dataForm.${pk.lowerAttrName}) {
putObj(this.dataForm).then(data => {
this.$notify.success('修改成功')
this.visible = false
this.$emit('refreshDataList')
}).catch(() => {
this.canSubmit = true;
});
} else {
addObj(this.dataForm).then(data => {
this.$notify.success('添加成功')
this.visible = false
this.$emit('refreshDataList')
}).catch(() => {
this.canSubmit = true;
});
}
}
})
},
//重置表单
closeDialog() {
this.$refs["dataForm"].resetFields()
}
}
}
</script>