|
@@ -30,7 +30,7 @@
|
|
<div v-for="item in book_list" :key="item.id" class="book-list-item">
|
|
<div v-for="item in book_list" :key="item.id" class="book-list-item">
|
|
<div
|
|
<div
|
|
:class="['book-list-item-img', { selected: item.is_selected === 'true' }]"
|
|
:class="['book-list-item-img', { selected: item.is_selected === 'true' }]"
|
|
- @click="addOrRemoveBookToCourse($event, item.id)"
|
|
|
|
|
|
+ @click="addOrRemoveBookToCourse(item.id)"
|
|
>
|
|
>
|
|
<el-image fit="contain" :src="item.picture_url" />
|
|
<el-image fit="contain" :src="item.picture_url" />
|
|
</div>
|
|
</div>
|
|
@@ -105,23 +105,21 @@ export default {
|
|
this.cur_page = newPage;
|
|
this.cur_page = newPage;
|
|
this.queryBookList();
|
|
this.queryBookList();
|
|
},
|
|
},
|
|
- addOrRemoveBookToCourse(e, book_id) {
|
|
|
|
- const classList = e.target.parentElement.parentElement.classList;
|
|
|
|
-
|
|
|
|
|
|
+ addOrRemoveBookToCourse(book_id) {
|
|
const data = {
|
|
const data = {
|
|
course_id: this.id,
|
|
course_id: this.id,
|
|
book_id
|
|
book_id
|
|
};
|
|
};
|
|
-
|
|
|
|
- if (classList.contains('selected')) {
|
|
|
|
|
|
+ const bookIndex = this.book_list.findIndex(({ id }) => id === book_id);
|
|
|
|
+ if (this.book_list[bookIndex].is_selected === 'true') {
|
|
RemoveBookFromCourse(data).then(() => {
|
|
RemoveBookFromCourse(data).then(() => {
|
|
this.$message.success(this.$i18n.t('Key350'));
|
|
this.$message.success(this.$i18n.t('Key350'));
|
|
- classList.remove('selected');
|
|
|
|
|
|
+ this.book_list[bookIndex].is_selected = 'false';
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
AddBookToCourse(data).then(() => {
|
|
AddBookToCourse(data).then(() => {
|
|
this.$message.success(this.$i18n.t('Key351'));
|
|
this.$message.success(this.$i18n.t('Key351'));
|
|
- classList.add('selected');
|
|
|
|
|
|
+ this.book_list[bookIndex].is_selected = 'true';
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|