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
<template>
<el-dialog
:title="dialogObj.title"
:visible.sync="dialogObj.show"
>
<el-form ref="form" :model="form" label-width="120px">
<el-form-item label="期数" v-if="this.dialogObj.type !==1">
<el-cascader
:options="goodsList"
:props="{value:'id',label:'name'}"
@active-item-change="handleItemChange"
@change="changePeriods"
>
</el-cascader>
</el-form-item>
<el-form-item label="老师">
<el-select v-model="form.teacher_id" placeholder="请选择">
<el-option
v-for="(data,index) in teacherList"
:key="index"
:label="data.name"
:value="data.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="最大学员">
<el-input-number v-model="form.max_join_num"></el-input-number>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogObj.show = false">取 消</el-button>
<el-button type="primary" @click="onSave">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import {getTeacherListApi,getClassDetailApi,editClassApi,addClassApi,getPeriodsApi,getGoodsListApi} from "../../service/api";
export default {
props:[
'dialogObj'
],
data(){
return{
form:{
teacher_id:'',
max_join_num:''
},
teacherList:[],
goodsList: [],
periods: {}
}
},
methods:{
initPage(){
getTeacherListApi().then(res=>{
this.teacherList = res.list
});
switch (this.dialogObj.type) {
case 0:
this.getPeriodList();
this.form = {
teacher_id:'',
max_join_num:''
};
break;
case 1:
getClassDetailApi(this.dialogObj.id).then(res=>{
this.form = {
teacher_id:res.teacher_id,
max_join_num:res.max_join_num
};
})
}
},
getPeriodList(){
getGoodsListApi().then(res=>{
res.list.forEach(i=>{
i.children = [];
});
this.goodsList = res.list;
if(!this.periods) {
getPeriodsApi({goods_id:this.goodsList[0].id}).then(res=>{
res.list.forEach(i=>{i.name = i.title});
this.goodsList[0].children = res.list;
this.periods = res.list[0]
})
}
});
},
onSave(){
switch (this.dialogObj.type) {
case 0:
addClassApi(this.periods.id,this.form).then(res=>{
this.$message({
type: 'success',
message: '添加成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
});
break;
case 1:
editClassApi(this.dialogObj.id,this.form).then(res=>{
this.$message({
type: 'success',
message: '修改成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
})
}
},
handleItemChange(val){
getPeriodsApi({goods_id:val[0]}).then(res=>{
res.list.forEach(i=>{i.name = i.title});
this.goodsList.find(i=>{return i.id === val[0]}).children = res.list
})
},
changePeriods(data){
if(data.length>1){
let nowGoods = this.goodsList.find(i=>{return i.id === data[0]});
this.periods = nowGoods.children.find(i=>{return i.id === data[1]});
this.getTeacher()
}
}
},
watch:{
'dialogObj'(value){
this.initPage()
}
}
}
</script>
<style scoped>
</style>