BookListItem.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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]" @click="handleAction">
  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.$nextTick(() => {
  57. this.$emit('checked', { book: this.book, checked: value })
  58. })
  59. },
  60. handleAction() {
  61. this.$emit('action', this.book)
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .book-item {
  68. position: relative;
  69. width: calc((100vw - 80rpx) / 3);
  70. background-color: #ffffff;
  71. box-sizing: border-box;
  72. padding: 20rpx;
  73. display: flex;
  74. flex-direction: column;
  75. align-items: center;
  76. border-radius: 10rpx;
  77. .check-icon {
  78. position: absolute;
  79. left: 6rpx;
  80. top: 6rpx;
  81. z-index: 1;
  82. width: 32rpx;
  83. height: 32rpx;
  84. background: #38C148;
  85. border-radius: 50%;
  86. display: flex;
  87. align-items: center;
  88. justify-content: center;
  89. }
  90. .book-cover {
  91. width: 140rpx;
  92. height: 197rpx;
  93. border-radius: 8rpx;
  94. margin-bottom: 8rpx;
  95. }
  96. .book-info {
  97. width: 100%;
  98. .book-title {
  99. font-size: 24rpx;
  100. color: #333333;
  101. margin-bottom: 8rpx;
  102. display: -webkit-box;
  103. -webkit-box-orient: vertical;
  104. -webkit-line-clamp: 1;
  105. overflow: hidden;
  106. }
  107. .book-price {
  108. font-size: 22rpx;
  109. margin-bottom: 12rpx;
  110. font-family: Source Han Sans CN;
  111. font-weight: 400;
  112. font-size: 22rpx;
  113. color: #999999;
  114. text {
  115. color: #999999;
  116. &.price {
  117. color: #FF5B5B;
  118. }
  119. }
  120. }
  121. .action-btn {
  122. width: 100%;
  123. padding: 8rpx 0;
  124. font-size: 22rpx;
  125. border-radius: 8rpx;
  126. text-align: center;
  127. gap: 4rpx;
  128. &.pending {
  129. background: #38C148;
  130. color: #FFFFFF;
  131. }
  132. &.added {
  133. background: #ffffff;
  134. color: #38C148;
  135. border: 1px solid #38C148;
  136. }
  137. &.disabled {
  138. background: #F5F5F5;
  139. color: #999999;
  140. }
  141. }
  142. }
  143. ::v-deep .checkbox-item {
  144. position: absolute;
  145. right: 6rpx;
  146. top: 0;
  147. z-index: 9;
  148. .u-checkbox__label {
  149. margin: 0 !important;
  150. }
  151. }
  152. }
  153. </style>