courseDetailed.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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"
  10. >本课程 共{{ info.amount || 0 }}课,已学完{{ info.finishCount || 0 }}课,共进度{{ info.finishPercent || 0 }}%</view
  11. >
  12. <view class="details-content-teacher">主讲老师:{{ info.presenter || '-' }}</view>
  13. <view class="details-content-info">{{ videoInfo.chapterInfo || '-' }}</view>
  14. </view>
  15. <!-- 课程章节 -->
  16. <view class="details-classes">
  17. <view class="details-classes-header">
  18. <view>精选课程</view>
  19. <view>
  20. 更多
  21. <u-icon name="arrow-right" size="22" color="#A3A3A3" />
  22. </view>
  23. </view>
  24. <view class="details-classes-list">
  25. <view
  26. class="details-classes-list-item"
  27. v-for="(item, index) in info.chapterList"
  28. :key="index"
  29. :class="{ active: index === videoIndex }"
  30. @click="classesClick(index)"
  31. >
  32. <view>{{ index + 1 }}</view>
  33. <view>{{ item.flag === 2 ? '已学' : item.finishPercent + '%' }}</view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="details-line">
  38. <view></view>
  39. </view>
  40. <!-- 评论 -->
  41. <view class="details-comment">
  42. <view class="details-comment-header">
  43. <view>课程评论</view>
  44. <view>共{{ total || 0 }}条评论</view>
  45. </view>
  46. <view class="details-comment-list">
  47. <view class="details-comment-list-item" v-for="(item, index) in commentList" :key="index">
  48. <view class="left">
  49. <u-avatar :src="item.createByAvatar" size="96" mode="square"></u-avatar>
  50. </view>
  51. <view class="right">
  52. <view>{{ item.createBy }}</view>
  53. <view>
  54. <u-rate :count="5" size="28" disabled="" active-color="#FFBC00" v-model="item.starLevel"> </u-rate>
  55. <text>{{ item.createTime }}</text>
  56. </view>
  57. <view>{{ item.content }}</view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="details-comment-page" v-if="total">
  62. <wyb-pagination :padding="0" :totalItems="total" :current="query.pageNum" @change="pageChange" />
  63. </view>
  64. <view class="details-comment-mine"><text>我的评论</text></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. videoIndex: 0,
  91. classesId: '',
  92. isPlay: true,
  93. query: {
  94. pageNum: 1,
  95. pageSize: 5,
  96. tabId: ''
  97. },
  98. total: 0,
  99. commentList: [],
  100. form: {
  101. tabId: '',
  102. starLevel: 0,
  103. content: ''
  104. },
  105. isApply: 1
  106. };
  107. },
  108. onLoad(page) {
  109. if (page.id) {
  110. this.getClassesDetails(page.id);
  111. this.classesId = page.id;
  112. this.query.tabId = this.classesId;
  113. this.form.tabId = this.classesId;
  114. this.isApply = page.isApply || 1;
  115. }
  116. },
  117. beforeDestroy() {
  118. this.$refs['videoBox'].recordDuration(this.videoIndex, false);
  119. },
  120. methods: {
  121. /**
  122. * 获取课程详情
  123. * @param {Object} id
  124. */
  125. getClassesDetails(id) {
  126. this.$u.api.school
  127. .getPackageCourseDetail({
  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. if (Number(this.isApply) === 1) {
  161. this.submitTimeLong(
  162. { tabId: this.videoInfo.id, playDuration: obj.playDuration, currentDuration: obj.currentDuration, duration: obj.duration },
  163. index || this.videoIndex,
  164. refresh
  165. );
  166. } else {
  167. if (refresh) {
  168. this.videoInfo = this.info.chapterList[index];
  169. this.getClassesDetails(this.classesId);
  170. }
  171. }
  172. },
  173. /**
  174. * 提交课程时长
  175. */
  176. submitTimeLong({ tabId, playDuration, currentDuration, duration }, index, refresh) {
  177. if (tabId) {
  178. this.$u.api.training
  179. .videoTimeLongApi({
  180. tabId,
  181. playDuration,
  182. currentDuration,
  183. duration
  184. })
  185. .then((res) => {
  186. if (res.code === 200) {
  187. this.videoInfo = this.info.chapterList[index];
  188. if (refresh) {
  189. this.$refs.uToast.show({
  190. title: '已记录章节时长!',
  191. type: 'success'
  192. });
  193. this.getClassesDetails(this.classesId);
  194. }
  195. } else {
  196. this.$refs.uToast.show({
  197. title: res.msg,
  198. type: 'error'
  199. });
  200. }
  201. });
  202. }
  203. },
  204. /**
  205. * 获取评论列表
  206. */
  207. getCommentList() {
  208. if (this.query.tabId) {
  209. this.$u.api.training.getClassesCommentApi(this.query).then((res) => {
  210. if (res.code === 200) {
  211. this.total = Number(res.total);
  212. this.commentList = res.rows;
  213. }
  214. });
  215. }
  216. },
  217. /**
  218. * @param {Object} e 分页触发
  219. */
  220. pageChange(e) {
  221. this.query.pageNum = e.current;
  222. this.getCommentList();
  223. },
  224. /**
  225. * 提交评论
  226. */
  227. submitCommet() {
  228. if (this.form.tabId) {
  229. if (this.form.starLevel && this.form.content) {
  230. this.$u.api.training.addClassesCommentApi(this.form).then((res) => {
  231. if (res.code === 200) {
  232. this.$refs.uToast.show({
  233. title: '评论成功!',
  234. type: 'success'
  235. });
  236. this.form.content = '';
  237. this.form.starLevel = 0;
  238. this.getCommentList();
  239. } else {
  240. this.$refs.uToast.show({
  241. title: res.msg,
  242. type: 'error'
  243. });
  244. }
  245. });
  246. }
  247. if (!this.form.starLevel) {
  248. this.$refs.uToast.show({
  249. title: '请选择星级',
  250. type: 'warning'
  251. });
  252. }
  253. if (!this.form.content) {
  254. this.$refs.uToast.show({
  255. title: '请输入评论内容',
  256. type: 'warning'
  257. });
  258. }
  259. } else {
  260. this.$refs.uToast.show({
  261. title: '未找到课程章节,无法提交评论!',
  262. type: 'warning'
  263. });
  264. }
  265. }
  266. }
  267. };
  268. </script>
  269. <style lang="scss" scoped>
  270. @import './courseDetailed.scss';
  271. </style>