detail.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. <template>
  2. <view>
  3. <nav-bar title="课程详情"></nav-bar>
  4. <view class="videoBox">
  5. <!-- <view > -->
  6. <view class="video_box" v-if="!startStatus">
  7. <image :src="$method.splitImgHost(detail.coverUrl)" style="width: 100%;height: 450rpx;"></image>
  8. <image v-if="false" class="video_play" src="/static/play.png" @click="startVideo"></image>
  9. </view>
  10. <view v-else class="video_box" style="width: 100%;height: 450rpx;">
  11. <polyv-player id="playerVideo" playerId="playerVideo" height="450rpx" :vid="vid" :showSettingBtn="true"
  12. :enablePlayGesture="true" :playbackRate="playbackRate" :isAllowSeek="isAllowSeek"
  13. :autoplay="autoplay" :startTime="startTime" @statechange="onStateChange"></polyv-player>
  14. </view>
  15. <view class="cou_title">
  16. <view class="title_name">
  17. <!-- <view class="yearTag" v-if="detail.year">{{detail.year}}</view> -->
  18. <view class="titleTag">{{ detail.goodsName }}</view>
  19. </view>
  20. <view style="display: flex;justify-content: space-between;margin-top: 13rpx;">
  21. <view class="prices">
  22. <text v-if="detail.standPrice" class="price_word">¥ {{ detail.standPrice }}</text>
  23. <text v-else class="price_word free">免费</text>
  24. <text v-if="detail.linePrice" class="sale"> ¥ </text>
  25. <text v-if="detail.linePrice" class="price_line"> {{ detail.linePrice }}</text>
  26. </view>
  27. <view class="noteTag">
  28. 共 <text class="blackFont">{{ courseList.length }} 课程 {{ detail.classHours || '-' }}</text> 学时
  29. </view>
  30. </view>
  31. </view>
  32. <!-- </view> -->
  33. </view>
  34. <view class="contents">
  35. <!-- <u-line color="#D6D6DB" /> -->
  36. <!-- <view style="height: 80rpx;">
  37. <view><u-tabs :list="list" :item-width="itemWidth()" font-size="30" bar-width="24" :current="current" @change="change" active-color="#007AFF"></u-tabs></view>
  38. </view> -->
  39. <view class="tabs">
  40. <view v-for="(item, index) in list" :key="index" class="tab_item"
  41. :class="[list.length == 2 ? 'twoBtn' : list.length == 3 ? 'threeBtn' : '', { nactive: current == index }]"
  42. @click="change(index)">{{ item.name }}</view>
  43. </view>
  44. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current == 0">
  45. <view class="content">
  46. <view v-html="detail.mobileDetailHtml" style="width: 100%;overflow: hidden;"></view>
  47. </view>
  48. </view>
  49. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current == 1">
  50. <!-- <view v-for="(item, index) in courseItem.courseList" :key="index" > -->
  51. <!-- 视频课 -->
  52. <template v-if="goodsType == 1">
  53. <view v-for="(courseItem, gTindex) in goodsTeacher" :key="gTindex">
  54. <view v-for="(item, index) in courseItem.courseList" :key="index">
  55. <view class="courseItemBox" v-if="item.show && item.show == 1">
  56. <view class="courseItem" @click="openCourse(item)">
  57. <view class="courseName">{{ item.courseName }}</view>
  58. <view>
  59. <image src="/static/icon/up.png" class="icon_up" v-if="item.down"></image>
  60. <image src="/static/icon/down.png" class="icon_up" v-if="!item.down"></image>
  61. </view>
  62. </view>
  63. <view v-if="courseItem.teaList && courseItem.teaList.length > 0" class='teacher_names'>
  64. <view v-for="(tea, tindex) in courseItem.teaList" :key="tindex" class="names"
  65. :class="[States[gTindex] == tindex ? 'nactive' : '']"
  66. @click.stop="switchTeacher(tea, tindex, gTindex)">
  67. <view>{{ tea.aliasName }}</view>
  68. </view>
  69. </view>
  70. <view v-show="!item.down">
  71. <view v-for="(itemM, indexM) in item.menuList" :key="indexM">
  72. <courseModule :courseId="itemM.courseId"
  73. :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false"
  74. v-if="itemM.type == 1" :menuItem="itemM"></courseModule>
  75. <courseChapter :courseId="itemM.courseId"
  76. :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false"
  77. v-if="itemM.type == 2" :isBuy="false" :menuItem="itemM"></courseChapter>
  78. <courseSection :courseId="itemM.courseId" v-if="itemM.type == 3" :isBuy="false"
  79. :menuItem="itemM"></courseSection>
  80. <u-line></u-line>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <!-- 直播课 -->
  88. <template v-else>
  89. <view v-for="(item, index) in courseList" :key="index">
  90. <view class="courseItemBox">
  91. <view class="courseItem" @click="openCourse(item)">
  92. <view class="courseName">{{ item.courseName }}</view>
  93. <view>
  94. <image src="/static/icon/up.png" class="icon_up" v-if="item.down"></image>
  95. <image src="/static/icon/down.png" class="icon_up" v-if="!item.down"></image>
  96. </view>
  97. </view>
  98. <view v-show="!item.down">
  99. <view v-for="(itemM, indexM) in item.menuList" :key="indexM">
  100. <courseModule :courseId="itemM.courseId"
  101. :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false"
  102. v-if="itemM.type == 1" :menuItem="itemM"></courseModule>
  103. <courseChapter :courseId="itemM.courseId"
  104. :needOpen="(isFirstEnter && menuIndex[0] === index && menuIndex[1] === indexM) ? true : false"
  105. v-if="itemM.type == 2" :isBuy="false" :menuItem="itemM"></courseChapter>
  106. <courseSection :courseId="itemM.courseId" v-if="itemM.type == 3" :isBuy="false"
  107. :menuItem="itemM"></courseSection>
  108. <u-line></u-line>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </template>
  114. </view>
  115. <view style="padding: 20rpx;padding-bottom: 100rpx;position: relative;" v-show="current == 2">
  116. <!-- <view > -->
  117. <view v-for="(item, index) in freeMenuList" :key="index">
  118. <view class="courseItemBox">
  119. <view class="courseItem">
  120. <view class="courseName">{{ item.freeExamName }}</view>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- </view> -->
  125. </view>
  126. </view>
  127. <view class="bottomBox" v-if="!hideBuyState">
  128. <view class="icons">
  129. <view class="icon_item ones">
  130. <image src="/static/index/share.png" class="share"></image>
  131. <button type="default" open-type="share" class="bt_share"></button>
  132. <view class="share_w">分享</view>
  133. </view>
  134. <view class="icon_item">
  135. <image src="/static/index/shopcar.png" class="shopcar" @click="toShopcar()"></image>
  136. <view class="share_w">购物车</view>
  137. </view>
  138. </view>
  139. <view style="display: flex;color: #FFFFFF;align-items: center;">
  140. <view class="btn1" @click="addCart()">加购物车</view>
  141. <view class="btn2" @click="buy()">立即购买 </view>
  142. </view>
  143. </view>
  144. <!-- 已购买过课程的弹窗 -->
  145. <u-popup v-model="bugCourseModel" mode="center" border-radius="40">
  146. <view class="had_bugCourse">
  147. <image src="/pages3/static/imgs/hadBug.png" class="share"></image>
  148. <view class="tips">
  149. <view class="warns">温馨提示</view>
  150. <view class="words">您<text>已购买过</text>该商品课程</view>
  151. <view class="words">可立即前往学习</view>
  152. </view>
  153. <view class="tip_botton">
  154. <view class="cancel_btn" @click="changeKown()">知道了</view>
  155. <view class="confirm_btn" @click="toStudy()">去学习</view>
  156. </view>
  157. </view>
  158. </u-popup>
  159. <!-- 选择规格弹窗 -->
  160. <u-popup v-model="toggleSkuShow" mode="bottom" border-radius="40">
  161. <view class="popup_box">
  162. <view class="check_head">
  163. <view class="headers">
  164. <view class="grade">选择规格</view>
  165. <u-icon name="close" color="#9C9C9C" size="40" @click="closePop()"></u-icon>
  166. </view>
  167. </view>
  168. <view class="check_con">
  169. <scroll-view scroll-y="true" style="height: 600rpx;">
  170. <view v-for="(item, index) in specList" :key="index" class="check_items">
  171. <view class="grades">{{ item.name }}</view>
  172. <view class="grade_names" v-if="index == 0 && specList.length > 1">
  173. <view class="course_items" v-for="(child, c_index) in item.specAttrList" :key="c_index"
  174. :class="{ 'nactive': selectGoodIndex == c_index }" @click="selectGoodType(c_index)">
  175. {{ child.name }}
  176. </view>
  177. </view>
  178. <view v-if="index == 1 || specList.length == 1" class="check_box">
  179. <u-checkbox-group>
  180. <view class="check_box_item" :class="spec.check ? 'selected' : ''"
  181. v-for="spec in item.specAttrList" :key="spec.specAttributeId">
  182. <u-checkbox @change="checkboxChange" v-model="spec.check"
  183. :name="spec.specAttributeId"></u-checkbox>
  184. <view class="price_box">
  185. <view class="check_box_item_titme">{{ spec.name }}</view>
  186. <view class="price">¥{{ spec.standPrice }}</view>
  187. </view>
  188. </view>
  189. </u-checkbox-group>
  190. </view>
  191. </view>
  192. </scroll-view>
  193. </view>
  194. <view class="confirm_btns">
  195. <view class="allprice">
  196. <view>
  197. 总价:<text>¥</text><text>{{ allPrice }}</text>
  198. </view>
  199. <text>已选择{{ goodsIds.length }}个商品</text>
  200. </view>
  201. <view class="btns">
  202. <view v-if="!goodsIds.length" class="right_now r_disable">{{ isCarOrBuy == 2 ? '立即购买' : '加入购物车'
  203. }}</view>
  204. <view v-else class="right_now" @click="rightNowBuy()">{{ isCarOrBuy == 2 ? '立即购买' : '加入购物车' }}
  205. </view>
  206. </view>
  207. </view>
  208. </view>
  209. </u-popup>
  210. </view>
  211. </template>
  212. <script>
  213. import courseModule from '@/components/course/courseModule.vue';
  214. import courseChapter from '@/components/course/courseChapter.vue';
  215. import courseSection from '@/components/course/courseSection.vue';
  216. import { mapGetters, mapMutations } from 'vuex';
  217. export default {
  218. components: {
  219. courseModule,
  220. courseChapter,
  221. courseSection
  222. },
  223. data() {
  224. return {
  225. id: 0,
  226. list: [],
  227. menuIndex: [],
  228. current: 0,
  229. detail: {},
  230. courseList: [],
  231. menuList: [],
  232. freeMenuList: [],
  233. startStatus: false,
  234. playbackRate: [1.0],
  235. isAllowSeek: 'no',
  236. vid: '',
  237. autoplay: true,
  238. listenConfigList: [],
  239. listenSecond: 0,
  240. isFirstEnter: true, //是否首次进入
  241. timer: null,
  242. businessData: {},
  243. startTime: 0,
  244. bugCourseModel: false, // 弹窗
  245. hadBuyCourse: {}, // 已购买课程信息
  246. goodsTeacher: [],
  247. teaIndex: 0,
  248. States: { 0: 0 },
  249. goodsType: 1, // 1视频2题库 3补考 4前培 6直播
  250. toggleSkuShow: false,
  251. skuItem: {},
  252. isCarOrBuy: 1, // 1加入购物车 2立即购买
  253. specList: [], // 规格列表
  254. checkedAttrs: [],
  255. selectGoodIndex: 0,
  256. specAttrPriceList: [],
  257. };
  258. },
  259. computed: {
  260. ...mapGetters(['userInfo', 'goodsAuditionConfigIdList', 'playSectionId', 'hideBuyState']),
  261. allPrice() {
  262. if (!this.specList.length) return 0
  263. return this.specList.slice(-1)[0].specAttrList.reduce((a, b) => {
  264. if (b.check) {
  265. return a + b.standPrice
  266. }
  267. return a
  268. }, 0)
  269. },
  270. goodsIds() {
  271. if (!this.specList.length) return []
  272. return this.specList.slice(-1)[0].specAttrList.filter(e => e.check).map(e => e.goodsId)
  273. },
  274. isSingleChoice() {
  275. if (!this.specAttrPriceList.length) {
  276. return false
  277. }
  278. return this.specAttrPriceList[0].specialGoods
  279. }
  280. },
  281. onLoad(option) {
  282. if (option.scene) {
  283. // scene 生成二维码扫码进来的
  284. let optObj = {}
  285. let arrs = decodeURIComponent(option.scene).split('&')
  286. for (let i = 0; i < arrs.length; i++) {
  287. optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
  288. }
  289. // console.log('optObj:', optObj);
  290. this.id = optObj.id
  291. this.goodsType = optObj.goodsType
  292. console.log('optObj.sc:', optObj.sc);
  293. uni.setStorageSync('newUser_sc', optObj.sc)
  294. } else {
  295. // 小程序正常跳转的
  296. // this.id => goodsId
  297. this.id = option.id
  298. this.goodsType = option.goodsType
  299. }
  300. this.getDetail()
  301. this.goodsCourseList()
  302. this.appCommonGoodsCourseModuleFreeExamList();
  303. this.getIsBuy() // 判断是否已经购买过该课程
  304. wx.showShareMenu({
  305. withShareTicket: true,
  306. menus: ["shareAppMessage", "shareTimeline"]
  307. })
  308. },
  309. onUnload(option) {
  310. this.$store.commit('setPlaySectionId', { playSectionId: 0 });
  311. //移除所有的事件监听器
  312. uni.$off();
  313. },
  314. // 分享到朋友圈
  315. onShareTimeline() {
  316. return {
  317. title: this.detail.goodsName,
  318. query: 'id=' + this.id,
  319. imageUrl: this.$method.splitImgHost(this.detail.coverUrl)
  320. }
  321. },
  322. // 分享给朋友
  323. onShareAppMessage() {
  324. return {
  325. title: this.detail.goodsName,
  326. path: `/pages3/course/detail?id=` + this.id + '&goodsType=' + this.goodsType,
  327. imageUrl: this.$method.splitImgHost(this.detail.coverUrl)
  328. }
  329. },
  330. mounted() {
  331. let self = this
  332. uni.$on('getSection', item => {
  333. //播放试听
  334. self.listenSecond = 0
  335. for (var itemChild of self.listenConfigList) {
  336. if (self.playSectionId == (itemChild.sectionId || itemChild.menuId) && item.courseId == itemChild.courseId) {
  337. if (itemChild.auditionMinute > 0) {
  338. // self.listenSecond = itemChild.auditionMinute *60 //试听秒数
  339. self.listenSecond = itemChild.auditionMinute //试听秒数 auditionMinute调整为秒单位
  340. }
  341. }
  342. }
  343. if (self.listenSecond > 0) {
  344. if (self.timer) {
  345. clearInterval(self.timer);
  346. }
  347. if (self.vid) {
  348. //切换视频
  349. var polyvPlayerContext = self.selectComponent('#playerVideo');
  350. polyvPlayerContext.changeVid(item.recordingUrl)
  351. } else {
  352. self.vid = item.recordingUrl
  353. }
  354. self.startStatus = true
  355. self.startTime = 0
  356. } else {
  357. self.$u.toast('试听配置错误');
  358. }
  359. })
  360. this.updateChapterOpen(true)
  361. },
  362. methods: {
  363. ...mapMutations(['updateChapterOpen']),
  364. itemWidth() {
  365. return (100 / this.list.length) + '%'
  366. },
  367. appCommonGoodsCourseModuleFreeExamList() {
  368. // url: '/app/common/goods/course/moduleFreeExamList/'+data,
  369. this.$api.appCommonGoodsCourseModuleFreeExamList(this.id).then(res => {
  370. if (res.data.data.length) {
  371. this.freeMenuList = res.data.data;
  372. this.list = [
  373. {
  374. name: '课程介绍'
  375. },
  376. {
  377. name: '课程目录'
  378. },
  379. {
  380. name: '赠送'
  381. }
  382. ]
  383. } else {
  384. this.list = [
  385. {
  386. name: '课程介绍'
  387. },
  388. {
  389. name: '课程目录'
  390. }
  391. ]
  392. }
  393. console.log(this.list)
  394. })
  395. },
  396. selectGoodType(index) {
  397. if (index == this.selectGoodIndex) {
  398. return
  399. }
  400. this.selectGoodIndex = index
  401. this.changeData()
  402. },
  403. checkboxChange(val) {
  404. if (!this.isSingleChoice) return
  405. this.specList.slice(-1)[0].specAttrList.forEach(ele => {
  406. if (val.name != ele.specAttributeId) {
  407. ele.check = false
  408. }
  409. })
  410. },
  411. courseBusiness() {
  412. // url: '/app/common/course/business/'+data,
  413. this.$api.courseBusiness(this.detail.businessId).then(res => {
  414. this.businessData = res.data.data;
  415. })
  416. },
  417. toFixed(number) {
  418. if (number > 0) {
  419. return number.toFixed(2)
  420. } else {
  421. return '0.00'
  422. }
  423. },
  424. onStateChange(newstate, oldstate) {
  425. if (newstate.detail.newstate == 'playing') {
  426. //开始播放
  427. if (this.timer) {
  428. clearInterval(this.timer);
  429. }
  430. this.timer = setInterval(this.timeEvent, 1500);//定时器
  431. }
  432. },
  433. closePlay() {
  434. this.$store.commit('setPlaySectionId', { playSectionId: 0 });
  435. this.vid = ""
  436. this.startStatus = false
  437. },
  438. timeEvent() {
  439. let self = this
  440. var polyvPlayerContext = this.selectComponent('#playerVideo');
  441. if (polyvPlayerContext != null) {
  442. let PlayCurrentTime = polyvPlayerContext.getCurrentTime();
  443. if (PlayCurrentTime >= this.listenSecond) {
  444. polyvPlayerContext.stop();
  445. polyvPlayerContext.exitFullScreen();
  446. clearInterval(this.timer);
  447. this.timer = null
  448. uni.showModal({
  449. title: '提示',
  450. content: '试听结束,购买课程可学习全部',
  451. showCancel: false,
  452. success: function (resst) {
  453. self.closePlay()
  454. }
  455. });
  456. }
  457. }
  458. },
  459. openCourse(item) {
  460. item.down = !item.down
  461. if (!item.down && item.menuList.length == 0) {
  462. this.getMenuList(item)
  463. }
  464. },
  465. addShopCart(goodsIds) {
  466. if (!Array.isArray(goodsIds)) {
  467. goodsIds = [goodsIds]
  468. }
  469. this.$api.addCart({ goodsIds: goodsIds }).then(res => {
  470. if (res.data.code == 200) {
  471. uni.setStorageSync('updateCart', 1) //提醒刷新购物车
  472. uni.showToast({
  473. title: '添加成功'
  474. });
  475. } else {
  476. this.$u.toast(res.data.msg);
  477. }
  478. });
  479. },
  480. goodsCourseList() {
  481. // url: '/app/common/goods/course/list/'+ data,
  482. this.$api.goodsCourseList(this.id).then(res => {
  483. if (res.data.code == 200) {
  484. for (let i = 0; i < res.data.rows.length; i++) {
  485. let item = res.data.rows[i]
  486. item.down = true
  487. item.menuList = []
  488. }
  489. this.courseList = res.data.rows;
  490. this.getFirstCourse();
  491. // 不同
  492. if (this.goodsType == 1) {
  493. this.getCourseTeacher(res.data.rows)
  494. }
  495. }
  496. });
  497. },
  498. /**
  499. * 获取第一个有模块或者章的课程
  500. */
  501. async getFirstCourse() {
  502. for (let i = 0; i < this.courseList.length; i++) {
  503. let menuIndexOrFalse = await this.getCourseMenus(this.courseList[i]);
  504. if (menuIndexOrFalse !== false) {
  505. this.menuIndex = [i, menuIndexOrFalse]
  506. this.openCourse(this.courseList[i])
  507. break
  508. }
  509. }
  510. },
  511. getCourseMenus(item) {
  512. return new Promise(resolve => {
  513. // url: '/app/common/course/menuList',
  514. this.$api.menuList({ courseId: item.courseId }).then(res => {
  515. if (res.data.code == 200) {
  516. for (let i = 0; i < res.data.rows.length; i++) {
  517. if (res.data.rows[i].type == 1 || res.data.rows[i].type == 2) {
  518. resolve(i)
  519. break;
  520. }
  521. }
  522. }
  523. });
  524. })
  525. },
  526. getCourseTeacher(rows) {
  527. //获取商品双师资模板
  528. this.$api.getGoodsCourseTeacher({
  529. goodsId: this.id
  530. }).then((res1) => {
  531. // console.log(res1,'res1');
  532. if (res1.data.data && res1.data.data.length > 0) {
  533. //课程老师模板
  534. let teacherTel = res1.data.data;
  535. //商品课程
  536. let courses = rows
  537. teacherTel.forEach((tea) => {
  538. let dataList = []
  539. let teacherList = []
  540. courses.forEach((item) => {
  541. let data = tea.courseList.filter(x => x.courseId == item.courseId)
  542. if (data && data.length > 0) {
  543. dataList.push(item)
  544. teacherList = tea.courseList
  545. }
  546. })
  547. let result = {
  548. teaList: teacherList,
  549. courseList: dataList
  550. }
  551. this.goodsTeacher.push(result)
  552. })
  553. if (this.goodsTeacher && this.goodsTeacher.length > 0) {
  554. let courseIds = []
  555. this.goodsTeacher.forEach((item) => {
  556. item.courseList.forEach((course) => {
  557. courseIds.push(course.courseId)
  558. })
  559. })
  560. if (courseIds.length > 0) {
  561. courses.forEach((item) => {
  562. if (!courseIds.includes(item.courseId)) {
  563. let data = {
  564. teaList: [],
  565. courseList: []
  566. }
  567. data.courseList.push(item)
  568. this.goodsTeacher.push(data)
  569. }
  570. })
  571. }
  572. this.goodsTeacher.forEach((item) => {
  573. if (item.courseList && item.courseList.length > 0) {
  574. item.courseList[0].show = 1
  575. }
  576. })
  577. }
  578. } else {
  579. //没有双师资模板
  580. rows.forEach((item) => {
  581. item.show = 1
  582. let data = {
  583. teaList: [],
  584. courseList: []
  585. }
  586. data.courseList.push(item)
  587. this.goodsTeacher.push(data)
  588. })
  589. }
  590. })
  591. console.log(this.goodsTeacher, 'this.goodsTeacher');
  592. },
  593. //切换老师
  594. switchTeacher(data, tindex, gTindex) {
  595. // console.log(data,'data');
  596. this.States[gTindex] = tindex
  597. this.teaIndex = tindex
  598. this.goodsTeacher.forEach((item, index) => {
  599. if (item.teaList && item.teaList.length > 0) {
  600. let list = item.teaList.filter(x => x.courseId == data.courseId)
  601. if (list && list.length > 0) {
  602. item.courseList.forEach((course, courseIndex) => {
  603. if (course.courseId == data.courseId) {
  604. this.$set(this.goodsTeacher[index].courseList[courseIndex], "show", 1)
  605. } else {
  606. this.$set(this.goodsTeacher[index].courseList[courseIndex], "show", 0)
  607. }
  608. })
  609. }
  610. }
  611. })
  612. console.log('切换后的this.goodsTeacher, ', this.goodsTeacher)
  613. },
  614. getMenuList(item) {
  615. let self = this
  616. this.$api.menuList({ courseId: item.courseId }).then(res => {
  617. if (res.data.code == 200) {
  618. for (let i = 0; i < res.data.rows.length; i++) {
  619. let item = res.data.rows[i]
  620. item.down = true
  621. item.id = item.menuId
  622. item.name = item.menuName
  623. if (item.type == 3) {
  624. //判断是否试听
  625. item.tryListen = false
  626. if (self.goodsAuditionConfigIdList.indexOf(item.id) !== -1) {
  627. item.tryListen = true
  628. }
  629. }
  630. }
  631. item.menuList = res.data.rows
  632. }
  633. });
  634. },
  635. // 获取课程详情
  636. getDetail() {
  637. let self = this
  638. let sectionIdList = []
  639. // /app/common/goods/+data
  640. this.$api.commonGoodsDetail(this.id).then(res => {
  641. if (res.data.code == 200) {
  642. if (res.data.data) {
  643. if (res.data.data.mobileDetailHtml) {
  644. res.data.data.mobileDetailHtml = res.data.data.mobileDetailHtml.replace(/<img/gi, '<img style="max-width:100%;"')
  645. }
  646. self.detail = res.data.data
  647. this.courseBusiness();
  648. if (self.detail.goodsAuditionConfig) {
  649. self.listenConfigList = JSON.parse(self.detail.goodsAuditionConfig)
  650. for (var itemChild of self.listenConfigList) {
  651. sectionIdList.push(itemChild.sectionId)//存储试听节ID
  652. }
  653. self.$store.commit('setGoodsAuditionConfigIdList', { goodsAuditionConfigIdList: sectionIdList });
  654. }
  655. }
  656. }
  657. });
  658. },
  659. buy() {
  660. if (this.$method.isGoLogin()) {
  661. return
  662. }
  663. // 判断有没有规格选择
  664. if (this.detail.specTemplateId) {
  665. this.isCarOrBuy = 2
  666. this.getSpecDetail()
  667. return
  668. }
  669. this.$navTo.togo('/pages2/order/confirm_list?id=' + this.id);
  670. },
  671. addCart() {
  672. if (this.$method.isGoLogin()) {
  673. return
  674. }
  675. // 判断有没有规格选择
  676. if (this.detail.specTemplateId) {
  677. this.isCarOrBuy = 1
  678. this.getSpecDetail()
  679. return
  680. }
  681. this.addShopCart(this.id)
  682. },
  683. getSpecDetail() {
  684. // || 35
  685. this.checkedAttrs = []
  686. this.$http({
  687. url: `/app/common/spec/${this.detail.specTemplateId}`,
  688. method: 'get',
  689. noToken: true
  690. }).then((res) => {
  691. let data = res.data.data
  692. if (data) {
  693. this.toggleSkuShow = true
  694. this.specAttrPriceList = data.specAttrPriceList
  695. this.specList = this.changeData(data.specList || [])
  696. } else {
  697. if (this.isCarOrBuy == 1) { // 加入购物车
  698. this.addShopCart(this.id)
  699. } else {
  700. this.$navTo.togo('/pages2/order/confirm_list?id=' + this.id);
  701. }
  702. this.closePop()
  703. }
  704. })
  705. },
  706. changeData(data = this.specList) {
  707. let len = data.length
  708. if (!len) return []
  709. data[len - 1].specAttrList.forEach((e, i) => {
  710. e.check = e.check || false
  711. let id = e.specAttributeId
  712. if (len > 1) {
  713. id = data[0].specAttrList[this.selectGoodIndex].specAttributeId + ',' + id
  714. }
  715. let item = this.specAttrPriceList.find(e => e.specAttrIds == id)
  716. if (item) {
  717. e.standPrice = item.standPrice
  718. e.goodsId = item.goodsId
  719. }
  720. })
  721. // data.forEach((item, index) => {
  722. // if (index == len - 1) {
  723. // item.specAttrList.forEach((e, i) => {
  724. // e.check = false
  725. // })
  726. // }
  727. // })
  728. return data
  729. },
  730. change(index) {
  731. this.current = index;
  732. },
  733. toShopcar() {
  734. uni.navigateTo({
  735. url: '/pages4/shopping/shoppingCart'
  736. })
  737. },
  738. getIsBuy() {
  739. this.$http({
  740. url: '/order/buyGoodsNotExpired',
  741. method: 'get',
  742. data: { goodsId: this.id }
  743. }).then((res) => {
  744. if (res.data.code == 200) {
  745. if (res.data.data) { // 有data返回是已经购买过的课程
  746. this.hadBuyCourse = res.data.data
  747. this.bugCourseModel = true
  748. }
  749. }
  750. })
  751. },
  752. changeKown() {
  753. this.bugCourseModel = false
  754. },
  755. async toStudy() {
  756. let item = this.hadBuyCourse
  757. if (item.goodsType == 6) { // 进入直播课
  758. this.toLive(item)
  759. return
  760. }
  761. // /course/goodsRebuildStatus查询用户商品重修状态
  762. let rebuildStatus = await this.courseGoodsRebuildStatus(item.goodsId, item.gradeId)
  763. if (rebuildStatus == 0) {
  764. this.$navTo.togo('/pages2/learn/details', {
  765. gradeId: item.gradeId,
  766. goodsId: item.goodsId,
  767. orderGoodsId: item.orderGoodsId,
  768. });
  769. return;
  770. }
  771. // /lock/lockStatus
  772. this.$api.lockLockStatus({
  773. action: 'jxjy',
  774. uuid: this.$method.getUuid()
  775. }).then(res => {
  776. if (res.data.code == 200) { //有其他端在操作,不能学习
  777. uni.showToast({
  778. icon: 'none',
  779. title: res.data.msg,
  780. mask: true,
  781. duration: 3000
  782. })
  783. } else if (res.data.code == 500) { //可以学习
  784. this.$http({
  785. url: '/course/courseList',
  786. method: 'get',
  787. data: {
  788. pageNum: 1,
  789. pageSize: 1,
  790. goodsId: item.goodsId,
  791. gradeId: item.gradeId,
  792. orderGoodsId: item.orderGoodsId,
  793. },
  794. })
  795. .then(res => {
  796. if (res.data.code == 200) {
  797. if (res.data.total > 1) {
  798. // this.$navTo.togo(`/pages2/wd/course?id=${item.goodsId}&gid=${item.gradeId}&orderGoodsId=${item.orderGoodsId}`);
  799. uni.navigateTo({
  800. url: `/pages3/polyv/detail?id=''&goodsId=${item.goodsId}&orderGoodsId=${item.orderGoodsId}&gradeId=${item.gradeId}`
  801. })
  802. } else if (res.data.total == 1) {
  803. uni.navigateTo({
  804. url: `/pages3/polyv/detail?id=${res.data.rows[0].courseId}&goodsId=${item.goodsId}&orderGoodsId=${item.orderGoodsId}&gradeId=${item.gradeId}`
  805. })
  806. } else {
  807. uni.showToast({
  808. icon: 'none',
  809. title: '暂无可观看的视频课程'
  810. })
  811. }
  812. }
  813. })
  814. }
  815. })
  816. },
  817. toLive(item) {
  818. this.$api.courseCourseList({
  819. pageNum: 1,
  820. pageSize: 1,
  821. goodsId: item.goodsId,
  822. gradeId: 0,
  823. orderGoodsId: item.orderGoodsId,
  824. }).then(res => {
  825. if (res.data.code == 200) {
  826. if (res.data.total > 1) {
  827. // uni.navigateTo({
  828. // url:'/pages5/liveDetail/course?orderGoodsId='+item.orderGoodsId+'&goodsId='+item.goodsId+'&gradeId=0'
  829. // })
  830. uni.navigateTo({
  831. url: '/pages3/live/detail?orderGoodsId=' + item.orderGoodsId + '&goodsId=' + item.goodsId + '&gradeId=0&courseId=""'
  832. })
  833. } else if (res.data.total == 1) {
  834. uni.navigateTo({
  835. url: '/pages3/live/detail?orderGoodsId=' + item.orderGoodsId + '&goodsId=' + item.goodsId + '&gradeId=0&courseId=' + res.data.rows[0].courseId
  836. })
  837. } else {
  838. uni.showToast({
  839. icon: 'none',
  840. title: '暂无可观看的直播课程'
  841. })
  842. }
  843. }
  844. })
  845. },
  846. /**
  847. * @param {Object} goodsId 商品id
  848. * 查询商品重修状态
  849. */
  850. courseGoodsRebuildStatus(goodsId, gradeId) {
  851. return new Promise(resolve => {
  852. this.$http({
  853. url: '/course/goodsRebuildStatus',
  854. method: 'get',
  855. data: {
  856. goodsId: goodsId,
  857. gradeId: gradeId
  858. },
  859. // noLoading: true,
  860. // compleLoading: true, // 请求成功是否还要继续显示加载中
  861. })
  862. .then(res => {
  863. resolve(res.data.data)
  864. })
  865. })
  866. },
  867. closePop() {
  868. this.toggleSkuShow = false
  869. this.skuItem = {}
  870. },
  871. // 获取规格属性值对应的商品信息
  872. getGoodsInfos(specAttrIds) {
  873. this.$http({
  874. url: '/app/common/attr/goods',
  875. method: 'get',
  876. data: {
  877. specTemplateId: this.detail.specTemplateId,
  878. specAttrIds: specAttrIds.join(',')
  879. },
  880. noToken: true
  881. }).then((res) => {
  882. if (res.data.code == 200) {
  883. this.skuItem = res.data.data || {}
  884. } else {
  885. this.skuItem = {}
  886. this.$u.toast('商品已下架, 请重新选择')
  887. }
  888. })
  889. },
  890. rightNowBuy() {
  891. let goodsIds = [...new Set(this.goodsIds)]
  892. this.$api.checkGoodsStatus({ goodsIds }).then(res => {
  893. if (res.data.code == 500) {
  894. return this.$u.toast(res.data.msg)
  895. }
  896. if (this.isCarOrBuy == 1) { // 加入购物车
  897. this.addShopCart(goodsIds)
  898. } else {
  899. if (this.isSingleChoice) {
  900. this.$navTo.togo('/pages2/order/confirm_list?id=' + goodsIds);
  901. } else {
  902. let data = []
  903. goodsIds.forEach(id => {
  904. data.push(this.specAttrPriceList.find(e => e.goodsId == id))
  905. })
  906. this.$store.commit('setShoppingCartList', { shoppingCartList: data });
  907. this.$navTo.togo('/pages2/order/confirm_pay');
  908. }
  909. }
  910. this.closePop()
  911. })
  912. }
  913. }
  914. };
  915. </script>
  916. <style >
  917. page {
  918. background-color: #F2F2F2;
  919. }
  920. </style>
  921. <style lang="scss" scope>
  922. @import './index.scss';
  923. .video_t2 {
  924. font-size: 24rpx;
  925. font-family: PingFang SC;
  926. font-weight: 500;
  927. color: #666666;
  928. }
  929. .video_t1 {
  930. height: 80rpx;
  931. color: #333333;
  932. line-height: 80rpx;
  933. font-size: 30rpx;
  934. font-family: PingFang SC;
  935. font-weight: bold;
  936. color: #333333;
  937. overflow: hidden;
  938. text-overflow: ellipsis;
  939. white-space: nowrap;
  940. }
  941. .video_t1_t {
  942. display: flex;
  943. flex-direction: column;
  944. height: 80rpx;
  945. color: #333333;
  946. text-align: center;
  947. align-items: center;
  948. border-left: solid 1px #d6d6db;
  949. }
  950. .video_play {
  951. position: absolute;
  952. width: 95rpx;
  953. height: 95rpx;
  954. top: 0;
  955. left: 0;
  956. right: 0;
  957. bottom: 0;
  958. margin: auto;
  959. }
  960. .video_box {
  961. position: relative;
  962. }
  963. .contents {
  964. width: 100%;
  965. height: 100%;
  966. background-color: #ffffff;
  967. margin-top: 16rpx;
  968. overflow: hidden;
  969. }
  970. .cou_title {
  971. padding: 24rpx 32rpx 40rpx 32rpx;
  972. display: flex;
  973. flex-direction: column;
  974. justify-content: space-around;
  975. }
  976. .prices {
  977. .price_word {
  978. font-size: 40rpx;
  979. font-weight: 800;
  980. color: #FC3F3F;
  981. }
  982. .sale {
  983. color: #999999;
  984. font-size: 28rpx;
  985. margin-left: 8rpx;
  986. }
  987. .price_line {
  988. color: #999999;
  989. font-size: 28rpx;
  990. text-decoration: line-through;
  991. font-weight: 400;
  992. }
  993. .free {
  994. font-size: 32rpx;
  995. }
  996. }
  997. // tab
  998. .tabs {
  999. // width: 100%;
  1000. height: 78rpx;
  1001. display: flex;
  1002. align-items: center;
  1003. justify-content: space-between;
  1004. background-color: #F2F7FF;
  1005. border-radius: 38rpx;
  1006. margin: 24rpx;
  1007. padding: 0rpx 5rpx;
  1008. .tab_item {
  1009. width: 345rpx;
  1010. height: 65rpx;
  1011. line-height: 65rpx;
  1012. font-size: 28rpx;
  1013. font-weight: bold;
  1014. border-radius: 32rpx;
  1015. text-align: center;
  1016. color: #333;
  1017. &.nactive {
  1018. color: #fff;
  1019. background-color: #3577E8;
  1020. }
  1021. &.twoBtn {
  1022. width: 50%;
  1023. }
  1024. &.threeBtn {
  1025. width: 33%;
  1026. }
  1027. }
  1028. // /deep/ .u-tabs {
  1029. // background:none!important;
  1030. // }
  1031. }
  1032. .courseName {
  1033. white-space: nowrap;
  1034. overflow: hidden;
  1035. text-overflow: ellipsis;
  1036. }
  1037. .videoBox {
  1038. background-color: #FFFFFF;
  1039. width: 100%;
  1040. /* height: 680rpx; */
  1041. z-index: 999;
  1042. }
  1043. .icon_up {
  1044. width: 32rpx;
  1045. height: 32rpx;
  1046. }
  1047. .courseItemBox {
  1048. background: #FFFFFF;
  1049. border-radius: 16rpx;
  1050. padding: 0 10rpx;
  1051. margin-bottom: 20rpx;
  1052. }
  1053. .courseItem {
  1054. height: 80rpx;
  1055. color: #333333;
  1056. font-size: 32rpx;
  1057. line-height: 80rpx;
  1058. font-weight: bold;
  1059. display: flex;
  1060. justify-content: space-between;
  1061. }
  1062. .content {
  1063. background-color: #FFFFFF;
  1064. width: 100%;
  1065. }
  1066. .btn2 {
  1067. width: 187rpx;
  1068. height: 79rpx;
  1069. line-height: 79rpx;
  1070. background: #FC3F3F;
  1071. border-radius: 40rpx;
  1072. text-align: center;
  1073. font-size: 24rpx;
  1074. }
  1075. .btn1 {
  1076. width: 187rpx;
  1077. height: 79rpx;
  1078. line-height: 79rpx;
  1079. background: #FFB102;
  1080. border-radius: 40rpx;
  1081. text-align: center;
  1082. margin-right: 11rpx;
  1083. font-size: 24rpx;
  1084. }
  1085. .blackFont {
  1086. margin: 0 4rpx;
  1087. }
  1088. .wk_icon {
  1089. width: 24rpx;
  1090. height: 24rpx;
  1091. margin-right: 12rpx;
  1092. }
  1093. .noteTag,
  1094. .blackFont {
  1095. font-size: 30rpx;
  1096. font-family: PingFang SC;
  1097. font-weight: 400;
  1098. color: #A7B0B8;
  1099. align-items: center;
  1100. }
  1101. .priceTag {
  1102. /* font-size: 30rpx;
  1103. font-family: PingFang SC;
  1104. font-weight: bold;
  1105. color: #FF2D55; */
  1106. width: 60rpx;
  1107. height: 40rpx;
  1108. line-height: 40rpx;
  1109. text-align: center;
  1110. border: 1rpx solid #333;
  1111. }
  1112. .titleTag {
  1113. font-size: 32rpx;
  1114. font-weight: bold;
  1115. color: #333333;
  1116. // margin-left: 8rpx;
  1117. }
  1118. .yearTag {
  1119. width: 80rpx;
  1120. height: 32rpx;
  1121. background: #EBF5FF;
  1122. border: 2rpx solid #007AFF;
  1123. border-radius: 16rpx;
  1124. font-size: 24rpx;
  1125. color: #007AFF;
  1126. text-align: center;
  1127. line-height: 32rpx;
  1128. }
  1129. .itemBox {
  1130. background: #FFFFFF;
  1131. box-shadow: 0rpx 10rpx 9rpx 1rpx rgba(165, 196, 239, 0.1);
  1132. border-radius: 24rpx;
  1133. width: 100%;
  1134. padding: 20rpx;
  1135. margin-bottom: 20rpx;
  1136. }
  1137. // 老师名字样式
  1138. .teacher_names {
  1139. display: flex;
  1140. padding-bottom: 15rpx;
  1141. border-bottom: 2rpx solid #F0F0F0;
  1142. .names {
  1143. padding: 6rpx 12rpx;
  1144. font-size: 26rpx;
  1145. color: #969696;
  1146. background: #F8F8F8;
  1147. border-radius: 8rpx;
  1148. margin-right: 10rpx;
  1149. &.nactive {
  1150. color: #3F8DFD;
  1151. background: #F2F7FF;
  1152. }
  1153. }
  1154. }
  1155. </style>