courseDetailed.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.videoInfo.videoUrl = null;
  127. this.$u.api.school
  128. .getPackageCourseDetail({
  129. id
  130. })
  131. .then((res) => {
  132. if (res.code === 200) {
  133. this.info = res.data;
  134. this.videoInfo = res.data.chapterList[this.videoIndex];
  135. this.query.pageNum = 1;
  136. this.isPlay = true;
  137. this.$nextTick(() => {
  138. this.$refs['videoBox'].loadVideo(this.videoInfo);
  139. });
  140. this.getCommentList();
  141. }
  142. });
  143. },
  144. /**
  145. * 课程章节点击
  146. * @param {Object} index
  147. */
  148. classesClick(index) {
  149. this.$refs['videoBox'].recordDuration(index, true);
  150. this.videoIndex = index;
  151. this.isPlay = false;
  152. },
  153. /**
  154. * 描述
  155. * @date 2022-10-19
  156. * @param {any} obj
  157. * @param {any} index
  158. * @returns {any}
  159. */
  160. recordDuration(obj, index, refresh = true) {
  161. if (Number(this.isApply) === 1) {
  162. this.submitTimeLong(
  163. { tabId: this.videoInfo.id, playDuration: obj.playDuration, currentDuration: obj.currentDuration, duration: obj.duration },
  164. index || this.videoIndex,
  165. refresh
  166. );
  167. } else {
  168. if (refresh) {
  169. this.videoInfo = this.info.chapterList[index];
  170. this.getClassesDetails(this.classesId);
  171. }
  172. }
  173. },
  174. /**
  175. * 提交课程时长
  176. */
  177. submitTimeLong({ tabId, playDuration, currentDuration, duration }, index, refresh) {
  178. if (tabId) {
  179. this.$u.api.training
  180. .videoTimeLongApi({
  181. tabId,
  182. playDuration,
  183. currentDuration,
  184. duration
  185. })
  186. .then((res) => {
  187. if (res.code === 200) {
  188. this.videoInfo = this.info.chapterList[index];
  189. if (refresh) {
  190. this.$refs.uToast.show({
  191. title: '已记录章节时长!',
  192. type: 'success'
  193. });
  194. this.getClassesDetails(this.classesId);
  195. }
  196. } else {
  197. this.$refs.uToast.show({
  198. title: res.msg,
  199. type: 'error'
  200. });
  201. }
  202. });
  203. }
  204. },
  205. /**
  206. * 获取评论列表
  207. */
  208. getCommentList() {
  209. if (this.query.tabId) {
  210. this.$u.api.training.getClassesCommentApi(this.query).then((res) => {
  211. if (res.code === 200) {
  212. this.total = Number(res.total);
  213. this.commentList = res.rows;
  214. }
  215. });
  216. }
  217. },
  218. /**
  219. * @param {Object} e 分页触发
  220. */
  221. pageChange(e) {
  222. this.query.pageNum = e.current;
  223. this.getCommentList();
  224. },
  225. /**
  226. * 提交评论
  227. */
  228. submitCommet() {
  229. if (this.form.tabId) {
  230. if (this.form.starLevel && this.form.content) {
  231. this.$u.api.training.addClassesCommentApi(this.form).then((res) => {
  232. if (res.code === 200) {
  233. this.$refs.uToast.show({
  234. title: '评论成功!',
  235. type: 'success'
  236. });
  237. this.form.content = '';
  238. this.form.starLevel = 0;
  239. this.getCommentList();
  240. } else {
  241. this.$refs.uToast.show({
  242. title: res.msg,
  243. type: 'error'
  244. });
  245. }
  246. });
  247. }
  248. if (!this.form.starLevel) {
  249. this.$refs.uToast.show({
  250. title: '请选择星级',
  251. type: 'warning'
  252. });
  253. }
  254. if (!this.form.content) {
  255. this.$refs.uToast.show({
  256. title: '请输入评论内容',
  257. type: 'warning'
  258. });
  259. }
  260. } else {
  261. this.$refs.uToast.show({
  262. title: '未找到课程章节,无法提交评论!',
  263. type: 'warning'
  264. });
  265. }
  266. }
  267. }
  268. };
  269. </script>
  270. <style lang="scss" scoped>
  271. @import './courseDetailed.scss';
  272. </style>