detail.vue 17 KB

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