courseDeal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <div class="page">
  3. <van-nav-bar :title="title" @click-left="onClickLeft">
  4. <template #left>
  5. <template v-if="$route.query && $route.query.code">
  6. <van-icon name="wap-home-o" />
  7. <span style="font-size: .32rem;color: #FFF;">首页</span>
  8. </template>
  9. <template v-else>
  10. <van-icon name="arrow-left" />
  11. <span style="font-size: .32rem;color: #FFF;">返回</span>
  12. </template>
  13. </template>
  14. </van-nav-bar>
  15. <div class="courseContent">
  16. <div class="tabs">
  17. <div v-show="showBack" class="toTop" @click="BackTop">
  18. <span><van-icon name="back-top"/></span>
  19. </div>
  20. <scroller ref="scroller" :on-scrolling="scrollChange">
  21. <div class="previewImg">
  22. <img :src="courseDetail.thumb" />
  23. </div>
  24. <div class="title">
  25. <span>{{ courseDetail.price }}</span>
  26. <p>{{ courseDetail.name }}</p>
  27. <i style="margin-right: .1rem;"
  28. >已更新{{ courseDetail.sections.length }}节课</i
  29. >
  30. <i
  31. >{{
  32. Number(courseDetail.baseClick) + Number(courseDetail.clickNum)
  33. }}次浏览</i
  34. >
  35. </div>
  36. <van-tabs v-model="activeTab" swipeable sticky>
  37. <van-tab title="课程介绍">
  38. <div class="images">
  39. <div
  40. class="descImage"
  41. v-for="(item, index) in courseDetail.images"
  42. :key="index"
  43. >
  44. <img :src="item" />
  45. </div>
  46. </div>
  47. </van-tab>
  48. <van-tab title="课程目录">
  49. <div class="catelog">
  50. <div class="logConetent">
  51. <div
  52. class="logLi"
  53. v-for="(item, index) in courseDetail.sections"
  54. :key="index"
  55. @click="toSectionVidio(item, index)"
  56. >
  57. <p>{{ index + 1 }}、{{ item.name }}</p>
  58. </div>
  59. </div>
  60. </div>
  61. </van-tab>
  62. </van-tabs>
  63. <div
  64. id="xxhh"
  65. style="height: 1.2rem;"
  66. v-if="!courseDetail.buy && canGive && canGive2"
  67. ></div>
  68. </scroller>
  69. </div>
  70. <div
  71. class="getCourse"
  72. v-if="!courseDetail.buy && canGive && canGive2"
  73. @click="useCode"
  74. >
  75. <van-button icon="fire-o" square class="getBtn"
  76. >点击领取课程名额</van-button
  77. >
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import { setWxConfig } from "../utils";
  84. import wx from 'weixin-js-sdk'
  85. import {
  86. learnerCourseDetail,
  87. getCourseCodeDetail,
  88. getCourseCode,
  89. getVideoSrc
  90. } from "../api";
  91. export default {
  92. name: "courseDetail",
  93. components: {},
  94. props: [],
  95. data() {
  96. return {
  97. showBack:false,
  98. activeTab: 0,
  99. title: "课程详情",
  100. courseDetail: {
  101. thumb: "",
  102. name: "",
  103. images: [],
  104. sections: [],
  105. buy: false
  106. },
  107. canGive: true,
  108. canGive2: true,
  109. giveCode: false,
  110. codeDetail: {
  111. enable: true
  112. }
  113. };
  114. },
  115. created() {
  116. // this.init();
  117. },
  118. activated(){
  119. this.init();
  120. },
  121. methods: {
  122. scrollChange(e){
  123. //需要滚动的界面实际长度大于整个页面长度
  124. if(e>40&&document.getElementsByClassName('page')[0].offsetHeight<document.getElementsByClassName('_v-content')[0].offsetHeight){
  125. this.showBack = true;
  126. }else{
  127. this.showBack = false;
  128. }
  129. },
  130. //回到顶部
  131. BackTop() {
  132. this.$refs.scroller.scrollTo(0, 0, 500);
  133. },
  134. // 领取课程提示
  135. useCode() {
  136. if (this.codeDetail && this.codeDetail.enable) {
  137. this.$dialog
  138. .confirm({
  139. title: "提示",
  140. message: "确定领取当前课程吗"
  141. })
  142. .then(() => {
  143. let data = {
  144. salesCode: this.codeDetail.salesCode,
  145. userId: this.codeDetail.userId,
  146. subjectId: this.codeDetail.subjectId
  147. };
  148. getCourseCode(data).then(res => {
  149. this.$toast.success("领取成功!");
  150. this.giveCode = true;
  151. this.getDetail();
  152. });
  153. });
  154. } else {
  155. this.$dialog.confirm({
  156. title: "提示",
  157. message: "该课程码已失效"
  158. });
  159. // this.$toast.fail("该课程码已失效");
  160. }
  161. },
  162. // 领取课程码课程
  163. getCodeDetail() {
  164. getCourseCodeDetail(this.$route.query.code).then(res => {
  165. this.codeDetail = res;
  166. if (!res && !this.courseDetail.buy) {
  167. this.$dialog.confirm({
  168. title: "提示",
  169. message: "该课程码已失效"
  170. });
  171. // this.$toast.fail("该课程码已失效");
  172. }
  173. });
  174. },
  175. // 章节点击观看视频
  176. toSectionVidio(item, index) {
  177. if (this.courseDetail.buy && this.courseDetail.enable) {
  178. let data = {
  179. index: index,
  180. link: item.link
  181. };
  182. sessionStorage.setItem("vd_info", JSON.stringify(data));
  183. this.$router.push({
  184. path: `/course/video/${this.$route.params.id}`
  185. });
  186. } else if (!this.courseDetail.buy) {
  187. this.$toast.fail("请先领取课程后再观看");
  188. } else {
  189. this.$toast.fail("课程已下架");
  190. }
  191. },
  192. // 返回首页
  193. onClickLeft() {
  194. if (this.$route.query && (this.$route.query.code)) {
  195. this.$router.push("/courseHome");
  196. } else {
  197. this.$router.go(-1);
  198. }
  199. },
  200. // 初始化
  201. init() {
  202. this.courseId = this.$route.params.id;
  203. if (this.$route.query && this.$route.query.code && this.$route.query.code != 2) {
  204. this.getDetail();
  205. } else {
  206. this.getDetail();
  207. this.canGive = false;
  208. }
  209. },
  210. //删除URL的指定参数
  211. urlDelP(url,name){
  212. var urlArr = url.split('?');
  213. if(urlArr.length>1 && urlArr[1].indexOf(name)>-1){
  214. var query = urlArr[1];
  215. var obj = {}
  216. var arr = query.split("&");
  217. for (var i = 0; i < arr.length; i++) {
  218. arr[i] = arr[i].split("=");
  219. obj[arr[i][0]] = arr[i][1];
  220. };
  221. delete obj[name];
  222. var urlte = urlArr[0] +'?'+ JSON.stringify(obj).replace(/[\"\{\}]/g,"").replace(/\:/g,"=").replace(/\,/g,"&");
  223. return urlte;
  224. }else{
  225. return url;
  226. };
  227. },
  228. // 获取用户此课程的详情
  229. getDetail() {
  230. learnerCourseDetail(this.courseId).then(res => {
  231. this.courseDetail = res;
  232. if(this.$isWx){
  233. let info = {
  234. title:this.courseDetail.name,// 分享标题
  235. desc:'听完觉得确实不错,忍不住要推荐~',// 分享描述
  236. link: `${window.location.href}`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  237. imgUrl: this.courseDetail.thumb, // 分享图标
  238. }
  239. if(this.$route.query&&this.$route.query.code){
  240. let newUrl = this.urlDelP(window.location.href,'code')
  241. info.link = newUrl.includes('?')?`${newUrl}&code=2`:`${newUrl}?code=2`
  242. }else{
  243. info.link = window.location.href.includes('?')?`${window.location.href}&code=2`:`${window.location.href}?code=2`
  244. }
  245. setWxConfig(info);
  246. }
  247. if (
  248. this.courseDetail.buy &&
  249. this.$route.query &&
  250. this.$route.query.code &&
  251. this.$route.query.code != 2 &&
  252. !this.giveCode
  253. ) {
  254. this.$toast.fail("您已经购买课程,无需再次购买");
  255. return;
  256. }
  257. if (!this.courseDetail.enable) {
  258. this.canGive2 = false;
  259. this.$toast.fail("课程已下架");
  260. return;
  261. }
  262. if (
  263. !this.courseDetail.buy &&
  264. this.$route.query &&
  265. this.$route.query.code &&
  266. this.$route.query.code != 2 &&
  267. this.courseDetail.enable &&
  268. !this.giveCode
  269. ) {
  270. this.getCodeDetail();
  271. }
  272. });
  273. }
  274. },
  275. computed: {}
  276. };
  277. </script>
  278. <style scoped lang="scss">
  279. @import url("../utils/navBar.scss");
  280. * {
  281. margin: 0;
  282. padding: 0;
  283. }
  284. img {
  285. display: block;
  286. }
  287. .page {
  288. // background-color: #fff;
  289. box-sizing: border-box;
  290. .courseContent {
  291. // padding: 0 0.2rem;
  292. // margin-top: 0.3rem;
  293. position: relative;
  294. .previewImg {
  295. // border-radius: 0.1rem;
  296. overflow: hidden;
  297. img {
  298. width: 100%;
  299. // height: 4rem;
  300. overflow: hidden;
  301. display: block;
  302. }
  303. }
  304. .title {
  305. padding: 0 0.2rem 0.2rem;
  306. background-color: #fff;
  307. margin-bottom: 0.2rem;
  308. span {
  309. font-size: 0.35rem;
  310. font-weight: 600;
  311. color: red;
  312. line-height: 0.8rem;
  313. }
  314. p {
  315. font-size: 0.32rem;
  316. font-weight: 600;
  317. color: #000;
  318. line-height: 0.4rem;
  319. margin-bottom: 0.2rem;
  320. /* white-space: pre-wrap; */
  321. /* overflow: hidden; */
  322. /* text-overflow: ellipsis; */
  323. /* white-space: nowrap; */
  324. /* word-break: break-all; */
  325. width: 100%;
  326. word-wrap: break-word;
  327. }
  328. i {
  329. font-size: 0.22rem;
  330. color: #888;
  331. line-height: 0.3rem;
  332. font-style: normal;
  333. }
  334. }
  335. .tabs {
  336. height: calc(100vh - 0.92rem);
  337. position: relative;
  338. .toTop {
  339. width: 1rem;
  340. height: 1rem;
  341. background-color: #ccc;
  342. border-radius: 50%;
  343. overflow: hidden;
  344. text-align: center;
  345. position: absolute;
  346. right: 0.4rem;
  347. bottom: 0.4rem;
  348. z-index: 999;
  349. span {
  350. font-size: 0.48rem;
  351. color: #fff;
  352. line-height: 1rem;
  353. }
  354. }
  355. .images {
  356. // margin-top: 0.1rem;
  357. img {
  358. width: 100%;
  359. }
  360. }
  361. .catelog {
  362. background: #fff;
  363. padding: 0.2rem;
  364. margin-top: 1px;
  365. border-top: 1px solid #efefef;
  366. position: relative;
  367. .sup {
  368. display: flex;
  369. justify-content: space-between;
  370. align-items: center;
  371. span {
  372. font-size: 0.24rem;
  373. color: #666;
  374. line-height: 3;
  375. margin-left: 0.1rem;
  376. }
  377. }
  378. .logConetent {
  379. .logLi {
  380. border: 1px solid #efefef;
  381. border-radius: 0.1rem;
  382. padding: 0 0.2rem;
  383. margin-bottom: 0.15rem;
  384. p {
  385. padding: 0.2rem 0;
  386. font-size: 0.3rem;
  387. color: #000;
  388. line-height: 1.3;
  389. // line-height: 3;
  390. // overflow: hidden;
  391. // text-overflow: ellipsis;
  392. // white-space: nowrap;
  393. // word-break: break-all;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. .getCourse {
  401. position: absolute;
  402. bottom: 0.1rem;
  403. left: 0.1rem;
  404. width: calc(100% - 0.2rem);
  405. .getBtn {
  406. width: 100%;
  407. background-color: #26a2ff;
  408. color: #fff;
  409. // animation: getFire 3s infinite linear;
  410. border-radius: 0.1rem;
  411. }
  412. }
  413. }
  414. @keyframes getFire {
  415. 0% {
  416. transform: scale(0.95);
  417. }
  418. 100% {
  419. transform: scale(1.05);
  420. }
  421. }
  422. </style>