123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <el-dialog
- :title="!dataForm.id ? '新增' : '修改'"
- :close-on-click-modal="false"
- :visible.sync="visible">
- <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" 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="dataFormSubmit()">确定</el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- 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}) {
- this.$http({
- url: #[[this.$http.adornUrl]]#(`/${moduleName}/${pathName}/info/#[[$]]#{this.dataForm.${pk.attrname}}`),
- method: 'get',
- #[[params: this.$http.adornParams()]]#
- }).then(({data}) => {
- if (data && data.code === 0) {
- #foreach($column in $columns)
- #if($column.columnName != $pk.columnName)
- this.dataForm.${column.attrname} = data.${classname}.${column.attrname}
- #end
- #end
- }
- })
- }
- })
- },
- // 表单提交
- dataFormSubmit () {
- #[[this.$refs['dataForm'].validate((valid) => {]]#
- if (valid) {
- this.$http({
- url: #[[this.$http.adornUrl]]#(`/${moduleName}/${pathName}/${!this.dataForm.${pk.attrname} ? 'save' : 'update'}`),
- method: 'post',
- #[[data: this.$http.adornData({]]#
- #foreach($column in $columns)
- #if($column.columnName == $pk.columnName)
- '${column.attrname}': this.dataForm.${column.attrname} || undefined,
- #else
- '${column.attrname}': this.dataForm.${column.attrname}#if($velocityCount != $columns.size()),#end
- #end
- #end
- })
- }).then(({data}) => {
- if (data && data.code === 0) {
- #[[this.$message({]]#
- message: '操作成功',
- type: 'success',
- duration: 1500,
- onClose: () => {
- this.visible = false
- #[[this.$emit('refreshDataList')]]#
- }
- })
- } else {
- #[[this.$message.error(data.msg)]]#
- }
- })
- }
- })
- }
- }
- }
- </script>
|