onlineTrainingDetails.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="details">
  3. <u-navbar back-text="" title="" back-icon-color="#FFFFFF" :background="{ background: '#3D5D4C' }" :border-bottom="false"></u-navbar>
  4. <!-- 视频 -->
  5. <video-box ref="videoBox" v-if="isPlay" :videoUrl="videoInfo.videoUrl" @recordDuration="recordDuration"></video-box>
  6. <!-- 介绍 -->
  7. <view class="details-content">
  8. <view class="details-content-title">{{ videoInfo.chapterName }}</view>
  9. <view class="details-content-progress">本课程 共{{ info.amount }}课,已学完{{ info.finishCount }}课,共进度{{ info.finishPercent || 0 }}%</view>
  10. <view class="details-content-teacher">主讲老师:{{ info.presenter }}</view>
  11. <view class="details-content-info">{{ videoInfo.chapterInfo }}</view>
  12. </view>
  13. <!-- 课程章节 -->
  14. <view class="details-classes">
  15. <view class="details-classes-header">
  16. <view>精选课程</view>
  17. <view
  18. >更多
  19. <u-icon name="arrow-right" size="22" color="#A3A3A3" />
  20. </view>
  21. </view>
  22. <view class="details-classes-list">
  23. <view
  24. class="details-classes-list-item"
  25. v-for="(item, index) in info.chapterList"
  26. :key="index"
  27. :class="{ active: index === videoIndex }"
  28. @click="classesClick(index)"
  29. >
  30. <view>{{ index + 1 }}</view>
  31. <view>{{ item.flag === 2 ? '已学' : item.finishPercent + '%' }}</view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="details-line">
  36. <view></view>
  37. </view>
  38. <!-- 评论 -->
  39. <!-- <view class="details-comment">
  40. <view class="details-comment-header">
  41. <view>课程评论</view>
  42. <view>共{{ total }}条评论</view>
  43. </view>
  44. <view class="details-comment-list">
  45. <view class="details-comment-list-item" v-for="(item, index) in commentList" :key="index">
  46. <view class="left">
  47. <u-avatar :src="item.createByAvatar" size="96" mode="square"></u-avatar>
  48. </view>
  49. <view class="right">
  50. <view>{{ item.createBy }}</view>
  51. <view>
  52. <u-rate :count="5" size="28" disabled="" active-color="#FFBC00" v-model="item.starLevel"> </u-rate>
  53. <text>{{ item.createTime }}</text>
  54. </view>
  55. <view>{{ item.content }}</view>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="details-comment-page" v-if="total > 5">
  60. <wyb-pagination :padding="0" :totalItems="total" :current="query.pageNum" @change="pageChange" />
  61. </view>
  62. <view class="details-comment-mine">
  63. <text>我的评论</text>
  64. </view>
  65. <view class="details-comment-conent">
  66. <view class="details-comment-conent-star">
  67. <u-rate :count="5" size="40" active-color="#FFBC00" v-model="form.starLevel"></u-rate>
  68. </view>
  69. <view class="details-comment-content-textarea">
  70. <u-input
  71. v-model="form.content"
  72. placeholder="请输入您的评价"
  73. type="textarea"
  74. :custom-style="{ backgroundColor: '#F5F5F5', padding: '30rpx', borderRadius: '10rpx', minHeight: '280rpx' }"
  75. >
  76. </u-input>
  77. </view>
  78. <view class="details-comment-conent-button" @click="submitCommet">提交</view>
  79. </view>
  80. </view> -->
  81. <u-toast ref="uToast" />
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. info: {},
  89. videoInfo: {},
  90. classesId: '',
  91. isPlay: true,
  92. query: {
  93. pageNum: 1,
  94. pageSize: 5,
  95. tabId: ''
  96. },
  97. total: 0,
  98. commentList: [],
  99. form: {
  100. tabId: '',
  101. starLevel: 0,
  102. content: ''
  103. },
  104. videoIndex: 0
  105. };
  106. },
  107. onLoad(page) {
  108. if (page.id) {
  109. this.getClassesDetails(page.id);
  110. this.classesId = page.id;
  111. this.query.tabId = this.classesId;
  112. this.form.tabId = this.classesId;
  113. }
  114. },
  115. beforeDestroy() {
  116. this.$refs['videoBox'].recordDuration(this.videoIndex, false);
  117. },
  118. methods: {
  119. /**
  120. * 获取课程详情
  121. * @param {Object} id
  122. */
  123. getClassesDetails(id) {
  124. this.videoLoading = true;
  125. this.videoInfo.videoUrl = null;
  126. this.$u.api.training
  127. .getOnlineDetailsApi({
  128. id
  129. })
  130. .then((res) => {
  131. if (res.code === 200) {
  132. this.info = res.data;
  133. this.videoInfo = res.data.chapterList[this.videoIndex];
  134. this.query.pageNum = 1;
  135. this.isPlay = true;
  136. this.$nextTick(() => {
  137. this.$refs['videoBox'].loadVideo(this.videoInfo);
  138. });
  139. // this.getCommentList();
  140. }
  141. });
  142. },
  143. /**
  144. * 课程章节点击
  145. * @param {Object} index
  146. */
  147. classesClick(index) {
  148. this.$refs['videoBox'].recordDuration(index, true);
  149. this.videoIndex = index;
  150. this.isPlay = false;
  151. },
  152. /**
  153. * 描述
  154. * @date 2022-10-19
  155. * @param {any} obj
  156. * @param {any} index
  157. * @returns {any}
  158. */
  159. recordDuration(obj, index, refresh = true) {
  160. this.submitTimeLong(
  161. { tabId: this.videoInfo.id, playDuration: obj.playDuration, currentDuration: obj.currentDuration, duration: obj.duration },
  162. index || this.videoIndex,
  163. refresh
  164. );
  165. },
  166. /**
  167. * 提交课程时长
  168. */
  169. submitTimeLong({ tabId, playDuration, duration, currentDuration }, index, refresh) {
  170. this.$u.api.training
  171. .videoTimeLongApi({
  172. tabId,
  173. playDuration,
  174. duration,
  175. currentDuration
  176. })
  177. .then((res) => {
  178. if (res.code === 200) {
  179. this.videoInfo = this.info.chapterList[index];
  180. if (refresh) {
  181. this.$refs.uToast.show({
  182. title: '已记录章节时长!',
  183. type: 'success'
  184. });
  185. this.getClassesDetails(this.classesId);
  186. }
  187. } else {
  188. this.$refs.uToast.show({
  189. title: res.msg,
  190. type: 'error'
  191. });
  192. }
  193. });
  194. },
  195. /**
  196. * 获取评论列表
  197. */
  198. getCommentList() {
  199. this.$u.api.training.getClassesCommentApi(this.query).then((res) => {
  200. if (res.code === 200) {
  201. this.total = Number(res.total);
  202. this.commentList = res.rows;
  203. }
  204. });
  205. },
  206. /**
  207. * @param {Object} e 分页触发
  208. */
  209. pageChange(e) {
  210. this.query.pageNum = e.current;
  211. this.getCommentList();
  212. },
  213. /**
  214. * 提交评论
  215. */
  216. submitCommet() {
  217. if (this.form.starLevel && this.form.content) {
  218. this.$u.api.training.addClassesCommentApi(this.form).then((res) => {
  219. if (res.code === 200) {
  220. this.$refs.uToast.show({
  221. title: '评论成功!',
  222. type: 'success'
  223. });
  224. this.form.content = '';
  225. this.form.starLevel = 0;
  226. this.getCommentList();
  227. } else {
  228. this.$refs.uToast.show({
  229. title: res.msg,
  230. type: 'error'
  231. });
  232. }
  233. });
  234. }
  235. if (!this.form.starLevel) {
  236. this.$refs.uToast.show({
  237. title: '请选择星级',
  238. type: 'warning'
  239. });
  240. }
  241. if (!this.form.content) {
  242. this.$refs.uToast.show({
  243. title: '请输入评论内容',
  244. type: 'warning'
  245. });
  246. }
  247. }
  248. }
  249. };
  250. </script>
  251. <style lang="scss" scoped>
  252. @import './onlineTrainingDetails.scss';
  253. </style>