提交 | 用户 | age
|
20ba22
|
1 |
<template> |
L |
2 |
<el-dialog v-el-drag-dialog :title="'('+name+')'+objectName+'列表'" width="60%" :visible.sync="isShow" :before-close="closeHandle" :close-on-click-modal="false"> |
|
3 |
<!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ --> |
|
4 |
<el-form v-show="showSearch" ref="searchForm" :inline="true"> |
|
5 |
<el-form-item label="老师名称"> |
|
6 |
<el-input |
|
7 |
v-model="keyWord" |
|
8 |
placeholder="请输入老师名称" |
|
9 |
clearable |
|
10 |
size="small" |
|
11 |
style="width: 240px" |
|
12 |
maxlength="50" |
|
13 |
@keyup.enter.native="reGetList" |
|
14 |
/> |
|
15 |
</el-form-item> |
|
16 |
<el-form-item> |
|
17 |
<el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button> |
|
18 |
<el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button> |
|
19 |
</el-form-item> |
|
20 |
</el-form> |
|
21 |
<!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
22 |
|
|
23 |
<!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ --> |
|
24 |
<el-row :gutter="10" class="mb8"> |
|
25 |
<el-col :span="1.5"> |
|
26 |
<el-button |
|
27 |
type="primary" |
|
28 |
icon="el-icon-plus" |
|
29 |
size="mini" |
|
30 |
@click="showAddDialog" |
|
31 |
>新增</el-button> |
|
32 |
</el-col> |
|
33 |
<right-toolbar :show-search.sync="showSearch" @queryTable="getList" /> |
|
34 |
</el-row> |
|
35 |
<!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
36 |
|
|
37 |
<el-table :data="list" max-height="420px"> |
|
38 |
<el-table-column type="index" label="序号" align="center" width="60" /> |
|
39 |
<el-table-column label="老师名称" prop="teacherName" align="center" min-width="120" /> |
|
40 |
<el-table-column label="班级名称" prop="className" align="center" min-width="120" /> |
|
41 |
<el-table-column label="创建时间" prop="createTime" align="center" width="160" /> |
|
42 |
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120"> |
|
43 |
<template slot-scope="scope"> |
|
44 |
<!-- <el-button |
|
45 |
size="mini" |
|
46 |
type="text" |
|
47 |
icon="el-icon-edit" |
|
48 |
@click="showEditDialog(scope.row)" |
|
49 |
>编辑</el-button> --> |
|
50 |
<el-button |
|
51 |
size="mini" |
|
52 |
type="text warn" |
|
53 |
icon="el-icon-delete" |
|
54 |
@click="handleDelete(scope.row)" |
|
55 |
>删除</el-button> |
|
56 |
</template> |
|
57 |
</el-table-column> |
|
58 |
</el-table> |
|
59 |
|
|
60 |
<!-- 新增&编辑 --> |
|
61 |
<el-dialog v-el-drag-dialog :title="(dialogData.type=='add'?'新增':'编辑') + objectName" width="500px" :visible.sync="dialogVisible" append-to-body :before-close="hideDialog" :close-on-click-modal="false"> |
|
62 |
<el-form ref="refDialog" :model="dialogData" label-width="110px" :rules="rules" size="small"> |
|
63 |
<el-form-item label="绑定老师" prop="teacherIds"> |
|
64 |
<el-select v-model="dialogData.teacherIds" clearable multiple placeholder="选择老师" style="width: 100%"> |
|
65 |
<el-option |
|
66 |
v-for="item in teacherOptions" |
|
67 |
:key="item.id" |
|
68 |
:label="item.name" |
|
69 |
:value="item.id" |
|
70 |
/> |
|
71 |
</el-select> |
|
72 |
</el-form-item> |
|
73 |
</el-form> |
|
74 |
<div slot="footer" class="dialog-footer"> |
|
75 |
<el-button @click="hideDialog">取消</el-button> |
|
76 |
<el-button type="primary" @click="submitHandle">确定</el-button> |
|
77 |
</div> |
|
78 |
</el-dialog> |
|
79 |
|
|
80 |
<pagination |
|
81 |
v-show="total>0" |
|
82 |
:total="total" |
|
83 |
:page.sync="pageNum" |
|
84 |
:limit.sync="pageSize" |
|
85 |
@pagination="getList" |
|
86 |
/> |
|
87 |
</el-dialog> |
|
88 |
</template> |
|
89 |
|
|
90 |
<script> |
|
91 |
|
|
92 |
export default { |
|
93 |
data() { |
|
94 |
return { |
|
95 |
isShow: false, |
|
96 |
showSearch: true, // 是否显示搜索区 |
|
97 |
keyWord: '', |
|
98 |
|
|
99 |
name: '', |
|
100 |
id: '', |
|
101 |
list: [], |
|
102 |
|
|
103 |
objectName: '绑定老师', // 对象名称,用于删除提示、启用提示、弹窗标题等 |
|
104 |
|
|
105 |
// 老师配置下拉 |
|
106 |
teacherOptions: [], |
|
107 |
|
|
108 |
// 弹窗数据 |
|
109 |
dialogVisible: false, |
|
110 |
dialogData: {}, |
|
111 |
|
|
112 |
// 分页 ↓↓↓↓↓↓↓↓↓↓ |
|
113 |
total: 0, |
|
114 |
pageNum: 1, |
|
115 |
pageSize: 20, |
|
116 |
// 分页 ↑↑↑↑↑↑↑↑↑↑ |
|
117 |
|
|
118 |
// 表单校验 |
|
119 |
rules: { |
|
120 |
teacherIds: [ |
|
121 |
{ required: true, message: '绑定老师不能为空', trigger: 'change' } |
|
122 |
] |
|
123 |
} |
|
124 |
|
|
125 |
} |
|
126 |
}, |
|
127 |
methods: { |
|
128 |
// 初始化 this.$refs.xxx.openHandle(id) |
|
129 |
openHandle(item) { |
|
130 |
this.id = item.id |
|
131 |
this.name = item.name |
|
132 |
this.getList() |
|
133 |
this.isShow = true |
|
134 |
}, |
|
135 |
|
|
136 |
// 关闭列表 |
|
137 |
closeHandle() { |
|
138 |
this.id = '' |
|
139 |
this.list = [] |
|
140 |
this.isShow = false |
|
141 |
}, |
|
142 |
|
|
143 |
// 获取列表 |
|
144 |
getList() { |
|
145 |
var { pageNum, pageSize, keyWord } = this |
|
146 |
this.postFN({ |
|
147 |
url: 'admin/schoolClassTeacher/list', |
|
148 |
params: { |
|
149 |
pageNum: pageNum, |
|
150 |
pageSize: pageSize, |
|
151 |
schoolClassId: this.id, |
|
152 |
name: keyWord |
|
153 |
}, |
|
154 |
mockData: { |
|
155 |
code: 100, |
|
156 |
msg: '', |
|
157 |
data: { |
|
158 |
list: [{ |
|
159 |
createTime: '2021-04-02 10:21:52', |
|
160 |
teacherName: '崔某', |
|
161 |
className: '五年一班', |
|
162 |
id: '1' |
|
163 |
}], |
|
164 |
total: 100 |
|
165 |
} |
|
166 |
} |
|
167 |
}, (inf) => { |
|
168 |
this.list = inf.list || [] |
|
169 |
this.total = inf.total |
|
170 |
}) |
|
171 |
}, |
|
172 |
// 重新获取列表 |
|
173 |
reGetList() { |
|
174 |
this.pageNum = 1 |
|
175 |
this.getList() |
|
176 |
}, |
|
177 |
// 重置 |
|
178 |
resetHandle() { |
|
179 |
this.keyWord = '' |
|
180 |
this.reGetList() |
|
181 |
}, |
|
182 |
// 删除 |
|
183 |
handleDelete(item) { |
|
184 |
// 打开二次确认弹窗 |
|
185 |
this.$confirm('是否确认删除该' + this.objectName + '?', '提示', { |
|
186 |
confirmButtonText: '确定', |
|
187 |
cancelButtonText: '取消', |
|
188 |
type: 'warning' |
|
189 |
}).then(() => { |
|
190 |
// 确定回调 |
|
191 |
// TODO url |
|
192 |
this.postFN({ |
|
193 |
url: 'admin/schoolClassTeacher/delete/one', |
|
194 |
params: { |
|
195 |
id: item.id |
|
196 |
}, |
|
197 |
mockData: { |
|
198 |
code: 100, |
|
199 |
msg: '', |
|
200 |
data: {} |
|
201 |
} |
|
202 |
}, () => { |
|
203 |
this.getList() |
|
204 |
this.$messageSuc('删除成功') |
|
205 |
}) |
|
206 |
}).catch(() => {}) |
|
207 |
}, |
|
208 |
// 修改是否上架 |
|
209 |
handleUpChange(item) { |
|
210 |
const text = item.isUp === 1 ? '上架' : '下架' |
|
211 |
this.$confirm('确认要' + text + '该' + this.objectName + '吗?', '提示', { |
|
212 |
confirmButtonText: '确定', |
|
213 |
cancelButtonText: '取消', |
|
214 |
type: 'warning' |
|
215 |
}).then(() => { |
|
216 |
// TODO url |
|
217 |
this.postFN({ |
|
218 |
url: 'xxx', |
|
219 |
params: { |
|
220 |
id: item.id, |
|
221 |
isUp: item.isUp |
|
222 |
}, |
|
223 |
mockData: { |
|
224 |
code: 100, |
|
225 |
msg: '', |
|
226 |
data: {} |
|
227 |
} |
|
228 |
}, () => { |
|
229 |
this.$messageSuc(text + '成功') |
|
230 |
}, (res) => { |
|
231 |
item.isUp = item.isUp === 1 ? 0 : 1 |
|
232 |
this.$messageError(res.msg) |
|
233 |
}) |
|
234 |
}).catch(() => { |
|
235 |
item.isUp = item.isUp === 1 ? 0 : 1 |
|
236 |
}) |
|
237 |
}, |
|
238 |
|
|
239 |
// 获取老师列表 |
|
240 |
getTeacherOptions(callback) { |
|
241 |
this.postFN({ |
|
242 |
url: 'admin/common/select/teacher/list', |
|
243 |
params: {}, |
|
244 |
mockData: { |
|
245 |
code: 100, |
|
246 |
msg: '', |
|
247 |
data: { |
|
248 |
list: [{ |
|
249 |
name: '黄冈', |
|
250 |
id: 1 |
|
251 |
}, { |
|
252 |
name: '表莲华', |
|
253 |
id: 2 |
|
254 |
}, { |
|
255 |
name: '吴起是', |
|
256 |
id: 3 |
|
257 |
}] |
|
258 |
} |
|
259 |
} |
|
260 |
}, (inf) => { |
|
261 |
this.teacherOptions = inf.list || [] |
|
262 |
callback && callback() |
|
263 |
}) |
|
264 |
}, |
|
265 |
// 打开新增弹窗 |
|
266 |
showAddDialog() { |
|
267 |
this.getTeacherOptions() |
|
268 |
var dialogData = { |
|
269 |
type: 'add', |
|
270 |
teacherIds: '' |
|
271 |
} |
|
272 |
this.dialogVisible = true |
|
273 |
this.$nextTick(() => { |
|
274 |
this.dialogData = dialogData |
|
275 |
this.$refs['refDialog'].resetFields() |
|
276 |
}) |
|
277 |
}, |
|
278 |
// 打开编辑弹框 |
|
279 |
showEditDialog(item) { |
|
280 |
var dialogData = { |
|
281 |
...item, |
|
282 |
type: 'edit' |
|
283 |
} |
|
284 |
console.log('dialogData', dialogData) |
|
285 |
this.dialogVisible = true |
|
286 |
this.$nextTick(() => { |
|
287 |
this.dialogData = dialogData |
|
288 |
this.$refs['refDialog'].resetFields() |
|
289 |
}) |
|
290 |
}, |
|
291 |
// 关闭编辑弹窗 |
|
292 |
hideDialog() { |
|
293 |
this.dialogData = {} |
|
294 |
this.dialogVisible = false |
|
295 |
}, |
|
296 |
// 提交新增&编辑 |
|
297 |
submitHandle() { |
|
298 |
this.$refs['refDialog'].validate(valid => { |
|
299 |
if (valid) { |
|
300 |
this.submitReq() |
|
301 |
} |
|
302 |
}) |
|
303 |
}, |
|
304 |
// 提交接口 |
|
305 |
submitReq() { |
|
306 |
var { dialogData } = this |
|
307 |
var params = { |
|
308 |
teacherIds: dialogData.teacherIds.join(','), |
|
309 |
schoolClassId: this.id |
|
310 |
} |
|
311 |
|
|
312 |
var isAdd = dialogData.type === 'add' |
|
313 |
var url = isAdd ? 'admin/schoolClassTeacher/add' : 'xxx' |
|
314 |
|
|
315 |
!isAdd && (params.id = dialogData.id) |
|
316 |
|
|
317 |
this.postFN({ |
|
318 |
url: url, |
|
319 |
params: params, |
|
320 |
mockData: { |
|
321 |
code: 100, |
|
322 |
msg: '', |
|
323 |
data: {} |
|
324 |
} |
|
325 |
}, () => { |
|
326 |
this.$messageSuc('保存成功') |
|
327 |
this.hideDialog() |
|
328 |
isAdd ? this.reGetList() : this.getList() |
|
329 |
}) |
|
330 |
} |
|
331 |
|
|
332 |
} |
|
333 |
} |
|
334 |
</script> |
|
335 |
|
|
336 |
<style lang="scss" scoped> |
|
337 |
|
|
338 |
</style> |