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
<template>
<div>
<el-card v-for="data in list" :key="data.id" class="box-card">
<div class="id">
<img :src="data.cover">
</div>
<div class="btn">
<el-button
type=""
icon="el-icon-view"
circle size="mini"
@click="showQr(data)"
v-if="!$store.state.readonly">
</el-button>
<el-button
type=""
icon="el-icon-edit"
circle size="mini"
@click="onEdit(data)"
v-if="!$store.state.readonly">
</el-button>
<el-button
type=""
icon="el-icon-delete"
circle size="mini"
@click="delLseeon(data)"
v-if="$store.state.deletePermission && !$store.state.readonly">
</el-button>
</div>
<div class="name">
{{data.title}}
<el-tag size="mini">{{data.min_age}}-{{data.max_age}}岁</el-tag>
</div>
</el-card>
<div class="add-block" v-if="id">
<el-button round type="success" @click="onAdd" v-if="!$store.state.readonly">+新增课时</el-button>
</div>
<editor-dialog :editorObj="editorObj" @reflash="getList"/>
<el-dialog
title="微信扫码预览"
:center="true"
:visible.sync="qrShow"
width="300px">
<div id="qrcode"></div>
</el-dialog>
</div>
</template>
<script>
import {getCateListApi,delElementApi} from "../../service/api";
import QRCode from 'qrcodejs2'
import EditorDialog from './editorDialog'
export default {
name: "list",
components:{
EditorDialog
},
props:[
'id'
],
data(){
return {
list:[],
qrShow:false,
qr:false,
editorObj:{
show:false,// 显示开关
category_id:0,// 分类id
type:0,//0 新增 1 修改
title:'',// 标题
id:''// 课程id
}
}
},
created(){
if(this.id !== '' && this.id !== null)this.getList()
},
methods:{
qrcode(data){
if(this.qr){
this.qr.makeCode(data)
}else{
this.qr = new QRCode('qrcode', {
width: 250,
height: 250, // 高度
text: data, // 二维码内容
image: ''
});
}
},
showQr(data){
this.qrShow = true;
this.$nextTick(()=>{
this.qrcode(window.location.href.split('#')[0] + '#/preview/'+data.id);
})
},
getList(){
getCateListApi({category_id:this.id}).then(res=>{
this.list = res.list
})
},
delLseeon(data){
this.$confirm('此操作将删除该课包?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
delElementApi(data.id).then(res=>{
this.$message({
type: 'success',
message: '删除成功!'
});
});
this.getList();
});
},
onUp(){},
onAdd(){
this.editorObj = {
show:true,
category_id:this.id,
type:0,
title:'新增课包'
}
},
onEdit(data){
this.editorObj = {
show:true,
category_id:this.id,
id:data.id,
type:1,
title:'编辑课包'
}
}
},
watch:{
id(value){
if(value !== '' && value !== null)this.getList()
}
}
}
</script>
<style scoped lang="less">
@import "../../util/public";
.box-card{
margin: 10px 0;
cursor: pointer;
padding: 0;
&:hover{
background: #3a8ee6;
color: white;
}
.id{
margin-right: 20px;
width: 4em;
text-align: center;
float: left;
img{
width: 100%;
}
}
.btn{
float: right;
}
.name{
span{
display: inline-block;
text-align: center;
}
}
}
.add-block{
.clear-both;
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
}
</style>