SelectBook.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="select-book">
  3. <step-bar :step-number="1" />
  4. <div class="select-book-container">
  5. <div class="select-book-container-title">
  6. {{ $t('Key49') }}
  7. </div>
  8. <div class="select-book-container-table">
  9. <div class="search">
  10. <div>
  11. <el-input
  12. v-model="search"
  13. prefix-icon="el-icon-search"
  14. :placeholder="$t('Key267')"
  15. class="keyword"
  16. @keyup.enter.native="queryBookList"
  17. >
  18. <el-button slot="append" @click="queryBookList">
  19. {{ $t('Key131') }}
  20. </el-button>
  21. </el-input>
  22. <!-- <el-button class="buy">去购买</el-button><span class="tip">只能添加已购买的资源</span> -->
  23. </div>
  24. <div>
  25. <!-- <el-button type="info">最新</el-button> -->
  26. </div>
  27. </div>
  28. <div class="book">
  29. <div class="book-list">
  30. <div v-for="item in book_list" :key="item.id" class="book-list-item">
  31. <div
  32. :class="['book-list-item-img', { selected: item.is_selected === 'true' }]"
  33. @click="addOrRemoveBookToCourse(item.id)"
  34. >
  35. <el-image fit="contain" :src="item.picture_url" />
  36. </div>
  37. <div class="book-list-item-name">
  38. {{ item.name }}
  39. </div>
  40. </div>
  41. </div>
  42. <div class="book-bottom">
  43. <el-pagination
  44. layout="prev, pager, next"
  45. :total="total_count"
  46. :current-page="cur_page"
  47. :page-size="page_capacity"
  48. @prev-click="changePage"
  49. @next-click="changePage"
  50. @current-change="changePage"
  51. />
  52. <div>
  53. <el-button class="prev-step" @click="prevCourseInfo">
  54. <i class="el-icon-back" />{{ $t('Key264') }}
  55. </el-button>
  56. <el-button type="primary" class="next-step" @click="nextStep">
  57. {{ $t('Key262') }}<i class="el-icon-right" />
  58. </el-button>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import StepBar from '@/components/StepBar.vue';
  68. import { PageQueryBookList_SelectBookForCourse } from '@/api/list';
  69. import { AddBookToCourse, RemoveBookFromCourse } from '@/api/course';
  70. export default {
  71. name: 'SelectBook',
  72. components: {
  73. StepBar
  74. },
  75. data() {
  76. return {
  77. id: this.$route.params.id,
  78. is_template: 'is_template' in this.$route.query ? this.$route.query.is_template === 'true' : false,
  79. search: '',
  80. page_capacity: 14,
  81. cur_page: 1,
  82. total_count: 0,
  83. book_list: []
  84. };
  85. },
  86. created() {
  87. this.queryBookList();
  88. },
  89. methods: {
  90. queryBookList() {
  91. PageQueryBookList_SelectBookForCourse({
  92. name: this.search,
  93. course_id: this.id,
  94. page_capacity: this.page_capacity,
  95. cur_page: this.cur_page
  96. }).then(({ book_list, cur_page, total_count }) => {
  97. this.cur_page = cur_page;
  98. this.total_count = total_count;
  99. this.book_list = book_list;
  100. });
  101. },
  102. changePage(newPage) {
  103. this.cur_page = newPage;
  104. this.queryBookList();
  105. },
  106. addOrRemoveBookToCourse(book_id) {
  107. const data = {
  108. course_id: this.id,
  109. book_id
  110. };
  111. const bookIndex = this.book_list.findIndex(({ id }) => id === book_id);
  112. if (this.book_list[bookIndex].is_selected === 'true') {
  113. RemoveBookFromCourse(data).then(() => {
  114. this.$message.success(this.$i18n.t('Key350'));
  115. this.book_list[bookIndex].is_selected = 'false';
  116. });
  117. } else {
  118. AddBookToCourse(data).then(() => {
  119. this.$message.success(this.$i18n.t('Key351'));
  120. this.book_list[bookIndex].is_selected = 'true';
  121. });
  122. }
  123. },
  124. prevCourseInfo() {
  125. this.$router.push(`/create_course_step_table/course_info?id=${this.id}&is_template=${this.is_template}`);
  126. },
  127. nextStep() {
  128. this.$router.push({
  129. path: `/create_course_step_table/create_task/${this.id}?is_template=${this.is_template}`
  130. });
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="scss">
  136. @import '~@/styles/mixin';
  137. .select-book {
  138. @include container;
  139. margin-top: $step-h;
  140. &-container {
  141. width: $basic-width;
  142. min-width: $basic-width;
  143. min-height: 674px;
  144. padding: 24px 32px;
  145. background-color: #fff;
  146. border-radius: 8px;
  147. &-title {
  148. padding-bottom: 24px;
  149. font-size: 20px;
  150. font-weight: 700;
  151. }
  152. &-table {
  153. .search {
  154. display: flex;
  155. justify-content: space-between;
  156. margin-bottom: 24px;
  157. .keyword {
  158. width: 300px;
  159. }
  160. .buy {
  161. margin-left: 16px;
  162. color: $basic-color;
  163. }
  164. .tip {
  165. margin-left: 16px;
  166. }
  167. }
  168. .book {
  169. display: flex;
  170. flex-direction: column;
  171. justify-content: space-between;
  172. min-height: calc(100vh - #{$header-h} - #{$step-h} - 224px);
  173. &-list {
  174. display: flex;
  175. flex-wrap: wrap;
  176. justify-content: flex-start;
  177. margin-bottom: 50px;
  178. &-item {
  179. display: inline-block;
  180. width: 120px;
  181. min-height: 192px;
  182. margin-right: 48px;
  183. &-img {
  184. position: relative;
  185. width: 100%;
  186. height: 160px;
  187. cursor: pointer;
  188. border: 1px solid #c4c4c4;
  189. .el-image {
  190. width: 100%;
  191. height: 100%;
  192. }
  193. &.selected {
  194. border: 2px solid $basic-color;
  195. &::after {
  196. position: absolute;
  197. right: 0;
  198. bottom: 0;
  199. display: inline-block;
  200. width: 24px;
  201. height: 24px;
  202. line-height: 30px;
  203. color: #fff;
  204. text-align: center;
  205. content: '√';
  206. background-color: $basic-color;
  207. border-top-left-radius: 5px;
  208. }
  209. }
  210. }
  211. &-name {
  212. margin-top: 8px;
  213. word-wrap: break-word;
  214. }
  215. &:nth-child(7n) {
  216. margin-right: 0;
  217. }
  218. &:nth-child(n + 8) {
  219. margin-top: 40px;
  220. }
  221. }
  222. }
  223. &-bottom {
  224. display: flex;
  225. align-items: flex-end;
  226. justify-content: space-between;
  227. .prev-step .el-icon-back {
  228. margin-right: 12px;
  229. }
  230. .next-step .el-icon-right {
  231. margin-left: 12px;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>