index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view>
  3. <view class="video_list">
  4. <view class="video_item" v-for="(item, index) in videoList">
  5. <view class="video_info">
  6. <image class="thumb_img" :src="item.thumb" mode="aspectFit"></image>
  7. <view>
  8. <view class="video_type">
  9. <text class="type_name">{{ item.type_name }}</text>
  10. </view>
  11. <view class="video_title">{{ item.name }}</view>
  12. <view class="video_time">
  13. <text class="time_info">{{ item.end_time }} </text>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="video_btn">
  18. <button class="after_exam" @click="goExam(item.id, item.report_id, item.learn_status)">
  19. {{ item.report_id > 0 ? '查看报告' : '课后评测' }}
  20. </button>
  21. <button class="to_learn" @click.stop="goDetail(item.id)">开始学习</button>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="to_bottom" v-if="!videoList.length"> -----您还没有可学习课程-----</view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. // 产品列表
  33. videoList: [],
  34. // 请求参数
  35. requestParam: {
  36. page: 1,
  37. status: 0,
  38. },
  39. // 是否最后一页
  40. isLast: false,
  41. // 是否请求中
  42. isReqing: false,
  43. };
  44. },
  45. onLoad() {},
  46. onShow() {
  47. // 没有数据的话,或者请求中,不允许刷新
  48. if (this.isReqing) return;
  49. // 初始化页码为1
  50. this.requestParam.page = 1;
  51. // 是否是最后一页
  52. this.isLast = false;
  53. // 设置请求中
  54. this.isReqing = true;
  55. // 请求列表
  56. this.$http.request('api/video_course/get_list', this.requestParam).then((re) => {
  57. // 设置非请求中
  58. this.isReqing = false;
  59. // 成功结果
  60. if (re.code == 'success') {
  61. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  62. this.videoList = re.data.data;
  63. }
  64. });
  65. },
  66. onPullDownRefresh() {
  67. // 如果请求中,不允许请求,
  68. if (this.isReqing) return false;
  69. // 初始化页码为1
  70. this.requestParam.page = 1;
  71. // 是否是最后一页
  72. this.isLast = false;
  73. // 设置请求中
  74. this.isReqing = true;
  75. // 请求列表
  76. this.$http.request('api/video_course/get_list', this.requestParam).then((re) => {
  77. // 设置非请求中
  78. this.isReqing = false;
  79. // 成功结果
  80. if (re.code == 'success') {
  81. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  82. this.videoList = re.data.data;
  83. }
  84. });
  85. uni.stopPullDownRefresh();
  86. },
  87. onReachBottom() {
  88. // 如果页码是0,避免第一页重复
  89. if (this.requestParam.page < 1) return;
  90. // 最后一页不请求
  91. if (this.isLast) return;
  92. // 请求中,不再请求
  93. if (this.isReqing) return;
  94. // 增加一页
  95. this.requestParam.page = this.requestParam.page + 1;
  96. // 设置请求中
  97. this.isReqing = true;
  98. // 请求列表
  99. this.$http.request('api/video_course/get_list', this.requestParam).then((re) => {
  100. // 设置非请求中
  101. this.isReqing = false;
  102. // 成功结果
  103. if (re.code == 'success') {
  104. // 数据
  105. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  106. // 追加数据
  107. this.videoList.push(...re.data.data);
  108. }
  109. });
  110. },
  111. methods: {
  112. goDetail(id) {
  113. uni.navigateTo({
  114. url: '/pages/video/detail?id=' + id,
  115. });
  116. },
  117. goExam(id, report_id, status) {
  118. if (status < 0) {
  119. uni.showToast({
  120. title: '请先完成课程再来答题吧',
  121. icon: 'none',
  122. duration: 2000,
  123. });
  124. return;
  125. }
  126. if (report_id > 0) {
  127. uni.navigateTo({
  128. url: '/pages/video/record?type=exam&record_id=' + report_id,
  129. });
  130. return;
  131. }
  132. uni.navigateTo({
  133. url: '/pages/video/exam?id=' + id,
  134. });
  135. },
  136. },
  137. };
  138. </script>
  139. <style lang="less">
  140. .video_list {
  141. float: left;
  142. width: 750rpx;
  143. display: block;
  144. overflow: hidden;
  145. .video_item {
  146. display: block;
  147. width: 700rpx;
  148. overflow: hidden;
  149. margin-bottom: 10rpx;
  150. padding: 20rpx 25rpx;
  151. border-radius: 10rpx;
  152. background-color: #ffffff;
  153. .video_btn {
  154. display: flex;
  155. align-items: center;
  156. justify-content: flex-end;
  157. gap: 20rpx;
  158. margin-top: 10rpx;
  159. .to_learn {
  160. margin: 0;
  161. color: #fff;
  162. border: none;
  163. width: 140rpx;
  164. height: 50rpx;
  165. font-size: 26rpx;
  166. line-height: 50rpx;
  167. padding: 0rpx 0rpx;
  168. text-align: center;
  169. border-radius: 10rpx;
  170. background-color: #5045e6;
  171. }
  172. .to_learn::after {
  173. border: none;
  174. }
  175. .after_exam {
  176. margin: 0;
  177. color: #5045e6;
  178. border: none;
  179. width: 140rpx;
  180. height: 50rpx;
  181. font-size: 26rpx;
  182. line-height: 50rpx;
  183. padding: 0rpx 0rpx;
  184. text-align: center;
  185. border-radius: 10rpx;
  186. background-color: #fff;
  187. border: 1px solid #5045e6;
  188. }
  189. }
  190. .video_info {
  191. width: 100%;
  192. display: flex;
  193. .thumb_img {
  194. width: 200rpx;
  195. height: 200rpx;
  196. border-radius: 10rpx;
  197. margin-right: 20rpx;
  198. }
  199. .video_type {
  200. color: #999999;
  201. width: 480rpx;
  202. display: block;
  203. height: 60rpx;
  204. font-size: 26rpx;
  205. line-height: 60rpx;
  206. }
  207. .video_title {
  208. width: 480rpx;
  209. display: block;
  210. height: 80rpx;
  211. font-size: 32rpx;
  212. overflow: hidden;
  213. font-weight: bold;
  214. line-height: 40rpx;
  215. text-overflow: ellipsis;
  216. }
  217. .video_time {
  218. color: #999999;
  219. width: 480rpx;
  220. display: block;
  221. height: 60rpx;
  222. font-size: 26rpx;
  223. line-height: 60rpx;
  224. }
  225. }
  226. }
  227. }
  228. </style>