trfficcodes.vue
7.72 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<template>
<div class="contentBox">
<div class="content">
<div>
<span class="selectBox">
<el-select
v-model="curCateUnid"
placeholder="请选择"
@change="cateChange"
:popper-append-to-body="false"
>
<el-option
v-for="(item, index) in catesData"
:key="index"
:value="item.cate_unid"
:label="item.name"
></el-option>
</el-select>
</span>
<span class="addbox">
<el-button type="primary" @click="addcode">添加code</el-button>
</span>
</div>
<div class="mt10">
<el-table
height="574"
:data="tableData"
stripe
border
style="width: 100%"
>
<el-table-column
type="index"
align="center"
label="#"
width="40"
></el-table-column>
<el-table-column align="center" prop="code_unid" label="code_unid">
</el-table-column>
<el-table-column prop="code" align="center" label="code">
</el-table-column>
<el-table-column align="center" prop="name" label="名称">
</el-table-column>
<el-table-column align="center" prop="note" label="备用名称">
</el-table-column>
<el-table-column
align="center"
prop="active"
label="状态"
:formatter="activeFormatter"
>
</el-table-column>
<el-table-column align="center" prop="operation" label="操作">
<template slot-scope="scope">
<el-tooltip
content="编辑"
placement="bottom"
effect="light"
:visible-arrow="false"
>
<span
class="icon-fanxing-xiugai editIcon"
@click="editCode(scope.$index, scope.row)"
></span>
</el-tooltip>
<el-tooltip
content="删除"
placement="bottom"
effect="light"
:visible-arrow="false"
>
<span
class="el-icon-delete delIcon del-btn"
@click="deleteCode(scope.$index, scope.row)"
></span>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<div style="margin-top: 28px;">
<el-pagination
style="float: right;"
background
prev-text="上一页"
next-text="下一页"
:page-sizes="[20, 30, 50, 100, 200]"
layout="prev, pager, next,sizes"
:current-page="page"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:total="total"
>
</el-pagination>
<div style="clear: both;"></div>
</div>
</div>
</div>
<el-dialog title="设置CODE" :visible.sync="detailVisible" width="400px">
<el-form
ref="trfficform"
:model="codeData"
label-position="left"
label-width="80px"
>
<el-form-item
label="类型"
prop="catename"
:rules="[
{ required: true, message: '类型不能为空!', trigger: 'blur' }
]"
>
<el-input v-model="codeData.catename" disabled></el-input>
</el-form-item>
<el-form-item
label="CODE"
prop="code"
:rules="[
{ required: true, message: 'code不能为空!', trigger: 'blur' }
]"
>
<el-input v-model="codeData.code" :disabled="editdis"></el-input>
</el-form-item>
<el-form-item
label="名称"
prop="name"
:rules="[
{ required: true, message: '名称不能为空!', trigger: 'blur' }
]"
>
<el-input v-model="codeData.name"></el-input>
</el-form-item>
<el-form-item label="备注" prop="note">
<el-input v-model="codeData.note"></el-input>
</el-form-item>
<el-form-item
label="启用"
prop="active"
:rules="[
{ required: true, message: '名称不能为空!', trigger: 'blur' }
]"
>
<el-select v-model="codeData.active" placeholder="请选择">
<el-option label="开启" :value="true"></el-option>
<el-option label="关闭" :value="false"></el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="detailVisible = false">取 消</el-button>
<el-button size="small" type="primary" @click="saveCode"
>确 定</el-button
>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
detailData: [],
total: 0,
page: 1,
curCateUnid: "",
pageSize: 20,
tableData: [],
catesData: [],
selectDevs: "",
detailVisible: false,
codeStatus: 0,
codeData: {},
editdis: false
};
},
components: {},
created() {
this.getCates();
},
methods: {
cateChange(cateunid) {
let offset = (this.page - 1) * this.pageSize;
let obj = {
limit: this.pageSize,
offset: offset
};
this.$api.codes
.codes(obj, cateunid)
.then(res => {
this.tableData = res.list_data;
})
.catch(err => {});
},
addcode() {
this.codeStatus = 0;
this.detailVisible = true;
this.codeData.catename = this.getCateName(this.curCateUnid);
this.editdis = false;
},
editCode(index, row) {
this.codeStatus = 1;
this.detailVisible = true;
this.codeData = row;
this.editdis = true;
this.codeData.catename = this.getCateName(this.curCateUnid);
},
getCateName(cateunid) {
let name = "";
this.catesData.forEach(ele => {
if (ele.cate_unid === cateunid) {
name = ele.name;
}
});
return name;
},
getCates() {
this.$api.codes.cates().then(res => {
this.catesData = res.list_data;
});
},
activeFormatter(row) {
let text = "开启";
if (row.active) {
text = "开启";
} else {
text = "关闭";
}
return text;
},
saveCode() {
this.$refs["trfficform"].validate(valid => {
if (valid) {
if (this.codeStatus === 0) {
this.saveAddCode();
}
if (this.codeStatus === 1) {
this.saveEditCode();
}
} else {
console.log("error submit!!");
return false;
}
});
},
saveAddCode() {
this.$api.codes
.addTrafficCode(this.codeData, this.curCateUnid)
.then(res => {
console.log(res);
});
},
saveEditCode() {
this.$api.codes
.editTrafficCode(
this.codeData,
this.curCateUnid,
this.codeData.code_unid
)
.then(res => {
console.log(res);
});
},
deleteCode(index, row) {
this.$api.codes
.editTrafficCode(row, this.curCateUnid, row.code_unid)
.then(res => {
console.log(res);
});
},
handleSizeChange(val) {
this.pageSize = val;
},
handleCurrentChange(val) {
this.page = val;
}
}
};
</script>
<style lang="scss" scoped>
.addbox {
float: right;
margin-right: 10px;
}
.code-btn {
margin-bottom: 10px;
float: right;
margin-right: 10px;
}
.del-btn {
padding-left: 20px;
}
</style>