detail.vue 11 KB

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