detail.vue 11 KB

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