detail.vue 12 KB

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