detail.vue 14 KB

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