learn.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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="filter-box">
  5. <view class="b-item" v-for="(item, index) in groupList" :key="index" :class="{ active: index == groupIndex }" @click="onGroupSelect(index)">
  6. <view class="">{{ 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. width: 100%;
  217. padding-bottom: 50rpx;
  218. background-image: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/xbg_2.png');
  219. background-size: 100% 100%;
  220. background-attachment: fixed;
  221. background-repeat: repeat-y;
  222. height: 100%;
  223. }
  224. .filter-box {
  225. padding: 30upx 50upx 0 50upx;
  226. margin-bottom: 30upx;
  227. display: flex;
  228. align-items: center;
  229. justify-content: space-between;
  230. }
  231. .active {
  232. color: #fae5bb !important;
  233. background-image: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/cy_tit1.png') !important;
  234. }
  235. .filter-box .b-item {
  236. width: 278rpx;
  237. height: 80rpx;
  238. font-size: 30rpx;
  239. color: #ffefc4;
  240. font-weight: 600;
  241. text-align: center;
  242. line-height: 80rpx;
  243. background-image: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/cy_tit2.png');
  244. background-size: 100% 100%;
  245. }
  246. .filter-box .b-item.f-active {
  247. padding-bottom: 0;
  248. border-bottom: 6upx solid #da5650;
  249. }
  250. .filter-box .b-item.f-active .s-tit {
  251. color: #da5650;
  252. }
  253. .filter-box .b-item .s-tit {
  254. color: #333;
  255. }
  256. .course-list .course-item {
  257. padding: 30upx;
  258. background: #fff;
  259. display: flex;
  260. align-items: center;
  261. border-bottom: 2upx solid #eee;
  262. }
  263. .course-list .course-item:last-child {
  264. border-bottom: none;
  265. margin-bottom: 0;
  266. }
  267. .course-list .course-item .b-cover {
  268. width: 140upx;
  269. height: 160upx;
  270. }
  271. .course-list .course-item .b-cover image {
  272. width: 100%;
  273. height: 100%;
  274. }
  275. .course-list .course-item .b-main {
  276. flex: 1;
  277. margin-left: 20upx;
  278. }
  279. .course-list .course-item .b-main .b-title {
  280. font-size: 30upx;
  281. color: #333;
  282. width: 530upx;
  283. display: inline-block;
  284. }
  285. .course-list .course-item .b-main .b-percent {
  286. margin-top: 10upx;
  287. display: flex;
  288. flex-direction: column;
  289. }
  290. .course-list .course-item .b-main .b-percent .b-line {
  291. position: relative;
  292. width: 100%;
  293. height: 20upx;
  294. background: #eee;
  295. }
  296. .course-list .course-item .b-main .b-percent .b-line .s-num {
  297. position: absolute;
  298. top: 0;
  299. left: 0;
  300. height: 20upx;
  301. background: rgba(218, 86, 80, 0.8);
  302. }
  303. .course-list .course-item .b-main .b-percent .b-data {
  304. margin-top: 10upx;
  305. display: flex;
  306. align-items: center;
  307. justify-content: space-between;
  308. }
  309. .course-list .course-item .b-main .b-percent .b-data .s-time {
  310. font-size: 26upx;
  311. color: #666;
  312. }
  313. .course-list .course-item .b-main .b-percent .b-data .s-percent {
  314. font-size: 24upx;
  315. color: #999;
  316. }
  317. .course-list .course-item .b-main .b-info {
  318. margin-top: 20upx;
  319. display: flex;
  320. align-items: center;
  321. justify-content: space-between;
  322. }
  323. .course-list .course-item .b-main .b-info .s-category {
  324. font-size: 24upx;
  325. color: #666;
  326. }
  327. .course-list .course-item .b-main .b-info .s-option {
  328. font-size: 32upx;
  329. color: #999;
  330. }
  331. .schedule-list .schedule-item {
  332. padding: 30upx;
  333. background: #fff;
  334. display: flex;
  335. align-items: center;
  336. border-bottom: 2upx solid #eee;
  337. }
  338. .schedule-list .schedule-item:last-child {
  339. border-bottom: none;
  340. margin-bottom: 0;
  341. }
  342. .schedule-list .schedule-item .b-cover {
  343. width: 140upx;
  344. height: 160upx;
  345. }
  346. .schedule-list .schedule-item .b-cover image {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. .schedule-list .schedule-item .b-main {
  351. flex: 1;
  352. margin-left: 20upx;
  353. }
  354. .schedule-list .schedule-item .b-main .b-title {
  355. font-size: 30upx;
  356. color: #333;
  357. width: 530upx;
  358. display: inline-block;
  359. }
  360. .schedule-list .schedule-item .b-main .b-percent {
  361. margin-top: 10upx;
  362. display: flex;
  363. flex-direction: column;
  364. }
  365. .schedule-list .schedule-item .b-main .b-percent .b-line {
  366. position: relative;
  367. width: 100%;
  368. height: 20upx;
  369. background: #eee;
  370. }
  371. .schedule-list .schedule-item .b-main .b-percent .b-line .s-num {
  372. position: absolute;
  373. top: 0;
  374. left: 0;
  375. height: 20upx;
  376. background: rgba(218, 86, 80, 0.8);
  377. }
  378. .schedule-list .schedule-item .b-main .b-percent .b-data {
  379. margin-top: 10upx;
  380. display: flex;
  381. align-items: center;
  382. justify-content: space-between;
  383. }
  384. .schedule-list .schedule-item .b-main .b-percent .b-data .s-time {
  385. font-size: 26upx;
  386. color: #333;
  387. }
  388. .schedule-list .schedule-item .b-main .b-percent .b-data .s-percent {
  389. font-size: 24upx;
  390. color: #666;
  391. }
  392. .schedule-list .schedule-item .b-main .b-info {
  393. margin-top: 16upx;
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. }
  398. .schedule-list .schedule-item .b-main .b-info .s-category {
  399. font-size: 24upx;
  400. color: #666;
  401. }
  402. .schedule-list .schedule-item .b-main .b-info .s-option {
  403. font-size: 32upx;
  404. color: #999;
  405. }
  406. </style>