detail.vue 16 KB

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