index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view class="wrap">
  3. <u-navbar :autoBack="true" title="课程" bgColor="rgba(255,255,255,0)" :placeholder="true" titleStyle="font-weight:bold;color:#000000"></u-navbar>
  4. <view class="search">
  5. <view class="b-input">
  6. <input class="s-input" :value="keyword" @input="onInput" @confirm="onSearch" placeholder="搜索课程" />
  7. <view class="s-submit iconfont icon-search" @click="onSearch"></view>
  8. </view>
  9. </view>
  10. <view class="category-list">
  11. <view class="b-row">
  12. <view class="b-all" @click="onCategorySelect('first', -1)" :class="{ 'f-active': -1 === firstCategoryIndex }">不限</view>
  13. <view class="b-items">
  14. <view
  15. class="s-item"
  16. v-for="(item, index) in categoryList"
  17. :key="index"
  18. @click="onCategorySelect('first', index)"
  19. :class="{ 'f-active': index === firstCategoryIndex }"
  20. >
  21. {{ item.name }}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="b-row" v-if="secondCategoryList.length > 0">
  26. <view class="b-all" @click="onCategorySelect('second', -1)" :class="{ 'f-active': -1 === secondCategoryIndex }">不限</view>
  27. <view class="b-items">
  28. <view
  29. class="s-item"
  30. v-for="(item, index) in secondCategoryList"
  31. :key="index"
  32. @click="onCategorySelect('second', index)"
  33. :class="{ 'f-active': index === secondCategoryIndex }"
  34. >
  35. {{ item.name }}
  36. </view>
  37. </view>
  38. </view>
  39. <view class="b-row" v-if="thirdCategoryList.length > 0">
  40. <view class="b-all" @click="onCategorySelect('third', -1)" :class="{ 'f-active': -1 === thirdCategoryIndex }">不限</view>
  41. <view class="b-items">
  42. <view
  43. class="s-item"
  44. v-for="(item, index) in thirdCategoryList"
  45. :key="index"
  46. @click="onCategorySelect('third', index)"
  47. :class="{ 'f-active': index === thirdCategoryIndex }"
  48. >
  49. {{ item.name }}
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="filter-box">
  55. <view class="b-item" v-for="(item, index) in groupList" :key="index" :class="{ 'f-active': index == groupIndex }" @click="onGroupSelect(index)">
  56. <view class="s-tit">{{ item.name }}</view>
  57. <view class="iconfont" v-if="item.sort && index == groupIndex" :class="{ 'icon-unfold': item.sort == 'asc', 'icon-fold': item.sort == 'desc' }"></view>
  58. </view>
  59. </view>
  60. <view class="course-list">
  61. <view class="b-items">
  62. <course-item v-for="item in courseList" :item="item" :key="item.id"></course-item>
  63. </view>
  64. <!-- 加载中 -->
  65. <load-more :loadingType="loadingType" :loadingText="loadingText"></load-more>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. // import { getCategoryList, getCourseList } from '@/service/api/course.js';
  71. // import mixinsCommon from '@/mixins/common.js';
  72. let that;
  73. export default {
  74. // mixins: [mixinsCommon],
  75. data() {
  76. return {
  77. groupIndex: 0,
  78. groupList: [
  79. {
  80. name: '全部',
  81. value: 'all',
  82. sort: ''
  83. },
  84. {
  85. name: '免费',
  86. value: 'free',
  87. sort: ''
  88. },
  89. {
  90. name: 'VIP',
  91. value: 'vip',
  92. sort: ''
  93. },
  94. {
  95. name: '热门',
  96. value: 'hot',
  97. sort: ''
  98. },
  99. {
  100. name: '价格',
  101. value: 'price',
  102. sort: 'asc'
  103. }
  104. ],
  105. categoryList: [],
  106. categoryValue: 0,
  107. firstCategoryIndex: -1,
  108. secondCategoryIndex: -1,
  109. thirdCategoryIndex: -1,
  110. courseList: [],
  111. keyword: '',
  112. loadingType: 1,
  113. loadingText: ''
  114. };
  115. },
  116. computed: {
  117. secondCategoryList() {
  118. if (this.firstCategoryIndex === -1) {
  119. return [];
  120. }
  121. return this.categoryList[this.firstCategoryIndex].children;
  122. },
  123. thirdCategoryList() {
  124. if (this.secondCategoryIndex === -1) {
  125. return [];
  126. }
  127. return this.categoryList[this.firstCategoryIndex].children[this.secondCategoryIndex].children;
  128. }
  129. },
  130. onLoad(options) {
  131. that = this;
  132. this.$api.getCategoryList({}, function (res) {
  133. // console.log(res.data, 9999);
  134. that.categoryList = res.data;
  135. });
  136. // getCategoryList().then(([err, res]) => {
  137. // console.log('getCourseList', err, res);
  138. // if (!err) {
  139. // this.categoryList = res;
  140. // console.log(this.categoryList, 'this.categoryList');
  141. // }
  142. // });
  143. this.loadList(true);
  144. },
  145. onReachBottom() {
  146. if (this.loadingType !== 1 && this.loadingType !== 2) {
  147. this.loadList();
  148. }
  149. },
  150. methods: {
  151. loadList(refresh) {
  152. console.log('loadList', refresh);
  153. if (refresh) {
  154. this.page = 1;
  155. this.courseList = [];
  156. } else {
  157. this.page++;
  158. }
  159. this.loadingType = 1;
  160. this.loadingText = '';
  161. this.$api.getCourseList(
  162. {
  163. category_id: this.categoryValue,
  164. group: this.groupList[this.groupIndex].value,
  165. keyword: this.keyword,
  166. page: this.page,
  167. page_size: 10,
  168. sort: this.groupList[this.groupIndex].sort
  169. },
  170. function (res) {
  171. that.loadingType = -1;
  172. console.log('啦啦啦', res);
  173. that.loadingType = -1;
  174. if (res.code == 1) {
  175. if (res.data.items.length > 0) {
  176. that.courseList = [...that.courseList, ...res.data.items];
  177. console.log(that.courseList, '33333333333');
  178. } else {
  179. that.loadingType = 2;
  180. if (that.page == 1) {
  181. that.loadingText = '暂无课程数据';
  182. }
  183. that.page--; // 重置分页
  184. }
  185. } else {
  186. that.loadingType = 3;
  187. }
  188. }
  189. );
  190. // getCourseList(this.categoryValue, this.groupList[this.groupIndex].value, this.groupList[this.groupIndex].sort, this.keyword, this.page, 10).then(([err, res]) => {
  191. // console.log('getCourseList', err, res);
  192. // this.loadingType = -1;
  193. // if (!err) {
  194. // if (res.items.length > 0) {
  195. // this.courseList = [...this.courseList, ...res.items];
  196. // } else {
  197. // this.loadingType = 2;
  198. // if (this.page == 1) {
  199. // this.loadingText = '暂无课程数据';
  200. // }
  201. // this.page--; // 重置分页
  202. // }
  203. // } else {
  204. // this.loadingType = 3;
  205. // }
  206. // });
  207. },
  208. onInput(e) {
  209. this.keyword = e.detail.value;
  210. },
  211. onSearch() {
  212. if (this.keyword) {
  213. this.onCategorySelect('first', -1);
  214. }
  215. },
  216. onCategorySelect(level, index) {
  217. if (this.keyword && !(level === 'first' && index === -1)) {
  218. this.keyword = '';
  219. }
  220. if (level === 'first') {
  221. this.firstCategoryIndex = index;
  222. if (index === -1) {
  223. this.categoryValue = 0;
  224. } else {
  225. this.categoryValue = this.categoryList[index].id;
  226. }
  227. } else if (level === 'second') {
  228. this.secondCategoryIndex = index;
  229. if (index === -1) {
  230. this.categoryValue = this.categoryList[this.firstCategoryIndex].id;
  231. } else {
  232. this.categoryValue = this.categoryList[this.firstCategoryIndex].children[index].id;
  233. }
  234. } else if (level === 'third') {
  235. this.thirdCategoryIndex = index;
  236. if (index === -1) {
  237. this.categoryValue = this.categoryList[this.firstCategoryIndex].children[this.secondCategoryIndex].id;
  238. } else {
  239. this.categoryValue = this.categoryList[this.firstCategoryIndex].children[this.secondCategoryIndex].children[index].id;
  240. }
  241. }
  242. this.loadList(true);
  243. },
  244. // 分类点击事件
  245. onGroupSelect(index) {
  246. console.log(index);
  247. if (index == this.groupIndex) {
  248. const sort = this.groupList[this.groupIndex].sort;
  249. if (sort) {
  250. if (sort === 'asc') {
  251. this.groupList[this.groupIndex].sort = 'desc';
  252. } else {
  253. this.groupList[this.groupIndex].sort = 'asc';
  254. }
  255. }
  256. }
  257. this.groupIndex = index;
  258. this.loadList(true);
  259. }
  260. }
  261. };
  262. </script>
  263. <style>
  264. .wrap {
  265. width: 100%;
  266. padding-bottom: 50rpx;
  267. background-image: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/xbg_2.png');
  268. background-size: 100% 100%;
  269. background-attachment: fixed;
  270. background-repeat: repeat-y;
  271. height: 100%;
  272. }
  273. .search {
  274. margin: auto;
  275. padding: 0 30upx;
  276. width: 690upx;
  277. height: 90upx;
  278. background: #da5650;
  279. display: flex;
  280. align-items: center;
  281. }
  282. .search .b-input {
  283. padding: 0 20upx;
  284. flex: 1;
  285. height: 70upx;
  286. background: #fff;
  287. border-radius: 10upx;
  288. display: flex;
  289. align-items: center;
  290. }
  291. .search .b-input .s-input {
  292. flex: 1;
  293. color: #333;
  294. font-size: 26upx;
  295. }
  296. .search .b-input .s-submit {
  297. margin-left: 20upx;
  298. color: #c3c3c3;
  299. font-size: 40upx;
  300. }
  301. .category-list {
  302. background: #fff;
  303. }
  304. .category-list .b-row {
  305. padding: 0 30upx;
  306. display: flex;
  307. border-bottom: 2upx solid #eee;
  308. }
  309. .category-list .b-all {
  310. padding: 20upx 0;
  311. font-size: 28upx;
  312. }
  313. .category-list .b-all.f-active {
  314. font-weight: bold;
  315. }
  316. .category-list .b-items {
  317. margin-left: 20upx;
  318. flex: 1;
  319. display: flex;
  320. flex-wrap: wrap;
  321. }
  322. .category-list .b-items .s-item {
  323. padding: 20upx 20upx;
  324. font-size: 28upx;
  325. }
  326. .category-list .b-items .s-item.f-active {
  327. font-weight: bold;
  328. }
  329. .filter-box {
  330. background: #fff;
  331. display: flex;
  332. align-items: center;
  333. }
  334. .filter-box .b-item {
  335. padding: 20upx 30upx;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. font-size: 28upx;
  340. }
  341. .filter-box .b-item.f-active {
  342. font-weight: bold;
  343. }
  344. .filter-box .b-item .s-tit {
  345. color: #333;
  346. }
  347. .filter-box .b-item .iconfont {
  348. color: #999;
  349. font-size: 28upx;
  350. margin-left: 10upx;
  351. }
  352. .course-list {
  353. margin-top: 30upx;
  354. }
  355. .course-list .course-item {
  356. border-bottom: 1upx solid #eee;
  357. }
  358. .course-list .course-item:last-child {
  359. border-bottom: none;
  360. }
  361. </style>