index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <view>
  3. <nav-bar title="课程详情"></nav-bar>
  4. <view class="videoBox" >
  5. <view >
  6. <view class="video_box" v-if="!startStatus">
  7. <image :src="$method.splitImgHost(detail.coverUrl)" style="width: 100%;height: 460rpx;"></image>
  8. <image v-if="false" class="video_play" src="/static/play.png" @click="startVideo"></image>
  9. </view>
  10. <view v-else class="video_box" style="width: 100%;height: 460rpx;">
  11. <polyv-player
  12. id="playerVideo"
  13. playerId="playerVideo"
  14. height="460rpx"
  15. :vid="vid"
  16. :showSettingBtn="true"
  17. :enablePlayGesture="true"
  18. :playbackRate="playbackRate"
  19. :isAllowSeek="isAllowSeek"
  20. :autoplay="autoplay"
  21. :startTime="startTime"
  22. @statechange="onStateChange"
  23. ></polyv-player>
  24. </view>
  25. <view style="padding:20rpx;">
  26. <view style="display: flex;">
  27. <view class="yearTag" v-if="detail.year">{{detail.year}}</view>
  28. <view class="titleTag">{{detail.goodsName}}</view>
  29. </view>
  30. <view style="display: flex;justify-content: space-between;margin-top: 13rpx;">
  31. <view class="noteTag"><image src="/static/icon/wk_icon1.png" class="wk_icon"></image>
  32. 共 <text class="blackFont">{{courseList.length}} 课程 {{detail.classHours}}</text> 学时</view>
  33. </view>
  34. </view>
  35. </view>
  36. <u-line color="#D6D6DB" />
  37. <view style="height: 80rpx;">
  38. <view><u-tabs :list="list" :item-width="itemWidth()" font-size="30" bar-width="24" :current="current" @change="change" active-color="#007AFF"></u-tabs></view>
  39. </view>
  40. </view>
  41. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current==0">
  42. <view class="content">
  43. <view v-html="detail.mobileDetailHtml" style="width: 100%;overflow: hidden;"></view>
  44. </view>
  45. </view>
  46. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current==1">
  47. <view >
  48. <view v-for="(item,index) in courseList" :key="index" >
  49. <view class="courseItemBox" >
  50. <view class="courseItem" @click="openCourse(item)">
  51. <view class="courseName">{{item.courseName}}</view>
  52. <view>
  53. <image src="/static/icon/up.png" class="icon_up" v-if="item.down"></image>
  54. <image src="/static/icon/down.png" class="icon_up" v-if="!item.down"></image>
  55. </view>
  56. </view>
  57. <view v-show="!item.down">
  58. <view v-for="(itemM,indexM) in item.menuList" :key="indexM">
  59. <courseModule :courseId="itemM.courseId" :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false" v-if="itemM.type==1" :menuItem="itemM"></courseModule>
  60. <courseChapter :courseId="itemM.courseId" :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false" v-if="itemM.type==2" :isBuy="false" :menuItem="itemM"></courseChapter>
  61. <courseSection :courseId="itemM.courseId" v-if="itemM.type==3" :isBuy="false" :menuItem="itemM"></courseSection>
  62. <u-line></u-line>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current==2">
  70. <view >
  71. <view v-for="(item,index) in freeMenuList" :key="index" >
  72. <view class="courseItemBox" >
  73. <view class="courseItem">
  74. <view class="courseName">{{item.freeExamName}}</view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="bottomBox" v-if="!hideBuyState">
  81. <view class="priceTag">¥ {{toFixed(detail.standPrice)}}</view>
  82. <view style="display: flex;color: #FFFFFF;align-items: center;">
  83. <view class="btn1" @click="addCart">加购物车</view>
  84. <view class="btn2" @click="buy">立即购买 </view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import courseModule from '@/components/course/courseModule.vue';
  91. import courseChapter from '@/components/course/courseChapter.vue';
  92. import courseSection from '@/components/course/courseSection.vue';
  93. import { mapGetters,mapMutations } from 'vuex';
  94. export default {
  95. components: {
  96. courseModule,
  97. courseChapter,
  98. courseSection
  99. },
  100. data() {
  101. return {
  102. id:0,
  103. list: [],
  104. menuIndex:[],
  105. current:0,
  106. detail:{},
  107. courseList:[],
  108. menuList:[],
  109. freeMenuList:[],
  110. startStatus:false,
  111. playbackRate: [1.0],
  112. isAllowSeek:'no',
  113. vid:'',
  114. autoplay:true,
  115. listenConfigList:[],
  116. listenSecond:0,
  117. isFirstEnter:true, //是否首次进入
  118. timer:null,
  119. businessData:{},
  120. startTime:0
  121. };
  122. },
  123. computed: { ...mapGetters(['userInfo','goodsAuditionConfigIdList','playSectionId','hideBuyState']) },
  124. onLoad(option) {
  125. this.id = option.id;
  126. this.getDetail()
  127. this.goodsCourseList()
  128. this.appCommonGoodsCourseModuleFreeExamList();
  129. },
  130. onUnload(option) {
  131. this.$store.commit('setPlaySectionId', {playSectionId :0});
  132. //移除所有的事件监听器
  133. uni.$off();
  134. },
  135. mounted() {
  136. let self = this
  137. uni.$on('getSection', item => {
  138. //播放试听
  139. self.listenSecond = 0
  140. for (var itemChild of self.listenConfigList) {
  141. if(self.playSectionId == (itemChild.sectionId || itemChild.menuId) && item.courseId == itemChild.courseId){
  142. if(itemChild.auditionMinute>0){
  143. // self.listenSecond = itemChild.auditionMinute *60 //试听秒数
  144. self.listenSecond = itemChild.auditionMinute //试听秒数 auditionMinute调整为秒单位
  145. }
  146. }
  147. }
  148. if(self.listenSecond>0){
  149. if(self.timer){
  150. clearInterval(self.timer);
  151. }
  152. if(self.vid){
  153. //切换视频
  154. var polyvPlayerContext = self.selectComponent('#playerVideo');
  155. polyvPlayerContext.changeVid(item.recordingUrl)
  156. }else{
  157. self.vid = item.recordingUrl
  158. }
  159. self.startStatus = true
  160. self.startTime = 0
  161. }else{
  162. self.$u.toast('试听配置错误');
  163. }
  164. })
  165. this.updateChapterOpen(true)
  166. },
  167. methods: {
  168. ...mapMutations(['updateChapterOpen']),
  169. itemWidth() {
  170. return (100/this.list.length)+'%'
  171. },
  172. appCommonGoodsCourseModuleFreeExamList() {
  173. this.$api.appCommonGoodsCourseModuleFreeExamList(this.id).then(res => {
  174. if(res.data.data.length) {
  175. this.freeMenuList = res.data.data;
  176. this.list = [
  177. {
  178. name: '详情'
  179. },
  180. {
  181. name: '大纲'
  182. },
  183. {
  184. name: '赠送'
  185. }
  186. ]
  187. } else {
  188. this.list = [
  189. {
  190. name: '详情'
  191. },
  192. {
  193. name: '大纲'
  194. }
  195. ]
  196. }
  197. console.log(this.list)
  198. })
  199. },
  200. courseBusiness(){
  201. this.$api.courseBusiness(this.detail.businessId).then(res => {
  202. this.businessData = res.data.data;
  203. })
  204. },
  205. toFixed(number) {
  206. if(number > 0) {
  207. return number.toFixed(2)
  208. } else {
  209. return '0.00'
  210. }
  211. },
  212. onStateChange(newstate, oldstate) {
  213. if (newstate.detail.newstate == 'playing') {
  214. //开始播放
  215. if(this.timer){
  216. clearInterval(this.timer);
  217. }
  218. this.timer = setInterval(this.timeEvent, 1500);//定时器
  219. }
  220. },
  221. closePlay(){
  222. this.$store.commit('setPlaySectionId', {playSectionId :0});
  223. this.vid = ""
  224. this.startStatus = false
  225. },
  226. timeEvent() {
  227. let self = this
  228. var polyvPlayerContext = this.selectComponent('#playerVideo');
  229. if (polyvPlayerContext != null) {
  230. let PlayCurrentTime = polyvPlayerContext.getCurrentTime();
  231. if(PlayCurrentTime>=this.listenSecond){
  232. polyvPlayerContext.stop();
  233. polyvPlayerContext.exitFullScreen();
  234. clearInterval(this.timer);
  235. this.timer = null
  236. uni.showModal({
  237. title: '提示',
  238. content: '试听结束,购买课程可学习全部',
  239. showCancel:false,
  240. success: function(resst) {
  241. self.closePlay()
  242. }
  243. });
  244. }
  245. }
  246. },
  247. openCourse(item){
  248. item.down = !item.down
  249. if(!item.down&&item.menuList.length==0){
  250. this.getMenuList(item)
  251. }
  252. },
  253. addShopCart() {
  254. let self = this
  255. this.$api.addCart({goodsId:this.id}).then(res => {
  256. if(res.data.code==200){
  257. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  258. uni.showToast({
  259. title: '添加成功'
  260. });
  261. }else{
  262. this.$u.toast(res.data.msg);
  263. }
  264. });
  265. },
  266. goodsCourseList() {
  267. let self = this
  268. this.$api.goodsCourseList(this.id).then(res => {
  269. if(res.data.code==200){
  270. for(let i=0;i<res.data.rows.length;i++){
  271. let item = res.data.rows[i]
  272. item.down = true
  273. item.menuList = []
  274. }
  275. self.courseList = res.data.rows;
  276. this.getFirstCourse();
  277. }
  278. });
  279. },
  280. /**
  281. * 获取第一个有模块或者章的课程
  282. */
  283. async getFirstCourse() {
  284. for(let i = 0; i < this.courseList.length; i++) {
  285. let menuIndexOrFalse = await this.getCourseMenus(this.courseList[i]);
  286. if(menuIndexOrFalse !== false) {
  287. this.menuIndex = [i,menuIndexOrFalse]
  288. this.openCourse(this.courseList[i])
  289. break
  290. }
  291. }
  292. },
  293. getCourseMenus(item) {
  294. return new Promise(resolve => {
  295. this.$api.menuList({courseId:item.courseId}).then(res => {
  296. if(res.data.code==200){
  297. for(let i=0;i<res.data.rows.length;i++){
  298. if(res.data.rows[i].type == 1 || res.data.rows[i].type == 2) {
  299. resolve(i)
  300. break;
  301. }
  302. }
  303. }
  304. });
  305. })
  306. },
  307. getMenuList(item) {
  308. let self = this
  309. this.$api.menuList({courseId:item.courseId}).then(res => {
  310. if(res.data.code==200){
  311. for(let i=0;i<res.data.rows.length;i++){
  312. let item = res.data.rows[i]
  313. item.down = true
  314. item.id = item.menuId
  315. item.name = item.menuName
  316. if(item.type==3){
  317. //判断是否试听
  318. item.tryListen = false
  319. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  320. item.tryListen = true
  321. }
  322. }
  323. }
  324. item.menuList = res.data.rows
  325. }
  326. });
  327. },
  328. getDetail() {
  329. let self = this
  330. let sectionIdList = []
  331. this.$api.commonGoodsDetail(this.id).then(res => {
  332. if(res.data.code==200){
  333. if(res.data.data.mobileDetailHtml){
  334. res.data.data.mobileDetailHtml = res.data.data.mobileDetailHtml.replace(/<img/gi,'<img style="max-width:100%;"')
  335. }
  336. self.detail = res.data.data
  337. this.courseBusiness();
  338. if(self.detail.goodsAuditionConfig){
  339. self.listenConfigList = JSON.parse(self.detail.goodsAuditionConfig)
  340. for (var itemChild of self.listenConfigList) {
  341. sectionIdList.push(itemChild.sectionId)//存储试听节ID
  342. }
  343. self.$store.commit('setGoodsAuditionConfigIdList', {goodsAuditionConfigIdList:sectionIdList});
  344. }
  345. }
  346. });
  347. },
  348. buy(){
  349. if(this.$method.isGoLogin()){
  350. return
  351. }
  352. this.$navTo.togo('/pages2/order/confirm_list?id='+this.id);
  353. },
  354. addCart(){
  355. if(this.$method.isGoLogin()){
  356. return
  357. }
  358. this.addShopCart()
  359. },
  360. open(item){
  361. item.showChildren = !item.showChildren
  362. },
  363. change(index){
  364. this.current = index;
  365. }
  366. }
  367. };
  368. </script>
  369. <style >
  370. page{
  371. background-color: #EAEEF1;
  372. }
  373. </style>
  374. <style scope>
  375. .video_t2 {
  376. font-size: 24rpx;
  377. font-family: PingFang SC;
  378. font-weight: 500;
  379. color: #666666;
  380. }
  381. .video_t1 {
  382. height: 80rpx;
  383. color: #333333;
  384. line-height: 80rpx;
  385. font-size: 30rpx;
  386. font-family: PingFang SC;
  387. font-weight: bold;
  388. color: #333333;
  389. overflow: hidden;
  390. text-overflow:ellipsis;
  391. white-space: nowrap;
  392. }
  393. .video_t1_t {
  394. display: flex;
  395. flex-direction: column;
  396. height: 80rpx;
  397. color: #333333;
  398. text-align: center;
  399. align-items: center;
  400. border-left: solid 1px #d6d6db;
  401. }
  402. .video_play {
  403. position: absolute;
  404. width: 95rpx;
  405. height: 95rpx;
  406. top: 0;
  407. left: 0;
  408. right: 0;
  409. bottom: 0;
  410. margin: auto;
  411. }
  412. .video_box {
  413. position: relative;
  414. }
  415. .courseName{
  416. white-space:nowrap;
  417. overflow:hidden;
  418. text-overflow:ellipsis;
  419. }
  420. .videoBox{
  421. background-color: #FFFFFF;
  422. width: 100%;
  423. /* height: 680rpx; */
  424. z-index: 999;
  425. }
  426. .icon_up{
  427. width: 32rpx;
  428. height: 32rpx;
  429. }
  430. .contentBox{
  431. }
  432. .courseItemBox{
  433. background: #FFFFFF;
  434. border-radius: 16rpx;
  435. padding: 0 10rpx;
  436. margin-bottom: 20rpx;
  437. }
  438. .courseItem{
  439. height: 80rpx;
  440. color: #333333;
  441. font-size: 32rpx;
  442. line-height: 80rpx;
  443. font-weight: bold;
  444. display: flex;
  445. justify-content: space-between;
  446. }
  447. .content{
  448. background-color: #FFFFFF;
  449. width: 100%;
  450. }
  451. .btn2{
  452. width: 200rpx;
  453. height: 64rpx;
  454. background: linear-gradient(0deg, #FFB102, #FD644F);
  455. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  456. border-radius: 32rpx;
  457. line-height: 64rpx;
  458. text-align: center;
  459. }
  460. .btn1{
  461. width: 200rpx;
  462. height: 64rpx;
  463. background: linear-gradient(0deg, #015EEA, #00C0FA);
  464. border-radius: 32rpx;
  465. line-height: 64rpx;
  466. text-align: center;
  467. margin-right: 20rpx;
  468. }
  469. .bottomBox{
  470. position: fixed;
  471. bottom: 0;
  472. width: 100%;
  473. left: 0;
  474. height:98rpx ;
  475. background-color: #FFFFFF;
  476. display: flex;
  477. justify-content: space-between;
  478. align-items: center;
  479. padding: 0 30rpx;
  480. }
  481. .blackFont{
  482. color: #333333;
  483. margin: 0 4rpx;
  484. }
  485. .wk_icon{
  486. width: 24rpx;
  487. height: 24rpx;
  488. margin-right: 12rpx;
  489. }
  490. .noteTag{
  491. ont-size: 24rpx;
  492. font-family: PingFang SC;
  493. font-weight: 500;
  494. color: #999999;
  495. align-items: center;
  496. }
  497. .priceTag{
  498. font-size: 30rpx;
  499. font-family: PingFang SC;
  500. font-weight: bold;
  501. color: #FF2D55;
  502. }
  503. .titleTag{
  504. font-size: 32rpx;
  505. font-weight: bold;
  506. color: #333333;
  507. margin-left: 8rpx;
  508. }
  509. .yearTag{
  510. width: 80rpx;
  511. height: 32rpx;
  512. background: #EBF5FF;
  513. border: 2rpx solid #007AFF;
  514. border-radius: 16rpx;
  515. font-size: 24rpx;
  516. color: #007AFF;
  517. text-align: center;
  518. line-height: 32rpx;
  519. }
  520. .itemBox{
  521. background: #FFFFFF;
  522. box-shadow: 0rpx 10rpx 9rpx 1rpx rgba(165, 196, 239, 0.1);
  523. border-radius: 24rpx;
  524. width: 100%;
  525. padding: 20rpx;
  526. margin-bottom: 20rpx;
  527. }
  528. </style>