detail.vue 16 KB

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