BookListItem.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="book-item">
  3. <!-- 书籍封面 -->
  4. <image class="book-cover" :src="book.cover" mode="aspectFill" />
  5. <!-- 书籍详情 -->
  6. <view class="book-info">
  7. <view class="book-title">{{ book.bookName }}</view>
  8. <view class="book-price">
  9. <text>回收价:</text>
  10. <text class="price">¥{{ book.recycleMoney }}</text>
  11. </view>
  12. <view class="action-btn" :class="statusMap[book.status]">
  13. <u-icon name="plus" size="16" v-if="book.status == 2"></u-icon>
  14. <text style="margin-left:6rpx">{{ getStatusText(book.status) }}</text>
  15. </view>
  16. </view>
  17. <!-- 选择框 -->
  18. <u-checkbox v-show="isEditMode" class="checkbox-item" v-model="book.selected" :name="book.isbn" shape="circle"
  19. active-color="#38C148" @change="updateCheckbox"></u-checkbox>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'BookListItem',
  25. props: {
  26. book: {
  27. type: Object,
  28. required: true
  29. },
  30. isEditMode: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data() {
  36. return {
  37. statusMap: {
  38. 1: "added",
  39. 2: 'pending',
  40. 3: 'disabled'
  41. }
  42. }
  43. },
  44. methods: {
  45. getStatusText(status) {
  46. // 1-已加入卖书清单 2-未加入 3-暂不回收
  47. let key = this.statusMap[status]
  48. const statusKey = {
  49. pending: '加入卖书清单',
  50. added: '已加入卖书清单',
  51. disabled: '暂不回收'
  52. }
  53. return statusKey[key] || key
  54. },
  55. updateCheckbox(value) {
  56. this.$set(this.book, 'selected', value)
  57. this.$emit('checked', this.book)
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .book-item {
  64. position: relative;
  65. width: calc((100vw - 80rpx) / 3);
  66. background-color: #ffffff;
  67. box-sizing: border-box;
  68. padding: 20rpx;
  69. display: flex;
  70. flex-direction: column;
  71. align-items: center;
  72. border-radius: 10rpx;
  73. .check-icon {
  74. position: absolute;
  75. left: 6rpx;
  76. top: 6rpx;
  77. z-index: 1;
  78. width: 32rpx;
  79. height: 32rpx;
  80. background: #38C148;
  81. border-radius: 50%;
  82. display: flex;
  83. align-items: center;
  84. justify-content: center;
  85. }
  86. .book-cover {
  87. width: 140rpx;
  88. height: 197rpx;
  89. border-radius: 8rpx;
  90. margin-bottom: 8rpx;
  91. }
  92. .book-info {
  93. width: 100%;
  94. .book-title {
  95. font-size: 24rpx;
  96. color: #333333;
  97. margin-bottom: 8rpx;
  98. display: -webkit-box;
  99. -webkit-box-orient: vertical;
  100. -webkit-line-clamp: 1;
  101. overflow: hidden;
  102. }
  103. .book-price {
  104. font-size: 22rpx;
  105. margin-bottom: 12rpx;
  106. font-family: Source Han Sans CN;
  107. font-weight: 400;
  108. font-size: 22rpx;
  109. color: #999999;
  110. text {
  111. color: #999999;
  112. &.price {
  113. color: #FF5B5B;
  114. }
  115. }
  116. }
  117. .action-btn {
  118. width: 100%;
  119. padding: 8rpx 0;
  120. font-size: 22rpx;
  121. border-radius: 8rpx;
  122. text-align: center;
  123. gap: 4rpx;
  124. &.pending {
  125. background: #38C148;
  126. color: #FFFFFF;
  127. }
  128. &.added {
  129. background: #ffffff;
  130. color: #38C148;
  131. border: 1px solid #38C148;
  132. }
  133. &.disabled {
  134. background: #F5F5F5;
  135. color: #999999;
  136. }
  137. }
  138. }
  139. ::v-deep .checkbox-item {
  140. position: absolute;
  141. right: 6rpx;
  142. top: 0;
  143. z-index: 9;
  144. .u-checkbox__label {
  145. margin: 0 !important;
  146. }
  147. }
  148. }
  149. </style>