detail.vue 40 KB

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