book-list-item.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="book-item" @click="handleClick">
  3. <!-- 书籍封面 -->
  4. <image class="book-cover" :src="book.cover" mode="aspectFill" />
  5. <!-- 书籍详情 -->
  6. <view class="book-info">
  7. <view class="book-title">{{ book.bookName || book.name }}</view>
  8. <view class="book-price">
  9. <view class="sale-price">
  10. <text class="symbol">¥</text>
  11. <text class="amount">{{ book.price || book.recycleMoney }}</text>
  12. </view>
  13. <text class="origin-price" v-if="book.producePrice">¥{{ book.producePrice }}</text>
  14. </view>
  15. </view>
  16. <!-- 选择框 -->
  17. <view class="checkbox-item" v-if="isEditMode" @click.stop>
  18. <u-checkbox v-show="isEditMode" class="checkbox-item" v-model="book.selected" :name="book.isbn"
  19. shape="circle" label-size="0" active-color="#38C148" @change="updateCheckbox"></u-checkbox>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'BookListItem',
  26. props: {
  27. book: {
  28. type: Object,
  29. required: true
  30. },
  31. isEditMode: {
  32. type: Boolean,
  33. default: false
  34. }
  35. },
  36. methods: {
  37. updateCheckbox({ value }) {
  38. this.$nextTick(() => {
  39. this.$emit('checked', { book: this.book, checked: value })
  40. })
  41. },
  42. handleClick() {
  43. if (this.isEditMode) {
  44. // 编辑模式下点击整个卡片也切换选中状态
  45. this.book.selected = !this.book.selected;
  46. this.updateCheckbox({ value: this.book.selected });
  47. return;
  48. }
  49. this.$emit('click', this.book);
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .book-item {
  56. position: relative;
  57. width: calc((100vw - 80rpx) / 3);
  58. background-color: #ffffff;
  59. box-sizing: border-box;
  60. padding: 20rpx;
  61. display: flex;
  62. flex-direction: column;
  63. align-items: center;
  64. border-radius: 10rpx;
  65. height: 100%;
  66. padding-bottom: 10rpx;
  67. .check-icon {
  68. position: absolute;
  69. left: 6rpx;
  70. top: 6rpx;
  71. z-index: 1;
  72. width: 32rpx;
  73. height: 32rpx;
  74. background: #38C148;
  75. border-radius: 50%;
  76. display: flex;
  77. align-items: center;
  78. justify-content: center;
  79. }
  80. .book-cover {
  81. width: 140rpx;
  82. height: 197rpx;
  83. border-radius: 8rpx;
  84. margin-bottom: 8rpx;
  85. }
  86. .book-info {
  87. width: 100%;
  88. .book-title {
  89. font-size: 24rpx;
  90. color: #333333;
  91. margin-bottom: 8rpx;
  92. display: -webkit-box;
  93. -webkit-box-orient: vertical;
  94. -webkit-line-clamp: 1;
  95. overflow: hidden;
  96. margin-top: 15rpx;
  97. }
  98. .book-price {
  99. margin-bottom: 12rpx;
  100. font-family: Source Han Sans CN;
  101. display: flex;
  102. align-items: baseline;
  103. .sale-price {
  104. color: #FF5B5B;
  105. margin-right: 12rpx;
  106. display: flex;
  107. align-items: baseline;
  108. font-weight: bold;
  109. .symbol {
  110. font-size: 24rpx;
  111. margin-right: 2rpx;
  112. }
  113. .amount {
  114. font-size: 32rpx;
  115. line-height: 1;
  116. }
  117. }
  118. .origin-price {
  119. font-size: 24rpx;
  120. color: #999999;
  121. text-decoration: line-through;
  122. }
  123. }
  124. }
  125. .checkbox-item {
  126. position: absolute;
  127. right: 6rpx;
  128. top: 0;
  129. z-index: 9;
  130. ::v-deep .u-checkbox__label {
  131. margin: 0 !important;
  132. }
  133. }
  134. }
  135. </style>