detail.vue 17 KB

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