BookListItem.vue 4.2 KB

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