wordList.vue
9.6 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<template>
<div class="container">
<headers></headers>
<right></right>
<scrollpage></scrollpage>
<div class="w box_sizing width_box my_wrap">
<div class="left_position">
<left></left>
</div>
<div class="question_list_wrap box_sizing">
<div class="flex_box flex_align_center listtitle">
<img src="../assets/images/words.png" alt="" />{{ title }}
</div>
<div class="flex_align_center flex_box flex_justify_between wordTip">
<div class="flex_align_center flex_box">
<input type="checkbox" @click="toall" />
<div>全选</div>
<div class="shengci" @click="toShuci(1)">全部标记生词</div>
<div class="shuci" @click="toShuci(2)">全部标记熟词</div>
<img src="../assets/images/del.png" alt="" />
</div>
<div class="flex_box flex_align_center">
<div>排序:</div>
<div class="flex_align_center flex_box all">
全部<img src="../assets/images/xiajiantou.png" alt="" />
</div>
<div class="flex_align_center flex_box all" @click="addTime(1)">
添加时间<img src="../assets/images/xiajiantou.png" alt="" />
</div>
<div class="flex_align_center flex_box all" @click="addTime(2)">
背诵次数<img src="../assets/images/xiajiantou.png" alt="" />
</div>
</div>
</div>
<div style="padding-top: 24px">
<div
class="flex_align_center flex_box flex_justify_between wordTip"
style="padding: 16px 0"
v-for="(item, index) in words"
:key="index"
>
<div class="flex_box flex_align_center">
<input
type="checkbox"
:checked="item.flag"
@click="tosigle(index)"
/>
<div
class="circle"
:style="item.status == 2 ? 'background:#67ddbf' : ''"
></div>
<!-- <div class="circle" v-if="item.status == 1"></div>
<div class="f_c" v-if="item.status == 2"></div> -->
<div>{{ item.word.word }}</div>
</div>
<div class="flex_align_center flex_box">
<div>背诵{{ item.num }}次</div>
<div
class="shengci"
@click="toShuci(1, $event)"
:data-id="item.word_id"
:data-word="item.word.word"
>
标记生词
</div>
<div
class="shuci"
@click="toShuci(2, $event)"
:data-id="item.word_id"
:data-word="item.word.word"
>
标记熟词
</div>
<img
src="../assets/images/del.png"
alt=""
@click="toShuci(3, $event)"
:data-id="item.word_id"
v-if="id == 0"
/>
</div>
</div>
</div>
<!-- 分页 -->
<div class="block">
<el-pagination
class="fenye"
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="prev, pager, next,total"
:total="total"
>
</el-pagination>
</div>
</div>
</div>
<footers></footers>
</div>
</template>
<script>
import headers from "@/components/headers";
import footers from "@/components/footders";
import left from "@/components/left";
import right from "@/components/right";
import scrollpage from "@/components/scrollpage";
var _this;
export default {
components: {
headers,
footers,
left,
right,
scrollpage,
},
data() {
return {
id: "", //单词本id
title: "",
words: [],
status: "", //状态0全部,1=生词,2=熟词
sort_field: "", //添加时间
sort: "", //1升序,2降序
page: 1,
total: 0, //总条数
word_id: "", //单词id
//
// orderList: [],
// 全选装填
selectAllStatus: false,
};
},
created() {
_this = this;
_this.getParams();
},
methods: {
// 获取传递过来的参数
getParams() {
_this.id = _this.$route.query.id;
_this.title = _this.$route.query.title;
_this.getList();
},
// 获取列表
getList() {
let params = {
word_book_id: _this.id,
status: _this.status,
sort_field: _this.sort_field,
sort: _this.sort,
page: _this.page,
per_page: 10,
},
url = "";
if (_this.id == 0) {
url = "word.user_word_book/lis";
} else {
url = "word.user_word_book/bookList";
// params.word_book_id = _this.id;
}
_this.$axios
.post(url, params)
.then((res) => {
console.log(res);
if (res.code == 1) {
let list = res.data.data;
list.forEach((el) => {
el.flag = false;
});
_this.words = list;
_this.total = res.data.total;
} else {
_this.$message.error(res.msg);
}
})
.catch((err) => {
console.log(err);
});
},
// 添加时间,背诵次数
addTime(e) {
_this.sort_field = e;
_this.getList();
},
// // 标记,删除
toShuci(num, e) {
console.log(num);
console.log(e.target.dataset.id);
console.log(e.target.dataset.word);
let type = num;
_this.word_id = e.target.dataset.id;
let url = "word.user_word_book/changeStatus";
let params = {
word_book_id: _this.id,
word_id: _this.word_id,
type: type,
};
console.log(params);
var list = _this.words;
_this.$axios
.post(url, params)
.then((res) => {
console.log(res);
if (res.code == 1) {
list.forEach((item) => {
if (item.word_id == _this.word_id) {
if (type == 1) {
item.status = 1;
item.num = item.num + 1;
} else if (type == 2) {
item.status = 2;
item.num = item.num + 1;
}
}
});
_this.words = list;
if (type == 1 || type == 2) {
_this.$message({
message: "标记成功",
type: "success",
});
} else if (type == 3) {
_this.$message({
message: "删除成功",
type: "success",
});
_this.page = 1;
_this.total = "";
_this.words = [];
_this.getList();
}
} else {
_this.$message.error(res.msg);
}
})
.catch((err) => {
console.log(err);
});
},
// 全选
toall(e) {
console.log(e);
var list = this.words;
var orderList = [];
//全选按钮---取反
this.selectAllStatus = !this.selectAllStatus;
list.forEach((item) => {
item.flag = this.selectAllStatus;
if (this.selectAllStatus) {
orderList.push(item.id);
} else {
orderList = [];
}
});
//更新data中的数据
this.words = list;
this.word_id = orderList.join(",");
},
// 单选
tosigle(e) {
console.log(e);
var list = this.words;
var flag = list[e].flag;
var orderList = [];
list[e].flag = !flag;
this.words = list;
console.log(orderList);
list.forEach((item) => {
console.log(item);
if (item.flag) {
orderList.push(item.word_id);
}
});
this.word_id = orderList.join(",");
},
handleSizeChange(val) {
console.log(`每页 ${val} 条`);
_this.page = val;
_this.getList();
},
handleCurrentChange(val) {
console.log(`当前页: ${val}`);
_this.page = val;
_this.getList();
},
},
};
</script>
<style>
.listtitle {
font-size: 16px;
font-weight: 600;
line-height: 44px;
color: #b90038;
}
.listtitle img {
width: 20px;
height: 20px;
margin-right: 10px;
}
.wordTip {
border-bottom: 1px solid #eeeeee;
}
.wordTip input {
width: 30px;
height: 30px;
transform: scale(0.6);
border: 1px solid black;
margin-right: 6px;
}
.wordTip img {
width: 20px;
height: 20px;
margin-left: 22px;
}
.wordTip .shengci {
width: 115px;
height: 24px;
background: linear-gradient(180deg, #f5a65c 0%, #fb9739 100%);
opacity: 1;
border-radius: 12px;
color: #ffffff;
text-align: center;
line-height: 24px;
margin: 0 16px 0 24px;
}
.wordTip .shuci {
width: 115px;
height: 24px;
background: linear-gradient(180deg, #67ddbf 0%, #31b99e 100%);
opacity: 1;
border-radius: 12px;
color: #ffffff;
text-align: center;
line-height: 24px;
}
.wordTip .all {
font-style: 16px;
color: #8c9198;
margin-left: 30px;
}
.all img {
width: 12px;
height: 12px;
margin-left: 6px;
}
.wordTip .circle {
width: 16px;
height: 16px;
background: linear-gradient(180deg, #f5a65c 0%, #fb9739 100%);
border-radius: 50%;
opacity: 1;
margin-right: 10px;
}
.f_c {
width: 16px;
height: 16px;
border-radius: 50%;
opacity: 1;
margin-right: 10px;
background: linear-gradient(180deg, #67ddbf, #31b99e);
}
.fenye {
margin-top: 20px;
width: 30%;
margin-left: auto;
}
input[type="checkbox"]:checked {
color: #31b99e;
background: #31b99e;
}
</style>