index.vue 14 KB

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