detail.vue 11 KB

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