detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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">{{courseList.length}} 课程 {{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: 730rpx;" 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: 730rpx;" 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 item.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. self.listenSecond = itemChild.auditionMinute //试听秒数 auditionMinute调整为秒单位
  136. }
  137. }
  138. }
  139. if(self.listenSecond>0){
  140. if(self.timer){
  141. clearInterval(self.timer);
  142. }
  143. if(self.vid){
  144. //切换视频
  145. var polyvPlayerContext = self.selectComponent('#playerVideo');
  146. polyvPlayerContext.changeVid(item.recordingUrl)
  147. }else{
  148. self.vid = item.recordingUrl
  149. }
  150. self.startStatus = true
  151. self.startTime = 0
  152. }else{
  153. self.$u.toast('试听配置错误');
  154. }
  155. })
  156. },
  157. methods: {
  158. courseBusiness(){
  159. this.$api.courseBusiness(this.detail.businessId).then(res => {
  160. this.businessData = res.data.data;
  161. })
  162. },
  163. toFixed(number) {
  164. if(number > 0) {
  165. return number.toFixed(2)
  166. } else {
  167. return '0.00'
  168. }
  169. },
  170. onStateChange(newstate, oldstate) {
  171. if (newstate.detail.newstate == 'playing') {
  172. //开始播放
  173. if(this.timer){
  174. clearInterval(this.timer);
  175. }
  176. this.timer = setInterval(this.timeEvent, 1500);//定时器
  177. }
  178. },
  179. closePlay(){
  180. this.$store.commit('setPlaySectionId', {playSectionId :0});
  181. this.vid = ""
  182. this.startStatus = false
  183. },
  184. timeEvent() {
  185. let self = this
  186. var polyvPlayerContext = this.selectComponent('#playerVideo');
  187. if (polyvPlayerContext != null) {
  188. let PlayCurrentTime = polyvPlayerContext.getCurrentTime();
  189. if(PlayCurrentTime>=this.listenSecond){
  190. polyvPlayerContext.stop();
  191. polyvPlayerContext.exitFullScreen();
  192. clearInterval(this.timer);
  193. this.timer = null
  194. uni.showModal({
  195. title: '提示',
  196. content: '试听结束,购买课程可学习全部',
  197. showCancel:false,
  198. success: function(resst) {
  199. self.closePlay()
  200. }
  201. });
  202. }
  203. }
  204. },
  205. openCourse(item){
  206. item.down = !item.down
  207. if(!item.down&&item.menuList.length==0){
  208. this.getMenuList(item)
  209. }
  210. },
  211. addShopCart() {
  212. let self = this
  213. this.$api.addCart({goodsId:this.id}).then(res => {
  214. if(res.data.code==200){
  215. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  216. uni.showToast({
  217. title: '添加成功'
  218. });
  219. }else{
  220. this.$u.toast(res.data.msg);
  221. }
  222. });
  223. },
  224. goodsCourseList() {
  225. let self = this
  226. this.$api.goodsCourseList(this.id).then(res => {
  227. if(res.data.code==200){
  228. for(let i=0;i<res.data.rows.length;i++){
  229. let item = res.data.rows[i]
  230. item.down = true
  231. item.menuList = []
  232. }
  233. self.courseList = res.data.rows
  234. }
  235. });
  236. },
  237. getMenuList(item) {
  238. let self = this
  239. this.$api.menuList({courseId:item.courseId}).then(res => {
  240. if(res.data.code==200){
  241. for(let i=0;i<res.data.rows.length;i++){
  242. let item = res.data.rows[i]
  243. item.down = true
  244. item.id = item.menuId
  245. item.name = item.menuName
  246. if(item.type==3){
  247. //判断是否试听
  248. item.tryListen = false
  249. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  250. item.tryListen = true
  251. }
  252. }
  253. }
  254. item.menuList = res.data.rows
  255. }
  256. });
  257. },
  258. getDetail() {
  259. let self = this
  260. let sectionIdList = []
  261. this.$api.commonGoodsDetail(this.id).then(res => {
  262. if(res.data.code==200){
  263. if(res.data.data.mobileDetailHtml){
  264. res.data.data.mobileDetailHtml = res.data.data.mobileDetailHtml.replace(/<img/gi,'<img style="max-width:100%;"')
  265. }
  266. self.detail = res.data.data
  267. this.courseBusiness();
  268. if(self.detail.goodsAuditionConfig){
  269. self.listenConfigList = JSON.parse(self.detail.goodsAuditionConfig)
  270. for (var itemChild of self.listenConfigList) {
  271. sectionIdList.push(itemChild.sectionId)//存储试听节ID
  272. }
  273. self.$store.commit('setGoodsAuditionConfigIdList', {goodsAuditionConfigIdList:sectionIdList});
  274. }
  275. }
  276. });
  277. },
  278. buy(){
  279. if(this.$method.isGoLogin()){
  280. return
  281. }
  282. this.$navTo.togo('/pages2/order/confirm_list?id='+this.id);
  283. },
  284. addCart(){
  285. if(this.$method.isGoLogin()){
  286. return
  287. }
  288. this.addShopCart()
  289. },
  290. open(item){
  291. item.showChildren = !item.showChildren
  292. },
  293. change(index){
  294. this.current = index;
  295. }
  296. }
  297. };
  298. </script>
  299. <style >
  300. page{
  301. background-color: #EAEEF1;
  302. }
  303. </style>
  304. <style scope>
  305. .video_t2 {
  306. font-size: 24rpx;
  307. font-family: PingFang SC;
  308. font-weight: 500;
  309. color: #666666;
  310. }
  311. .video_t1 {
  312. height: 80rpx;
  313. color: #333333;
  314. line-height: 80rpx;
  315. font-size: 30rpx;
  316. font-family: PingFang SC;
  317. font-weight: bold;
  318. color: #333333;
  319. overflow: hidden;
  320. text-overflow:ellipsis;
  321. white-space: nowrap;
  322. }
  323. .video_t1_t {
  324. display: flex;
  325. flex-direction: column;
  326. height: 80rpx;
  327. color: #333333;
  328. text-align: center;
  329. align-items: center;
  330. border-left: solid 1px #d6d6db;
  331. }
  332. .video_play {
  333. position: absolute;
  334. width: 95rpx;
  335. height: 95rpx;
  336. top: 0;
  337. left: 0;
  338. right: 0;
  339. bottom: 0;
  340. margin: auto;
  341. }
  342. .video_box {
  343. position: relative;
  344. }
  345. .courseName{
  346. white-space:nowrap;
  347. overflow:hidden;
  348. text-overflow:ellipsis;
  349. }
  350. .videoBox{
  351. position: fixed;
  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>