detail.vue 11 KB

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