detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view>
  3. <view class="videoBox" >
  4. <view >
  5. <view class="video_box" v-if="!startStatus">
  6. <image :src="$method.splitImgHost(detail.coverUrl)" style="width: 100%;height: 460rpx;"></image>
  7. <image v-if="false" class="video_play" src="/static/play.png" @click="startVideo"></image>
  8. </view>
  9. <view v-else class="video_box" style="width: 100%;height: 460rpx;">
  10. <polyv-player
  11. id="playerVideo"
  12. playerId="playerVideo"
  13. height="460rpx"
  14. :vid="vid"
  15. :showSettingBtn="true"
  16. :enablePlayGesture="true"
  17. :playbackRate="playbackRate"
  18. :isAllowSeek="isAllowSeek"
  19. :autoplay="autoplay"
  20. :startTime="startTime"
  21. @statechange="onStateChange"
  22. ></polyv-player>
  23. </view>
  24. <view style="padding:20rpx;height: 120rpx;">
  25. <view style="display: flex;">
  26. <view class="yearTag" v-if="detail.year">{{detail.year}}</view>
  27. <view class="titleTag">{{detail.goodsName}}</view>
  28. </view>
  29. <view style="display: flex;justify-content: space-between;margin-top: 13rpx;">
  30. <view class="noteTag"><image src="/static/icon/wk_icon1.png" class="wk_icon"></image>
  31. 共 <text class="blackFont">{{detail.subjectNum}} 科 {{detail.classHours}}</text> 学时</view>
  32. </view>
  33. </view>
  34. </view>
  35. <u-line color="#D6D6DB" />
  36. <view style="height: 80rpx;">
  37. <view style="width: 160px;margin: 0 auto;"><u-tabs :list="list" item-width="150" font-size="24" bar-width="110" :current="current" @change="change" active-color="#007AFF"></u-tabs></view>
  38. </view>
  39. </view>
  40. <view style="padding: 20rpx;position: relative;top: 680rpx;" v-show="current==0">
  41. <view class="content">
  42. <view v-html="detail.mobileDetailHtml" style="width: 100%;overflow: hidden;"></view>
  43. </view>
  44. </view>
  45. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;top: 680rpx;" v-show="current==1">
  46. <view >
  47. <view v-for="(item,index) in courseList" :key="index" >
  48. <view class="courseItemBox" >
  49. <view class="courseItem" @click="openCourse(item)">
  50. <view class="courseName">{{item.courseName}}</view>
  51. <view>
  52. <image src="/static/icon/up.png" class="icon_up" v-if="item.down"></image>
  53. <image src="/static/icon/down.png" class="icon_up" v-if="!item.down"></image>
  54. </view>
  55. </view>
  56. <view v-show="!item.down">
  57. <view v-for="(itemM,indexM) in menuList" :key="indexM">
  58. <courseModule v-if="itemM.type==1" :menuItem="itemM"></courseModule>
  59. <courseChapter v-if="itemM.type==2" :isBuy="false" :menuItem="itemM"></courseChapter>
  60. <courseSection v-if="itemM.type==3" :isBuy="false" :menuItem="itemM"></courseSection>
  61. <u-line></u-line>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="bottomBox">
  69. <view class="priceTag">¥ {{detail.standPrice}}</view>
  70. <view style="display: flex;color: #FFFFFF;align-items: center;">
  71. <view class="btn1" @click="addCart">加购物车</view>
  72. <view class="btn2" @click="buy">立即购买 </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import courseModule from '@/components/course/courseModule.vue';
  79. import courseChapter from '@/components/course/courseChapter.vue';
  80. import courseSection from '@/components/course/courseSection.vue';
  81. import { mapGetters } from 'vuex';
  82. export default {
  83. components: {
  84. courseModule,
  85. courseChapter,
  86. courseSection
  87. },
  88. data() {
  89. return {
  90. id:0,
  91. list: [
  92. {
  93. name: '详情'
  94. },
  95. {
  96. name: '大纲'
  97. }
  98. ],
  99. current:0,
  100. detail:{},
  101. courseList:[],
  102. menuList:[],
  103. startStatus:false,
  104. playbackRate: [1.0],
  105. isAllowSeek:'no',
  106. vid:'',
  107. autoplay:true,
  108. listenConfigList:[],
  109. listenSecond:0,
  110. timer:null,
  111. startTime:0
  112. };
  113. },
  114. computed: { ...mapGetters(['userInfo','goodsAuditionConfigIdList','playSectionId']) },
  115. onLoad(option) {
  116. this.id = option.id;
  117. this.getDetail()
  118. this.goodsCourseList()
  119. },
  120. onUnload(option) {
  121. this.$store.commit('setPlaySectionId', {playSectionId :0});
  122. //移除所有的事件监听器
  123. uni.$off();
  124. },
  125. mounted() {
  126. let self = this
  127. uni.$on('getSection', item => {
  128. //播放试听
  129. self.listenSecond = 0
  130. for (var itemChild of self.listenConfigList) {
  131. if(itemChild.sectionId==self.playSectionId){
  132. if(itemChild.auditionMinute>0){
  133. self.listenSecond = itemChild.auditionMinute *60 //试听秒数
  134. }
  135. }
  136. }
  137. if(self.listenSecond>0){
  138. if(self.timer){
  139. clearInterval(self.timer);
  140. }
  141. if(self.vid){
  142. //切换视频
  143. var polyvPlayerContext = self.selectComponent('#playerVideo');
  144. polyvPlayerContext.changeVid(item.recordingUrl)
  145. }else{
  146. self.vid = item.recordingUrl
  147. }
  148. self.startStatus = true
  149. self.startTime = 0
  150. }else{
  151. self.$u.toast('试听配置错误');
  152. }
  153. })
  154. },
  155. methods: {
  156. onStateChange(newstate, oldstate) {
  157. if (newstate.detail.newstate == 'playing') {
  158. //开始播放
  159. if(this.timer){
  160. clearInterval(this.timer);
  161. }
  162. this.timer = setInterval(this.timeEvent, 1500);//定时器
  163. }
  164. },
  165. closePlay(){
  166. this.$store.commit('setPlaySectionId', {playSectionId :0});
  167. this.vid = ""
  168. this.startStatus = false
  169. },
  170. timeEvent() {
  171. let self = this
  172. var polyvPlayerContext = this.selectComponent('#playerVideo');
  173. if (polyvPlayerContext != null) {
  174. let PlayCurrentTime = polyvPlayerContext.getCurrentTime();
  175. if(PlayCurrentTime>=this.listenSecond){
  176. polyvPlayerContext.stop();
  177. polyvPlayerContext.exitFullScreen();
  178. clearInterval(this.timer);
  179. this.timer = null
  180. uni.showModal({
  181. title: '提示',
  182. content: '试听结束,购买课程可学习全部',
  183. showCancel:false,
  184. success: function(resst) {
  185. self.closePlay()
  186. }
  187. });
  188. }
  189. }
  190. },
  191. openCourse(item){
  192. item.down = !item.down
  193. if(!item.down&&this.menuList.length==0){
  194. this.getMenuList(item.courseId)
  195. }
  196. },
  197. addShopCart() {
  198. let self = this
  199. this.$api.addCart({goodsId:this.id}).then(res => {
  200. if(res.data.code==200){
  201. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  202. uni.showToast({
  203. title: '添加成功'
  204. });
  205. }else{
  206. this.$u.toast(res.data.msg);
  207. }
  208. });
  209. },
  210. goodsCourseList() {
  211. let self = this
  212. this.$api.goodsCourseList(this.id).then(res => {
  213. if(res.data.code==200){
  214. for(let i=0;i<res.data.rows.length;i++){
  215. let item = res.data.rows[i]
  216. item.down = true
  217. }
  218. self.courseList = res.data.rows
  219. }
  220. });
  221. },
  222. getMenuList(courseId) {
  223. let self = this
  224. this.$api.menuList({courseId:courseId}).then(res => {
  225. if(res.data.code==200){
  226. for(let i=0;i<res.data.rows.length;i++){
  227. let item = res.data.rows[i]
  228. item.down = true
  229. item.id = item.menuId
  230. item.name = item.menuName
  231. if(item.type==3){
  232. //判断是否试听
  233. item.tryListen = false
  234. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  235. item.tryListen = true
  236. }
  237. }
  238. }
  239. self.menuList = res.data.rows
  240. }
  241. });
  242. },
  243. getDetail() {
  244. let self = this
  245. let sectionIdList = []
  246. this.$api.commonGoodsDetail(this.id).then(res => {
  247. if(res.data.code==200){
  248. if(res.data.data.mobileDetailHtml){
  249. res.data.data.mobileDetailHtml = res.data.data.mobileDetailHtml.replace(/<img/gi,'<img style="max-width:100%;"')
  250. }
  251. self.detail = res.data.data
  252. if(self.detail.goodsAuditionConfig){
  253. self.listenConfigList = JSON.parse(self.detail.goodsAuditionConfig)
  254. for (var itemChild of self.listenConfigList) {
  255. sectionIdList.push(itemChild.sectionId)//存储试听节ID
  256. }
  257. self.$store.commit('setGoodsAuditionConfigIdList', {goodsAuditionConfigIdList:sectionIdList});
  258. }
  259. }
  260. });
  261. },
  262. buy(){
  263. if(this.$method.isGoLogin()){
  264. return
  265. }
  266. this.$navTo.togo('/pages2/order/confirm_list?id='+this.id);
  267. },
  268. addCart(){
  269. if(this.$method.isGoLogin()){
  270. return
  271. }
  272. this.addShopCart()
  273. },
  274. open(item){
  275. item.showChildren = !item.showChildren
  276. },
  277. change(index){
  278. this.current = index;
  279. }
  280. }
  281. };
  282. </script>
  283. <style >
  284. page{
  285. background-color: #EAEEF1;
  286. }
  287. </style>
  288. <style scope>
  289. .video_t2 {
  290. font-size: 24rpx;
  291. font-family: PingFang SC;
  292. font-weight: 500;
  293. color: #666666;
  294. }
  295. .video_t1 {
  296. height: 80rpx;
  297. color: #333333;
  298. line-height: 80rpx;
  299. font-size: 30rpx;
  300. font-family: PingFang SC;
  301. font-weight: bold;
  302. color: #333333;
  303. overflow: hidden;
  304. text-overflow:ellipsis;
  305. white-space: nowrap;
  306. }
  307. .video_t1_t {
  308. display: flex;
  309. flex-direction: column;
  310. height: 80rpx;
  311. color: #333333;
  312. text-align: center;
  313. align-items: center;
  314. border-left: solid 1px #d6d6db;
  315. }
  316. .video_play {
  317. position: absolute;
  318. width: 95rpx;
  319. height: 95rpx;
  320. top: 0;
  321. left: 0;
  322. right: 0;
  323. bottom: 0;
  324. margin: auto;
  325. }
  326. .video_box {
  327. position: relative;
  328. }
  329. .courseName{
  330. white-space:nowrap;
  331. overflow:hidden;
  332. text-overflow:ellipsis;
  333. }
  334. .videoBox{
  335. position: fixed;
  336. background-color: #FFFFFF;
  337. width: 100%;
  338. height: 680rpx;
  339. z-index: 999;
  340. }
  341. .icon_up{
  342. width: 32rpx;
  343. height: 32rpx;
  344. }
  345. .contentBox{
  346. }
  347. .courseItemBox{
  348. background: #FFFFFF;
  349. border-radius: 16rpx;
  350. padding: 0 10rpx;
  351. margin-bottom: 20rpx;
  352. }
  353. .courseItem{
  354. height: 80rpx;
  355. color: #333333;
  356. font-size: 32rpx;
  357. line-height: 80rpx;
  358. font-weight: bold;
  359. display: flex;
  360. justify-content: space-between;
  361. }
  362. .content{
  363. background-color: #FFFFFF;
  364. width: 100%;
  365. }
  366. .btn2{
  367. width: 200rpx;
  368. height: 64rpx;
  369. background: linear-gradient(0deg, #FFB102, #FD644F);
  370. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  371. border-radius: 32rpx;
  372. line-height: 64rpx;
  373. text-align: center;
  374. }
  375. .btn1{
  376. width: 200rpx;
  377. height: 64rpx;
  378. background: linear-gradient(0deg, #015EEA, #00C0FA);
  379. border-radius: 32rpx;
  380. line-height: 64rpx;
  381. text-align: center;
  382. margin-right: 20rpx;
  383. }
  384. .bottomBox{
  385. position: fixed;
  386. bottom: 0;
  387. width: 100%;
  388. left: 0;
  389. height:98rpx ;
  390. background-color: #FFFFFF;
  391. display: flex;
  392. justify-content: space-between;
  393. align-items: center;
  394. padding: 0 30rpx;
  395. }
  396. .blackFont{
  397. color: #333333;
  398. margin: 0 4rpx;
  399. }
  400. .wk_icon{
  401. width: 24rpx;
  402. height: 24rpx;
  403. margin-right: 12rpx;
  404. }
  405. .noteTag{
  406. ont-size: 24rpx;
  407. font-family: PingFang SC;
  408. font-weight: 500;
  409. color: #999999;
  410. align-items: center;
  411. }
  412. .priceTag{
  413. font-size: 30rpx;
  414. font-family: PingFang SC;
  415. font-weight: bold;
  416. color: #FF2D55;
  417. }
  418. .titleTag{
  419. font-size: 32rpx;
  420. font-weight: bold;
  421. color: #333333;
  422. margin-left: 8rpx;
  423. }
  424. .yearTag{
  425. width: 80rpx;
  426. height: 32rpx;
  427. background: #EBF5FF;
  428. border: 2rpx solid #007AFF;
  429. border-radius: 16rpx;
  430. font-size: 24rpx;
  431. color: #007AFF;
  432. text-align: center;
  433. line-height: 32rpx;
  434. }
  435. .itemBox{
  436. background: #FFFFFF;
  437. box-shadow: 0rpx 10rpx 9rpx 1rpx rgba(165, 196, 239, 0.1);
  438. border-radius: 24rpx;
  439. width: 100%;
  440. padding: 20rpx;
  441. margin-bottom: 20rpx;
  442. }
  443. </style>