courseDeal.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div class="page">
  3. <van-nav-bar
  4. :title="title"
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. ></van-nav-bar>
  9. <div class="courseContent">
  10. <div class="previewImg">
  11. <img :src="courseDetail.thumb" />
  12. </div>
  13. <div class="title">
  14. <p>{{ courseDetail.name }}</p>
  15. </div>
  16. <div class="tabs">
  17. <scroller ref="scroller">
  18. <van-tabs v-model="activeTab" swipeable>
  19. <van-tab title="课程目录">
  20. <div class="catelog">
  21. <div class="sup">
  22. <span>共{{ courseDetail.sections.length }}节课</span>
  23. </div>
  24. <div class="logConetent">
  25. <div
  26. class="logLi"
  27. v-for="(item, index) in courseDetail.sections"
  28. :key="index"
  29. @click="toSectionVidio(item, index)"
  30. >
  31. <p>{{ index + 1 }}、{{ item.name }}</p>
  32. </div>
  33. </div>
  34. </div>
  35. </van-tab>
  36. <van-tab title="课程介绍">
  37. <div class="images">
  38. <div
  39. class="descImage"
  40. v-for="(item, index) in courseDetail.images"
  41. :key="index"
  42. >
  43. <img :src="item" />
  44. </div>
  45. </div>
  46. </van-tab>
  47. </van-tabs>
  48. </scroller>
  49. </div>
  50. <div
  51. class="getCourse"
  52. v-if="!courseDetail.buy && codeDetail && codeDetail.enable"
  53. @click="useCode"
  54. >
  55. <van-button icon="fire-o" square class="getBtn"
  56. >点击领取课程名额</van-button
  57. >
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import {
  64. learnerCourseDetail,
  65. getCourseCodeDetail,
  66. getCourseCode,
  67. getVideoSrc
  68. } from "../api";
  69. export default {
  70. name: "",
  71. components: {},
  72. props: [],
  73. data() {
  74. return {
  75. loading: false,
  76. finished: false,
  77. activeTab: 0,
  78. title: "课程详情",
  79. courseDetail: {
  80. thumb: "",
  81. name: "",
  82. images: [],
  83. sections: [],
  84. buy: false
  85. },
  86. giveCode: false,
  87. codeDetail: {
  88. enable: true
  89. }
  90. };
  91. },
  92. created() {
  93. this.init();
  94. },
  95. methods: {
  96. useCode() {
  97. this.$dialog
  98. .confirm({
  99. title: "提示",
  100. message: "确定领取当前课程吗"
  101. })
  102. .then(() => {
  103. let data = {
  104. salesCode: this.codeDetail.salesCode,
  105. userId: this.codeDetail.userId,
  106. subjectId: this.codeDetail.subjectId
  107. };
  108. getCourseCode(data).then(res => {
  109. this.$toast.success("领取成功!");
  110. this.giveCode = true;
  111. this.getDetail();
  112. });
  113. });
  114. },
  115. getCodeDetail() {
  116. getCourseCodeDetail(this.$route.query.code).then(res => {
  117. this.codeDetail = res;
  118. if (res && !res.enable) {
  119. this.codeDetail.enable = false;
  120. this.$toast.fail("该分享码已失效");
  121. }
  122. });
  123. },
  124. getVideoLink(link){
  125. let data = {
  126. subjectId:this.$route.params.id,
  127. link:link
  128. }
  129. getVideoSrc(data).then(res=>{
  130. window.location.href = res
  131. })
  132. },
  133. toSectionVidio(item, index) {
  134. if (this.courseDetail.buy) {
  135. // this.getVideoLink(item.link)
  136. let data = {
  137. index: index,
  138. link: item.link
  139. };
  140. sessionStorage.setItem('vd_info',JSON.stringify(data))
  141. this.$router.push({
  142. path: `/course/video/${this.$route.params.id}`
  143. });
  144. } else {
  145. this.$toast.fail("请先领取课程后再观看");
  146. }
  147. },
  148. onClickLeft() {
  149. this.$router.push('/courseHome');
  150. },
  151. init() {
  152. this.courseId = this.$route.params.id;
  153. this.getDetail();
  154. if (this.$route.query && this.$route.query.code) {
  155. this.getCodeDetail();
  156. }
  157. },
  158. getDetail() {
  159. learnerCourseDetail(this.courseId).then(res => {
  160. this.courseDetail = res;
  161. if (
  162. this.courseDetail.buy &&
  163. this.$route.query &&
  164. this.$route.query.code &&
  165. !this.giveCode
  166. ) {
  167. this.$toast.fail("您已经购买课程,无需再次购买");
  168. }
  169. });
  170. }
  171. },
  172. computed: {}
  173. };
  174. </script>
  175. <style scoped lang="scss">
  176. * {
  177. margin: 0;
  178. padding: 0;
  179. }
  180. img {
  181. display: block;
  182. }
  183. .page {
  184. background-color: #fff;
  185. box-sizing: border-box;
  186. .courseContent {
  187. padding: 0 0.2rem;
  188. margin-top: 0.3rem;
  189. .previewImg {
  190. border-radius: 0.1rem;
  191. overflow: hidden;
  192. img {
  193. width: 100%;
  194. height: 4rem;
  195. }
  196. }
  197. .title {
  198. p {
  199. font-size: 0.32rem;
  200. font-weight: 600;
  201. color: #000;
  202. line-height: 1rem;
  203. overflow: hidden;
  204. text-overflow: ellipsis;
  205. white-space: nowrap;
  206. word-break: break-all;
  207. }
  208. }
  209. .tabs {
  210. height: calc(100vh - 6.25rem);
  211. position: relative;
  212. .images {
  213. margin-top: 0.1rem;
  214. img {
  215. width: 100%;
  216. }
  217. }
  218. .catelog {
  219. margin-top: 1px;
  220. border-top: 1px solid #ccc;
  221. .sup {
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. span {
  226. font-size: 0.24rem;
  227. color: #666;
  228. line-height: 3;
  229. }
  230. }
  231. .logConetent {
  232. .logLi {
  233. border: 1px solid #ccc;
  234. border-radius: 0.1rem;
  235. padding: 0 0.2rem;
  236. margin-bottom: 0.15rem;
  237. p {
  238. font-size: 0.3rem;
  239. color: #000;
  240. line-height: 3;
  241. overflow: hidden;
  242. text-overflow: ellipsis;
  243. white-space: nowrap;
  244. word-break: break-all;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. .getCourse {
  252. position: absolute;
  253. bottom: 0.1rem;
  254. left: 0.1rem;
  255. width: calc(100% - 0.2rem);
  256. .getBtn {
  257. width: 100%;
  258. background-color: #26a2ff;
  259. color: #fff;
  260. // animation: getFire 3s infinite linear;
  261. border-radius: 0.1rem;
  262. }
  263. }
  264. }
  265. @keyframes getFire {
  266. 0% {
  267. transform: scale(0.95);
  268. }
  269. 100% {
  270. transform: scale(1.05);
  271. }
  272. }
  273. </style>