courseDetailed.vue 7.4 KB

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