detail.vue 11 KB

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