BookLiveCard.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div>
  3. <el-skeleton style="width: 282px" :loading="true" animated v-if="item.skeleton">
  4. <template slot="template">
  5. <el-skeleton-item
  6. variant="image"
  7. style="width: 282px; height: 174px;"
  8. />
  9. <div style="padding: 8px 8px 16px 8px;width: 282px;">
  10. <el-skeleton-item variant="h3" style="width: 100%; height: 24px" />
  11. <el-skeleton-item variant="text" style="margin: 4px 0 12px 0; height: 20px; width:50%;" />
  12. <el-skeleton-item variant="text" style="height: 24px; width:70%;" />
  13. </div>
  14. </template>
  15. </el-skeleton>
  16. <div class="BookCard" v-else @click="handleLink">
  17. <el-image
  18. class="image"
  19. :src="item.cover_image_url?item.cover_image_url:item.course_type==='baozhi'?require('../../assets/baozhi'+(Math.floor(Math.random()*2)+1)+'.png'):require('../../assets/kecheng'+(Math.floor(Math.random()*3)+1)+'.png')"
  20. :fit="'cover'">
  21. </el-image>
  22. <div class="bottom">
  23. <p class="name">{{item.name}}</p>
  24. <div class="live-box">
  25. <img src="../../assets/icon-live.png" />
  26. <p>直播{{item.begin_time}}</p>
  27. </div>
  28. <template>
  29. <p class="price">
  30. <span class="OPPOSans">¥{{item.hasOwnProperty('price_discount')?item.price_discount:item.price|cutMoneyFiter}}</span>
  31. <s v-if="item.hasOwnProperty('price_discount')&&item.price_discount!==item.price">¥{{item.price|cutMoneyFiter}}</s>
  32. </p>
  33. </template>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  40. //例如:import 《组件名称》from ‘《组件路径》';
  41. import { cutMoneyFiter } from '@/utils/defined';
  42. export default {
  43. name: "BookCard",
  44. //import引入的组件需要注入到对象中才能使用
  45. components: {},
  46. props: ["item", "height"],
  47. filters:{
  48. cutMoneyFiter
  49. },
  50. data() {
  51. //这里存放数据
  52. return {
  53. colors: ['#EA5939', '#EA5939', '#EA5939'],
  54. dataContext: [
  55. { "houseId": 1, "date": "2023-02-25", "weight": 150, "rate": 1.5 },
  56. { "houseId": 1, "date": "2023-02-26", "weight": 200, "rate": 1.5 },
  57. { "houseId": 1, "date": "2023-02-24", "weight": 50, "rate": 1.5 },
  58. { "houseId": 1, "date": "2023-02-27", "weight": 300, "rate": 1.5 },
  59. { "houseId": 2, "date": "2023-02-25", "weight": 100, "rate": 3.6 },
  60. { "houseId": 2, "date": "2023-02-26", "weight": 500, "rate": 7.9 },
  61. { "houseId": 3, "date": "2023-02-25", "weight": 80, "rate": 7.9 },
  62. { "houseId": 3, "date": "2023-02-26", "weight": 200, "rate": 7.9 }
  63. ]
  64. }
  65. },
  66. //计算属性 类似于data概念
  67. computed: {
  68. score() {
  69. return this.item.score.toFixed(1)
  70. }
  71. },
  72. //监控data中数据变化
  73. watch: {},
  74. //方法集合
  75. methods: {
  76. changeData(data) {
  77. var datasort = data.sort((a, b) => a.date.localeCompare(b.date));// 大重_-----Set 中的元素只会出现一次
  78. var timeArr = new Set(datasort.map(it => it.date))
  79. let newarr = []
  80. let rateArr = []
  81. timeArr.forEach(item => {
  82. let a = {
  83. date: "",
  84. arr: []
  85. }
  86. data.forEach(items => {
  87. if (item == items.date) {
  88. a.date = items.date
  89. a.arr.push(items.weight)
  90. rateArr.push(items.rate)
  91. }
  92. })
  93. newarr.push(a)
  94. })
  95. newarr.forEach(item => {
  96. if (item.arr.length < 3) {
  97. for (let i = 0; i < 3 - (item.arr.length - 1); i++) {
  98. item.arr.push(0)
  99. }
  100. }
  101. })
  102. return { newarr, timeArr, rateArr }
  103. },
  104. handleLink(){
  105. window.open(this.item.url)
  106. }
  107. },
  108. //生命周期 - 创建完成(可以访问当前this实例)
  109. created() {
  110. // let data = this.changeData(this.dataContext)
  111. },
  112. //生命周期 - 挂载完成(可以访问DOM元素)
  113. mounted() {
  114. },
  115. //生命周期-创建之前
  116. beforeCreated() { },
  117. //生命周期-挂载之前
  118. beforeMount() { },
  119. //生命周期-更新之前
  120. beforUpdate() { },
  121. //生命周期-更新之后
  122. updated() { },
  123. //生命周期-销毁之前
  124. beforeDestory() { },
  125. //生命周期-销毁完成
  126. destoryed() { },
  127. //如果页面有keep-alive缓存功能,这个函数会触发
  128. activated() { }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. /* @import url(); 引入css类 */
  133. .BookCard {
  134. width: 100%;
  135. cursor: pointer;
  136. .image {
  137. width: 100%;
  138. height: 174px;
  139. }
  140. .bottom {
  141. // height: 132px;
  142. padding: 8px 8px 16px 8px
  143. }
  144. p {
  145. margin: 0;
  146. padding: 0;
  147. }
  148. .name {
  149. width: 100%;
  150. font-weight: 400;
  151. font-size: 16px;
  152. line-height: 24px;
  153. color: #2F3742;
  154. white-space: nowrap;
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. }
  158. .live-box{
  159. background: #E8FFEA;
  160. border-radius: 2px;
  161. display: flex;
  162. align-items: center;
  163. padding: 0 8px;
  164. margin-top: 4px;
  165. width: max-content;
  166. img{
  167. width: 12px;
  168. margin-right: 4px;
  169. }
  170. p{
  171. font-weight: 500;
  172. font-size: 12px;
  173. line-height: 20px;
  174. color: #00B42A;
  175. margin: 0;
  176. }
  177. }
  178. .price {
  179. margin-top: 12px;
  180. display: flex;
  181. align-items: flex-end;
  182. :nth-child(1) {
  183. font-weight: 700;
  184. font-size: 16px;
  185. line-height: 24px;
  186. color: #EC5E41;
  187. }
  188. :nth-child(2) {
  189. font-weight: 400;
  190. font-size: 14px;
  191. line-height: 22px;
  192. text-decoration-line: line-through;
  193. color: #929CA8;
  194. margin-left: 8px;
  195. }
  196. }
  197. }
  198. </style>