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
<template>
<div class="periods">
<div class="form-block">
<el-form label-width="90px" inline>
<el-form-item label="期数标题">
<el-input v-model="title" placeholder="请输入内容" clearable></el-input>
</el-form-item>
<el-form-item label="商品名称">
<el-select v-model="goodsId" placeholder="请选择" clearable>
<el-option
v-for="(data,index) in goodList"
:key="index"
:label="data | filterGoods"
:value="data.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="课程名称">
<el-select v-model="lessonId" placeholder="请选择" clearable>
<el-option
v-for="(data,index) in lessonList"
:key="index"
:label="data.title"
:value="data.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="onSearch" type="primary">查询</el-button>
</el-form-item>
<el-form-item style="float: right;" v-if="!$store.state.readonly">
<el-button @click="onAdd" type="primary">添加期数</el-button>
</el-form-item>
</el-form>
</div>
<el-table
:data="periodList"
style="width: 100%">
<el-table-column
prop="id"
label="期数ID">
</el-table-column>
<el-table-column
prop="title"
label="期数标题">
</el-table-column>
<el-table-column
prop="goods_name"
label="商品名称">
</el-table-column>
<el-table-column
label="商品价格">
<template slot-scope="scope">
{{scope.row.goods_price / 100 }}元
</template>
</el-table-column>
<el-table-column
prop="course_title"
label="课程名称">
</el-table-column>
<el-table-column
prop="start_name"
label="开始主题/歌">
</el-table-column>
<el-table-column
prop="current_category_name"
label="当前歌曲">
</el-table-column>
<el-table-column
label="看课情况"
min-width="150">
<template slot-scope="scope">
可看课包数: {{scope.row.watch_num}}<br> 已看课包数:{{scope.row.has_watch_num}} <br>
续看课包数: {{scope.row.duration_num}}<br> 已续看课包数:{{scope.row.has_duration_num}}
</template>
</el-table-column>
<el-table-column
label="周几不上课"
min-width="120">
<template slot-scope="scope">
{{scope.row.rest_week_day | dayFilter}}
</template>
</el-table-column>
<el-table-column
prop="start_at"
label="期数开始时间">
</el-table-column>
<el-table-column
label="操作"
width="148" v-if="!$store.state.readonly">
<template slot-scope="scope">
<el-button size="mini" plain type="primary" @click="onEdit(scope.row)">
编辑
</el-button>
<el-button size="mini" type="danger" plain @click="del(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<page :nowPage="nowPage" :total="total"/>
<new-dialog v-if="newDialog.show" :dialogObj="newDialog" @reflash="onSave"></new-dialog>
</div>
</template>
<script>
import goodDialog from './dialog'
import newDialog from './newDialog'
import page from '../framework/page'
import {getPeriodsApi,delPeriodApi,getGoodsListApi,getLessonApi} from "../../service/api";
import {WEEKDAY} from '../../util/wordbook';
export default {
name: "index",
data(){
return {
nowPage: 1,
total: 0,
title: '',
goodsId: null,
lessonId: null,
periodList: [],
newDialog: {
form: {
id: 0,
title: '',
start_num: 0,
start_at: '',
rest_week_day: [],
goods_id:''
},
show: false,
title: ''
},
goodList: [],
lessonList: []
}
},
filters: {
dayFilter: function (value) {
let list = value ? value.split(',') : [];
list = list.map((day) => {
return WEEKDAY[day];
})
return list.join(',')
},
filterGoods(val){
return val.name + '[' +val.current_price / 100 + '元]'
}
},
components:{
goodDialog,
newDialog,
page
},
methods: {
onSearch(){
let json={
}
if(this.title){
json.title = this.title;
}
if(this.goodsId){
json.goods_id = this.goodsId;
}
if(this.lessonId){
json.course_id = this.lessonId;
}
getPeriodsApi(json).then(res=>{
this.periodList = res.list;
this.total = res.total
});
},
onAdd(){
this.newDialog.form.id = '';
this.newDialog.start_num = '';
this.newDialog.form.goods_id = '';
this.newDialog.form.title = '';
this.newDialog.form.start_at = '';
this.newDialog.form.rest_week_day = [];
this.newDialog.form.teacher_ids = [];
this.newDialog.title = '添加期数';
this.newDialog.show = true;
},
onEdit(row){
this.newDialog.form.id = row.id;
this.newDialog.form.start_num = row.start_num;
this.newDialog.form.start_at = row.start_at;
this.newDialog.form.title = row.title;
this.newDialog.form.goods_id = row.goods_id;
console.log('row', row)
let weekList = [];
if(row.rest_week_day){
row.rest_week_day.split(',').forEach((val)=>{
weekList.push(parseInt(val));
})
}
this.newDialog.form.rest_week_day = weekList;
let teacherList = [];
if(row.teacher_ids){
row.teacher_ids.split(',').forEach((val)=>{
teacherList.push(parseInt(val));
})
}
this.newDialog.form.teacher_ids = teacherList;
this.newDialog.title = '编辑期数';
this.newDialog.show = true;
},
onSave(val){
this.newDialog.show = false;
this.onSearch();
},
del(row){
this.$confirm('此操作将删除该期数?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
delPeriodApi(row.id).then(res=>{
this.$message({
type: 'success',
message: '删除成功!'
});
this.onSearch()
});
});
},
getGoodsOption(){
let json = {
page: 1,
limit: 100
};
getGoodsListApi(json).then(res=>{
this.goodList = res.list;
})
},
getLessonOption(){
let json = {
page: 1,
limit: 100
};
getLessonApi(json).then(res=>{
this.lessonList = res.list;
})
}
},
mounted(){
this.onSearch();
this.getGoodsOption();
this.getLessonOption();
}
}
</script>
<style scoped>
.periods {
padding: 20px 0;
}
</style>