detail.vue 13 KB

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