learn.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view class="wrap">
  3. <u-navbar :autoBack="true" title="我的学习" bgColor="rgba(255,255,255,255)" :placeholder="true" titleStyle="font-weight:bold;color:#121212"></u-navbar>
  4. <view class="filter-box">
  5. <view class="b-item" v-for="(item, index) in groupList" :key="index" :class="{ 'f-active': index == groupIndex }" @click="onGroupSelect(index)">
  6. <view class="s-tit">{{ item.name }}</view>
  7. </view>
  8. </view>
  9. <view class="course-list" v-if="groupList[groupIndex].value === 'course' && recordList.length > 0">
  10. <view class="course-item" @click="onJumpDetail('course', item.course_id)" v-for="(item, index) in recordList" :key="index">
  11. <view class="b-cover">
  12. <image :src="item.course_data.cover_url" mode="aspectFill"></image>
  13. </view>
  14. <view class="b-main">
  15. <text class="b-title too-long">{{ item.course_data.name }}</text>
  16. <view class="b-percent">
  17. <view class="b-line">
  18. <view class="s-num" :style="'width:' + item.learn_percent + '%'"></view>
  19. </view>
  20. <view class="b-data">
  21. <view class="s-time">{{ item.course_data.total_length }}课时</view>
  22. <view class="s-percent">已学{{ item.learn_percent }}%</view>
  23. </view>
  24. </view>
  25. <view class="b-info">
  26. <view class="s-category">{{ item.course_data.category_name }}</view>
  27. <!-- <view class="s-option">
  28. <view class="iconfont icon-option"></view>
  29. </view> -->
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="schedule-list" v-if="groupList[groupIndex].value === 'schedule' && recordList.length > 0">
  35. <view class="schedule-item" @click="onJumpDetail('schedule', item.schedule_id)" v-for="(item, index) in recordList" :key="index">
  36. <view class="b-cover">
  37. <image :src="item.schedule_data.cover_url" mode="aspectFill"></image>
  38. </view>
  39. <view class="b-main">
  40. <text class="b-title too-long">{{ item.schedule_data.name }}</text>
  41. <view class="b-percent">
  42. <view class="b-line">
  43. <view class="s-num" :style="'width:' + item.learn_percent + '%'"></view>
  44. </view>
  45. <view class="b-data">
  46. <view class="s-time">{{ item.schedule_data.total_length }}课时</view>
  47. <view class="s-percent">已学{{ item.learn_percent }}%</view>
  48. </view>
  49. </view>
  50. <view class="b-info">
  51. <view class="s-category">{{ item.schedule_data.category_name }}</view>
  52. <!-- <view class="s-option">
  53. <view class="iconfont icon-option"></view>
  54. </view> -->
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 加载中 -->
  60. <load-more :loadingType="loadingType" :loadingText="loadingText" color="#888888"></load-more>
  61. </view>
  62. </template>
  63. <script>
  64. // import { getMineCourseList } from '@/service/api/course.js';
  65. // import { getMineScheduleList } from '@/service/api/schedule.js';
  66. import Util from '@/common/util';
  67. import mixinsCommon from '@/mixins/common.js';
  68. export default {
  69. mixins: [mixinsCommon],
  70. data() {
  71. return {
  72. groupList: [
  73. {
  74. name: '我的课程',
  75. value: 'course'
  76. },
  77. {
  78. name: '我的培训',
  79. value: 'schedule'
  80. }
  81. ],
  82. groupIndex: 0,
  83. recordList: [],
  84. hasLoad: false,
  85. refreshTime: 0,
  86. loadingType: 1,
  87. loadingText: ''
  88. };
  89. },
  90. onLoad(options) {
  91. if (!this.$store.state.learnType) {
  92. this.refreshTime = Util.getTimestamp();
  93. this.loadRecordList(true);
  94. }
  95. },
  96. onShow() {
  97. // switchTab时通过这种方式传参
  98. console.log('onShow', this.$store.state.learnType);
  99. const learnType = this.$store.state.learnType;
  100. if (learnType) {
  101. this.$store.commit('delLearnType');
  102. if (learnType === 'course') {
  103. this.groupIndex = 0;
  104. } else if (learnType === 'schedule') {
  105. this.groupIndex = 1;
  106. }
  107. this.loadRecordList(true);
  108. } else {
  109. if (this.hasLoad) {
  110. const timestamp = Util.getTimestamp();
  111. if (timestamp - this.refreshTime >= 5) {
  112. this.refreshTime = timestamp;
  113. this.loadRecordList(true);
  114. }
  115. }
  116. }
  117. },
  118. onReachBottom() {
  119. if (this.loadingType !== 1 && this.loadingType !== 2) {
  120. this.loadRecordList();
  121. }
  122. },
  123. methods: {
  124. loadRecordList(refresh) {
  125. if (this.isLogin) {
  126. if (this.groupList[this.groupIndex].value === 'course') {
  127. this.loadCourseList(refresh);
  128. } else if (this.groupList[this.groupIndex].value === 'schedule') {
  129. this.loadScheduleList(refresh);
  130. }
  131. } else {
  132. this.loadingType = 2;
  133. this.loadingText = '暂无数据,请先登录吧';
  134. }
  135. },
  136. loadCourseList(refresh) {
  137. console.log('loadCourseList', refresh);
  138. if (refresh) {
  139. this.page = 1;
  140. this.recordList = [];
  141. } else {
  142. this.page++;
  143. }
  144. this.loadingType = 1;
  145. this.loadingText = '';
  146. // this.$api.getMineCourseList({},function(res){
  147. // })
  148. // getMineCourseList(this.page, 10).then(([err, res]) => {
  149. // console.log('getMineCourseList', err, res);
  150. // this.loadingType = -1;
  151. // this.hasLoad = true;
  152. // if (!err) {
  153. // if (res.items.length > 0) {
  154. // this.recordList = [...this.recordList, ...res.items];
  155. // } else {
  156. // this.loadingType = 2;
  157. // if (this.page == 1) {
  158. // this.loadingText = '暂无记录,快去学习吧';
  159. // }
  160. // this.page--; // 重置分页
  161. // }
  162. // } else {
  163. // this.loadingType = 2;
  164. // }
  165. // });
  166. },
  167. loadScheduleList(refresh) {
  168. console.log('loadScheduleList', refresh);
  169. if (refresh) {
  170. this.page = 1;
  171. this.recordList = [];
  172. } else {
  173. this.page++;
  174. }
  175. this.loadingType = 1;
  176. this.loadingText = '';
  177. getMineScheduleList(this.page, 10).then(([err, res]) => {
  178. console.log('getMineScheduleList', err, res);
  179. this.loadingType = -1;
  180. this.hasLoad = true;
  181. if (!err) {
  182. if (res.items.length > 0) {
  183. this.recordList = [...this.recordList, ...res.items];
  184. } else {
  185. this.loadingType = 2;
  186. if (this.page == 1) {
  187. this.loadingText = '暂无记录,快去参加吧';
  188. }
  189. this.page--; // 重置分页
  190. }
  191. } else {
  192. this.loadingType = 2;
  193. }
  194. });
  195. },
  196. onGroupSelect(index) {
  197. this.groupIndex = index;
  198. this.loadRecordList(true);
  199. },
  200. onJumpDetail(type, id) {
  201. if (type === 'schedule') {
  202. uni.navigateTo({
  203. url: '/pages/schedule/detail?sid=' + id
  204. });
  205. } else if (type === 'course') {
  206. uni.navigateTo({
  207. url: '/pages/course/detail?cid=' + id
  208. });
  209. }
  210. }
  211. }
  212. };
  213. </script>
  214. <style>
  215. .wrap {
  216. padding-bottom: 150upx;
  217. }
  218. .filter-box {
  219. padding: 30upx 50upx 0 50upx;
  220. margin-bottom: 30upx;
  221. background: #fff;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. }
  226. .filter-box .b-item {
  227. margin: 0 40upx;
  228. height: 80upx;
  229. line-height: 80upx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. font-size: 30upx;
  234. padding-bottom: 6upx;
  235. position: relative;
  236. }
  237. .filter-box .b-item.f-active {
  238. padding-bottom: 0;
  239. border-bottom: 6upx solid #da5650;
  240. }
  241. .filter-box .b-item.f-active .s-tit {
  242. color: #da5650;
  243. }
  244. .filter-box .b-item .s-tit {
  245. color: #333;
  246. }
  247. .course-list .course-item {
  248. padding: 30upx;
  249. background: #fff;
  250. display: flex;
  251. align-items: center;
  252. border-bottom: 2upx solid #eee;
  253. }
  254. .course-list .course-item:last-child {
  255. border-bottom: none;
  256. margin-bottom: 0;
  257. }
  258. .course-list .course-item .b-cover {
  259. width: 140upx;
  260. height: 160upx;
  261. }
  262. .course-list .course-item .b-cover image {
  263. width: 100%;
  264. height: 100%;
  265. }
  266. .course-list .course-item .b-main {
  267. flex: 1;
  268. margin-left: 20upx;
  269. }
  270. .course-list .course-item .b-main .b-title {
  271. font-size: 30upx;
  272. color: #333;
  273. width: 530upx;
  274. display: inline-block;
  275. }
  276. .course-list .course-item .b-main .b-percent {
  277. margin-top: 10upx;
  278. display: flex;
  279. flex-direction: column;
  280. }
  281. .course-list .course-item .b-main .b-percent .b-line {
  282. position: relative;
  283. width: 100%;
  284. height: 20upx;
  285. background: #eee;
  286. }
  287. .course-list .course-item .b-main .b-percent .b-line .s-num {
  288. position: absolute;
  289. top: 0;
  290. left: 0;
  291. height: 20upx;
  292. background: rgba(218, 86, 80, 0.8);
  293. }
  294. .course-list .course-item .b-main .b-percent .b-data {
  295. margin-top: 10upx;
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-between;
  299. }
  300. .course-list .course-item .b-main .b-percent .b-data .s-time {
  301. font-size: 26upx;
  302. color: #666;
  303. }
  304. .course-list .course-item .b-main .b-percent .b-data .s-percent {
  305. font-size: 24upx;
  306. color: #999;
  307. }
  308. .course-list .course-item .b-main .b-info {
  309. margin-top: 20upx;
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. }
  314. .course-list .course-item .b-main .b-info .s-category {
  315. font-size: 24upx;
  316. color: #666;
  317. }
  318. .course-list .course-item .b-main .b-info .s-option {
  319. font-size: 32upx;
  320. color: #999;
  321. }
  322. .schedule-list .schedule-item {
  323. padding: 30upx;
  324. background: #fff;
  325. display: flex;
  326. align-items: center;
  327. border-bottom: 2upx solid #eee;
  328. }
  329. .schedule-list .schedule-item:last-child {
  330. border-bottom: none;
  331. margin-bottom: 0;
  332. }
  333. .schedule-list .schedule-item .b-cover {
  334. width: 140upx;
  335. height: 160upx;
  336. }
  337. .schedule-list .schedule-item .b-cover image {
  338. width: 100%;
  339. height: 100%;
  340. }
  341. .schedule-list .schedule-item .b-main {
  342. flex: 1;
  343. margin-left: 20upx;
  344. }
  345. .schedule-list .schedule-item .b-main .b-title {
  346. font-size: 30upx;
  347. color: #333;
  348. width: 530upx;
  349. display: inline-block;
  350. }
  351. .schedule-list .schedule-item .b-main .b-percent {
  352. margin-top: 10upx;
  353. display: flex;
  354. flex-direction: column;
  355. }
  356. .schedule-list .schedule-item .b-main .b-percent .b-line {
  357. position: relative;
  358. width: 100%;
  359. height: 20upx;
  360. background: #eee;
  361. }
  362. .schedule-list .schedule-item .b-main .b-percent .b-line .s-num {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. height: 20upx;
  367. background: rgba(218, 86, 80, 0.8);
  368. }
  369. .schedule-list .schedule-item .b-main .b-percent .b-data {
  370. margin-top: 10upx;
  371. display: flex;
  372. align-items: center;
  373. justify-content: space-between;
  374. }
  375. .schedule-list .schedule-item .b-main .b-percent .b-data .s-time {
  376. font-size: 26upx;
  377. color: #333;
  378. }
  379. .schedule-list .schedule-item .b-main .b-percent .b-data .s-percent {
  380. font-size: 24upx;
  381. color: #666;
  382. }
  383. .schedule-list .schedule-item .b-main .b-info {
  384. margin-top: 16upx;
  385. display: flex;
  386. align-items: center;
  387. justify-content: space-between;
  388. }
  389. .schedule-list .schedule-item .b-main .b-info .s-category {
  390. font-size: 24upx;
  391. color: #666;
  392. }
  393. .schedule-list .schedule-item .b-main .b-info .s-option {
  394. font-size: 32upx;
  395. color: #999;
  396. }
  397. </style>