add.vue
4.23 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
<el-dialog
:title='isEdit?"编辑":"新增"'
class="manage-dialog"
v-if="addDialogVisible"
:visible.sync="addDialogVisible"
:close-on-click-modal="false"
@close="addDialogClose()"
>
<el-form :model="addForm" status-icon :rules="rules" ref="addForm">
<el-form-item label="业态名称" prop="name">
<el-input v-model.trim="addForm.name"></el-input>
<i class="error-tip">*</i>
</el-form-item>
<el-form-item label="介绍" prop="intro">
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model.trim="addForm.intro"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="addDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
<el-button
type="primary"
@click="addSubmit('addForm')"
class="dialog-btn dialog-confirm-btn"
>{{$t('dialog.confirm')}}</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
addDialogVisible: false,
addForm: {
name: "",
pid: -1,
intro: "",
},
rules: {
name: [
{ required: true, message: "请输入业态名称", trigger: "blur" }
]
},
isEdit:'',
isChild:''
};
},
methods: {
dialogInit(type,parmas,child) {
this.isChild = child;
if(child){
// 新增子级
if(type=='add'){
this.addForm = {
name: "",
pid: parmas.id,
intro: "",
}
}else{
this.addForm = {
name: parmas.name,
intro: parmas.intro,
id:parmas.id,
pid:parmas.pid
}
}
}else{
if(parmas){
this.addForm = {
name: parmas.name,
intro: parmas.intro,
id:parmas.id
}
}else{
this.addForm = {
name: "",
pid: -1,
intro: "",
}
}
}
this.isEdit = type
this.addDialogVisible = true;
},
addSubmit(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
if(this.isEdit=='add'){
this.$api.management.addFormat(this.addForm)
.then(data => {
let result = data.data;
if (result.code == 200) {
this.$message({
showClose: true,
type: "success",
message: result.msg
});
this.addDialogVisible = false;
if(this.isChild){
let obj = {
id:this.addForm.pid
}
this.$parent.handleClick(obj)
}else{
this.$parent.getTableData()
}
} else {
this.$message({
showClose: true,
type: "error",
message: result.msg
});
}
})
}else{
this.$api.management.editFormat(this.addForm)
.then(data => {
let result = data.data;
if (result.code == 200) {
this.$message({
showClose: true,
type: "success",
message: result.msg
});
this.addDialogVisible = false;
if(this.isChild){
// 子级的table
this.$parent.getTableData(this.addForm.pid)
}else{
this.$parent.getTableData()
}
} else {
this.$message({
showClose: true,
type: "error",
message: result.msg
});
}
})
}
} else {
return false;
}
});
}
}
};
</script>
<style scoped>
.bdmap-btn {
margin-left: 17px;
width: 100%;
margin: 0;
padding: 0 8px;
height: 30px;
box-sizing: border-box;
border-radius: 2px;
font-size: 13px;
}
</style>