detail.vue 12 KB

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