detail.vue 11 KB

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