courseSection.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <view style="display: flex;justify-content: space-between;align-items: center;" @click="getVideo">
  3. <view style="display: flex;justify-content: space-between;margin: 20rpx 0;width: 100%;">
  4. <view style="display: flex;align-items: center;flex:1;">
  5. <view class="tag tagColor1" v-if="menuItem.sectionType==1">录播</view>
  6. <view class="tag tagColor2" v-if="menuItem.sectionType==2">直播</view>
  7. <view class="tag tagColor3" v-if="menuItem.sectionType==3">回放</view>
  8. <view class="t_content">
  9. <view v-if="menuItem.sectionType==1" :class="playSectionId==newId && playNextId==playId?'color1':''">{{menuItem.name || ''}}</view>
  10. <view v-if="menuItem.sectionType==2" :class="playSectionId==newId && playNextId==playId?'color2':''">{{menuItem.name || ''}}</view>
  11. <view v-if="menuItem.sectionType==3" :class="playSectionId==newId && playNextId==playId?'color3':''">{{menuItem.name || ''}}</view>
  12. <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.sectionType==2 && menuItem.liveStartTime">
  13. <view v-if="menuItem.liveStartTime>nowTime">
  14. <text>{{$method.timestampToTime(menuItem.liveStartTime, isDay =false)}}</text>-
  15. <text>{{$method.timestampToTime(menuItem.liveEndTime, isDay =false)}}</text>
  16. </view>
  17. <!-- <view v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
  18. <text>直播中</text>
  19. </view>
  20. <view v-if="menuItem.liveEndTime<nowTime">
  21. <text>回放</text>
  22. </view> -->
  23. </view>
  24. </view>
  25. <view v-if="menuItem.sectionType==null">{{menuItem.name || ''}}</view>
  26. </view>
  27. <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.liveStartTime && menuItem.sectionType != 3">
  28. <view class="tagWillPlay" v-if="menuItem.liveStartTime>nowTime">
  29. <text>待开播</text>
  30. </view>
  31. <view class="tagPlaying" v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
  32. <text>直播中</text>
  33. </view>
  34. <view class="tagPlayed" v-if="menuItem.liveEndTime<nowTime">
  35. <text>已结束</text>
  36. </view>
  37. </view>
  38. <view v-if="(isRebuild||menuItem.rebuild>0)" class="tagRe">待重修</view>
  39. <view v-else>
  40. <view v-if="menuItem.learning==1" class="tagGreen">已看完</view>
  41. </view>
  42. </view>
  43. <view v-if="menuItem.tryListen&&!isBuy" class="tryBox">
  44. 试看
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { mapGetters } from 'vuex';
  50. import eventHub from '@/common/eventHub.js'
  51. export default {
  52. name: 'courseSection',
  53. props: {
  54. orderGoodsId:{
  55. default:0
  56. },
  57. preItem:{
  58. default:undefined,
  59. },
  60. learningOrder:{ //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
  61. type:Number,
  62. default:0
  63. },
  64. courseId: {
  65. type: Number,
  66. default: 0
  67. },
  68. goodsId: {
  69. type: Number,
  70. default: 0
  71. },
  72. menuItem: {
  73. type: Object,
  74. default: {}
  75. },
  76. isBuy: {
  77. type: Boolean,
  78. default: false
  79. },
  80. levelId: {
  81. type: String,
  82. default: ""
  83. },
  84. isRebuild: {
  85. type: Boolean,
  86. default: false
  87. },
  88. gradeId: {
  89. type: Number,
  90. default: 0
  91. },
  92. nextMenuItem: {
  93. type: Object,
  94. default: {}
  95. },
  96. sectionMaxNum:{
  97. default:undefined,
  98. },
  99. },
  100. watch:{
  101. menuItem(val) {
  102. console.log(val,'val')
  103. }
  104. },
  105. data() {
  106. return {
  107. nowTime:0,
  108. newId:0,
  109. playId:'',
  110. clickLock:false, //点击锁,防止连续点击多次
  111. };
  112. },
  113. onLoad() {
  114. },
  115. created() {
  116. },
  117. mounted() {
  118. this.nowTime = Number(new Date().getTime()/1000).toFixed(0)
  119. this.newId= this.menuItem.sectionId>0?this.menuItem.sectionId:this.menuItem.menuId
  120. console.log(this.isRebuild)
  121. console.log(this.nextMenuItem,'nextMenuItem')
  122. console.log(this.menuItem,'this.menuItem')
  123. let moduleId = this.menuItem.moduleId || 0;
  124. let chapterId = this.menuItem.chapterId || 0;
  125. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  126. let playNextId = `moduleId${moduleId}chapterId${chapterId}sectionId${sectionId}${this.isRebuild?'isRebuild':''}`;
  127. this.playId = playNextId;
  128. uni.$off('playNext'+playNextId) //绑定前先移除之前的事件
  129. uni.$once('playNext'+playNextId, (data) => {
  130. //到时会触发每个节的监听事件,只允许当前节的接收
  131. let self = this
  132. if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId) && data.fromRebuild){ // fromRebuild 来自重修目录的点击才弹出播放下一节
  133. //重修存在下一节
  134. uni.showModal({
  135. title: '提示',
  136. content: '是否播放下一节',
  137. success: function (res) {
  138. if (res.confirm) {
  139. console.log('用户点击确定');
  140. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  141. //设置播放的节ID
  142. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  143. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  144. let ids = self.levelId.split('-');
  145. ids[2] = nextId
  146. uni.$emit('levelId', ids.join('-'))
  147. uni.$emit('getSection', self.nextMenuItem)
  148. self.$emit('playEnd',{isRebuild:self.isRebuild})
  149. // uni.$off('playend')
  150. // uni.$on('playend',res => {
  151. // console.log('playend2')
  152. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  153. // })
  154. } else {
  155. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  156. //设置播放的节ID
  157. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  158. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  159. let ids = self.levelId.split('-');
  160. ids[2] = nextId
  161. self.$emit('playEnd',{isRebuild:self.isRebuild})
  162. }
  163. }
  164. });
  165. } else {
  166. this.$emit('playEnd',{isRebuild:this.isRebuild})
  167. }
  168. });
  169. },
  170. methods: {
  171. studyRecordMenuAllList() {
  172. return new Promise(resolve => {
  173. this.$api.studyRecordMenuAllList({
  174. courseId:this.courseId,
  175. gradeId:this.gradeId,
  176. goodsId:this.goodsId
  177. }).then(res => {
  178. if(res.data.code == 200) {
  179. resolve(res.data.data)
  180. }
  181. })
  182. })
  183. },
  184. gradeCheckGoodsStudy() {
  185. let moduleId = this.menuItem.moduleId || 0;
  186. let chapterId = this.menuItem.chapterId || 0;
  187. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  188. return new Promise(resolve => {
  189. this.$api.gradeCheckGoodsStudy({
  190. goodsId:this.goodsId,
  191. gradeId:this.gradeId,
  192. moduleId:this.menuItem.moduleId || 0,
  193. chapterId:this.menuItem.chapterId || 0,
  194. sectionId:this.menuItem.sectionId || this.menuItem.menuId
  195. }).then( res => {
  196. resolve(res.data.data)
  197. })
  198. })
  199. },
  200. goodsTodayStudySectionNum() {
  201. return new Promise(resolve => {
  202. this.$api.goodsTodayStudySectionNum({goodsId:this.goodsId,gradeId:this.gradeId}).then(res => {
  203. if(res.data.code == 200) {
  204. resolve(res.data.data)
  205. }
  206. })
  207. })
  208. },
  209. async getVideo(){
  210. if(this.clickLock) {
  211. return;
  212. }
  213. this.clickLock = true;
  214. if(this.learningOrder == 2 && !this.menuItem.isRebuild) { //要按从头到尾顺序学习, 且不是重修课程
  215. if(this.preItem) {
  216. let rows = await this.studyRecordMenuAllList();
  217. let newRows = [];
  218. for(let i = 0; i < rows.length; i++ ) {
  219. let moduleTrue = rows[i].moduleId == this.menuItem.moduleId || rows[i].moduleId == 0
  220. let chapterTrue = rows[i].chapterId == this.menuItem.chapterId || rows[i].chapterId == 0;
  221. let sectionTrue = (rows[i].sectionId == this.menuItem.sectionId) || (rows[i].sectionId == this.menuItem.menuId);
  222. if(moduleTrue && chapterTrue && sectionTrue) {
  223. break;
  224. } else {
  225. if(rows[i].sectionType != 2) {
  226. newRows.push(rows[i])
  227. }
  228. }
  229. }
  230. console.log(newRows)
  231. let isAllLearn = newRows.every(item => {
  232. return item.studyStatus == 1;
  233. })
  234. if(isAllLearn) {
  235. this.playVideo();
  236. } else {
  237. uni.showToast({
  238. icon:'none',
  239. title:'请按顺序学习视频课程'
  240. })
  241. }
  242. // if(this.preItem.menuType == 3) { //上一个是节
  243. // if(this.preItem.learning == 1) { //上一节学完
  244. // this.playVideo();
  245. // } else {
  246. // uni.showToast({
  247. // icon:'none',
  248. // title:'请按顺序学习视频课程'
  249. // })
  250. // }
  251. // } else if(this.preItem.menuType == 2) { //上一个是章
  252. // this.$api.reSectionList({chapterId: this.preItem.menuId || this.preItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.preItem.moduleId || 0}).then(res => {
  253. // if(res.data.code==200){
  254. // let lastItem = res.data.data[res.data.data.length -1];
  255. // if(lastItem.learning == 1) {
  256. // this.playVideo();
  257. // } else {
  258. // uni.showToast({
  259. // icon:'none',
  260. // title:'请按顺序学习视频课程'
  261. // })
  262. // }
  263. // }
  264. // });
  265. // } else if(this.preItem.menuType == 1) { //上一个是模块
  266. // this.$api.reChapterList({moduleId:this.preItem.menuId,gradeId:this.gradeId,courseId:this.courseId}).then(res => {
  267. // if(res.data.code==200){
  268. // let lastChapterItem = res.data.data[res.data.data.length -1];
  269. // this.$api.reSectionList({chapterId:lastChapterItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.menuItem.menuId || this.menuItem.moduleId}).then(res => {
  270. // if(res.data.code==200){
  271. // let lastSectionItem = res.data.data[res.data.data.length -1];
  272. // if(lastSectionItem.learning == 1) {
  273. // this.playVideo();
  274. // } else {
  275. // uni.showToast({
  276. // icon:'none',
  277. // title:'请按顺序学习视频课程'
  278. // })
  279. // }
  280. // }
  281. // });
  282. // }
  283. // });
  284. // }
  285. } else { //第一章第一节
  286. this.playVideo();
  287. }
  288. } else {
  289. this.playVideo();
  290. }
  291. setTimeout(() => {
  292. this.clickLock = false;
  293. },3000)
  294. },
  295. async playVideo() {
  296. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  297. //录播
  298. if(!this.isBuy){
  299. //非购买
  300. if(!this.menuItem.tryListen){
  301. //不允许试听
  302. this.clickLock = false;
  303. return
  304. } else {
  305. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  306. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  307. this.menuItem.courseId = this.courseId;
  308. uni.$emit('getSection', this.menuItem)
  309. return;
  310. }
  311. }
  312. let learnNum = await this.goodsTodayStudySectionNum()
  313. let hasLearn = await this.gradeCheckGoodsStudy();
  314. console.log(this.sectionMaxNum,'this.sectionMaxNum')
  315. console.log(learnNum,'learnNum')
  316. if(this.sectionMaxNum > 0) {
  317. if(learnNum >= this.sectionMaxNum && !hasLearn) {
  318. uni.showToast({
  319. icon:'none',
  320. title:`每天最多学习${this.sectionMaxNum}节`
  321. })
  322. this.clickLock = false;
  323. return;
  324. }
  325. }
  326. if(!this.menuItem.recordingUrl){
  327. uni.showToast({
  328. title: '暂无播放地址数据',
  329. icon: 'error'
  330. });
  331. this.clickLock = false;
  332. return;
  333. }
  334. /* if(this.playSectionId==this.newId){
  335. //切换为同一节
  336. return
  337. } */
  338. if(this.playSectionId>0){
  339. //切换视频
  340. let oldSectionId = this.playSectionId
  341. uni.$emit('changeSection', oldSectionId)
  342. }
  343. //设置播放的节ID
  344. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  345. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  346. this.$store.commit('updatePlayNextId',this.playId)
  347. uni.$emit('levelId', this.levelId)
  348. uni.$emit('getSection', this.menuItem)
  349. uni.$emit('isRebuild',this.isRebuild)
  350. console.log(this.menuItem,'menuItem')
  351. // uni.$off('playend')
  352. // uni.$on('playend',res => {
  353. // console.log('playend2')
  354. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  355. // })
  356. console.log(999)
  357. }
  358. if(this.menuItem.sectionType==2){
  359. //直播
  360. if(!this.isBuy){
  361. //非购买
  362. this.clickLock = false;
  363. return
  364. }
  365. let learnNum = await this.goodsTodayStudySectionNum()
  366. let hasLearn = await this.gradeCheckGoodsStudy();
  367. console.log(this.sectionMaxNum,'this.sectionMaxNum')
  368. console.log(learnNum,'learnNum')
  369. if(this.sectionMaxNum > 0) {
  370. if(learnNum >= this.sectionMaxNum && !hasLearn) {
  371. uni.showToast({
  372. icon:'none',
  373. title:`每天最多学习${this.sectionMaxNum}节`
  374. })
  375. this.clickLock = false;
  376. return;
  377. }
  378. }
  379. if(!this.menuItem.liveUrl){
  380. uni.showToast({
  381. title: '暂无直播地址数据',
  382. icon: 'error'
  383. });
  384. }
  385. if(this.playSectionId==this.newId){
  386. //切换为同一频道
  387. this.clickLock = false;
  388. return
  389. }
  390. //设置播放的节ID
  391. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  392. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  393. this.$store.commit('updatePlayNextId',this.playId)
  394. uni.$emit('levelId', this.levelId)
  395. uni.$emit('getChannel', this.menuItem)
  396. uni.$emit('isRebuild',this.isRebuild)
  397. console.log(this.menuItem,'menuItem')
  398. // uni.$off('playend')
  399. // uni.$on('playend',res => {
  400. // console.log('playend1')
  401. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  402. // })
  403. console.log(888)
  404. }
  405. }
  406. },
  407. computed: { ...mapGetters(['playSectionId','playChannelId','playVID','playNextId']) }
  408. };
  409. </script>
  410. <style scoped lang="scss">
  411. .tagGreen{
  412. width: 80rpx;
  413. height: 28rpx;
  414. background: #34C759;
  415. border-radius: 8rpx;
  416. font-size: 20rpx;
  417. color: #FFFFFF;
  418. text-align: center;
  419. }
  420. .tagWillPlay{
  421. width: 80rpx;
  422. height: 28rpx;
  423. background: #EBF4FF;
  424. border-radius: 8rpx;
  425. font-size: 20rpx;
  426. color: #007AFF;
  427. text-align: center;
  428. }
  429. .tagPlaying{
  430. width: 80rpx;
  431. height: 28rpx;
  432. background: #FFF7EB;
  433. border-radius: 8rpx;
  434. font-size: 20rpx;
  435. color: #FF9500;
  436. text-align: center;
  437. }
  438. .tagPlayed{
  439. width: 80rpx;
  440. height: 28rpx;
  441. background: #EEEEEE;
  442. border-radius: 8rpx;
  443. font-size: 20rpx;
  444. color: #666666;
  445. text-align: center;
  446. }
  447. .tagRe{
  448. width: 80rpx;
  449. height: 28rpx;
  450. background: #FF3B30;
  451. border-radius: 8rpx;
  452. font-size: 20rpx;
  453. color: #FFFFFF;
  454. text-align: center;
  455. }
  456. .tryBox{
  457. width: 96rpx;
  458. height: 48rpx;
  459. background: #007AFF;
  460. border-radius: 24rpx;
  461. color: #FFFFFF;
  462. font-size: 30rpx;
  463. line-height: 48rpx;
  464. text-align: center;
  465. }
  466. .icon_up{
  467. width: 24rpx;
  468. height: 24rpx;
  469. }
  470. .t_content3{
  471. color: #007AFF;
  472. }
  473. .t_content2{
  474. color: #007AFF;
  475. }
  476. .t_content1{
  477. color: #007AFF;
  478. }
  479. .t_content{
  480. font-size: 30rpx;
  481. margin-left: 10rpx;
  482. color: #666666;
  483. flex:1;
  484. }
  485. .tagColor3{
  486. border: 2rpx solid #FF9500;
  487. color: #FF9500;
  488. }
  489. .tagColor2{
  490. border: 2rpx solid #FF3B30;
  491. color: #FF3B30;
  492. }
  493. .tagColor1{
  494. border: 2rpx solid #007AFF;
  495. color: #007AFF;
  496. }
  497. .color3{
  498. color: #FF9500;
  499. }
  500. .color2{
  501. color: #FF3B30;
  502. }
  503. .color1{
  504. color: #007AFF;
  505. }
  506. .tag{
  507. border-radius: 8rpx;
  508. font-size: 20rpx;
  509. padding: 5rpx;
  510. }
  511. </style>