ClassInfo.vue 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="class-box">
  3. <ratio-div class="thumb-banner" :ratio="0.6">
  4. <img width="100%" :src="ClassContent.thumb" alt />
  5. </ratio-div>
  6. <div class="summary">
  7. <div class="title">
  8. {{ClassContent.title}}
  9. </div>
  10. <div class="flex" style="margin-top: 16px">
  11. <div class="flex-1 subtitle">
  12. {{dateStr}}
  13. </div>
  14. <div class="flex-0" @click="handleFavor()">
  15. <span>
  16. <van-icon size="1.4em" :name="favor.icon" :color="favor.color" />
  17. </span>
  18. <span class="star-favor">{{favor.text}}</span>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="content-bar"></div>
  23. <div class="class-box-body">
  24. <img :src="ClassContent.content" alt />
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import { getCourseInfof, addCollection, deleteCollection } from '@/util/api'
  30. import { parseTime } from '@/util/formattingData'
  31. export default {
  32. components: {
  33. RatioDiv: () => import('@/components/RatioDiv/index.vue')
  34. },
  35. data() {
  36. return {
  37. ClassContent: {},
  38. isShoucang: false,
  39. courseIds: '',
  40. on: require('@/assets/Collection/on.png'),
  41. off: require('@/assets/Collection/off.png')
  42. }
  43. },
  44. computed: {
  45. dateStr() {
  46. if (!this.startDate || !this.endDate) return '课程时间: 暂无';
  47. const start = parseTime(this.startDate, '{y}-{m}-{d} {h}:{i}')
  48. const end = parseTime(this.endDate, '{y}-{m}-{d} {h}:{i}')
  49. return `课程时间: ${start} ~ ${end}`
  50. },
  51. favor() {
  52. const isFavored = this.ClassContent.isFavored || false
  53. return {
  54. icon: isFavored ? 'star' : 'star-o',
  55. color: isFavored ? '#2BB898' : '#000',
  56. text: isFavored?'已收藏':'收藏',
  57. }
  58. }
  59. },
  60. watch: {
  61. '$route.query.courseId': {
  62. handler(id) {
  63. this.onloadClass(id)
  64. },
  65. immediate: true
  66. }
  67. },
  68. methods: {
  69. onloadClass(id) {
  70. const courseId = id || this.$route.query.courseId;
  71. getCourseInfof(courseId).then((e) => {
  72. this.ClassContent = e
  73. if (e.isFavored) {
  74. this.isShoucang = true
  75. }
  76. console.log(e)
  77. })
  78. },
  79. handleFavor() {
  80. if (this.ClassContent.isFavored) {
  81. this.deleteColl()
  82. } else {
  83. this.collectionHande()
  84. }
  85. },
  86. collectionHande() {
  87. addCollection({
  88. targetId: this.$route.query.courseId,
  89. targetName: this.ClassContent.title,
  90. targetType: 'course'
  91. }).then((e) => {
  92. console.log(e)
  93. this.ClassContent.isFavored = true
  94. this.$toast('收藏成功')
  95. // this.onloadClass()
  96. })
  97. },
  98. deleteColl() {
  99. deleteCollection({
  100. targetId: this.$route.query.courseId,
  101. targetName: this.ClassContent.title,
  102. targetType: 'course'
  103. }).then((e) => {
  104. console.log(e)
  105. this.ClassContent.isFavored = false
  106. this.$toast('取消收藏成功')
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="less" scoped>
  113. .class-box {
  114. font-size: 14px;
  115. height: 100%;
  116. background: #fff;
  117. .summary {
  118. margin-top: -30px;
  119. font-size: 12px;
  120. color: #000;
  121. padding: 24px 2em 3em;
  122. background-color: #f9f9f9;
  123. box-sizing: border-box;
  124. border-top-left-radius: 30px;
  125. border-top-right-radius: 30px;
  126. position: relative;
  127. .title {
  128. font-size: 1.3em;
  129. // min-height: 2.6em;
  130. line-height: 1.4em;
  131. }
  132. .subtitle {
  133. color: rgb(133, 133, 133);
  134. }
  135. .star-favor {
  136. display: inline-block;
  137. margin-left: .6em;
  138. vertical-align: top;
  139. }
  140. }
  141. .content-bar {
  142. position: relative;
  143. margin-top: -1.5em;
  144. box-shadow: 0 0 4px 4px rgba(0, 0, 0, .08);
  145. border-top-left-radius: 30px;
  146. border-top-right-radius: 30px;
  147. height: 30px;
  148. background: #fff;
  149. }
  150. &-body {
  151. position: relative;
  152. background: #fff;
  153. padding: 0 2em 1em;
  154. > img {
  155. width: 100%;
  156. }
  157. }
  158. }
  159. </style>