detail.vue 11 KB

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