小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.4 KiB

  1. <template>
  2. <!-- 礼物盒页面 -->
  3. <view class="giftbox-container">
  4. <!-- 顶部标题栏 -->
  5. <uv-navbar title="礼物盒" :autoBack="true" fixed placeholder rightIcon="more-dot-fill">
  6. <template #left>
  7. <BackArrow :size="56" color="#333" />
  8. </template>
  9. </uv-navbar>
  10. <!-- 礼物列表 -->
  11. <view class="gift-list">
  12. <view
  13. v-for="(gift, idx) in gifts"
  14. :key="gift.id"
  15. :class="['gift-item', { selected: idx === selectedIndex }]"
  16. @click="selectGift(idx)"
  17. >
  18. <view class="gift-img">
  19. <text class="gift-emoji">{{ gift.emoji }}</text>
  20. </view>
  21. <view class="gift-name">{{ gift.name }}</view>
  22. <view class="gift-info">
  23. <text class="gift-count">x{{ gift.count }}</text>
  24. <text class="gift-bean">{{ gift.price }}豆豆</text>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 底部操作栏 -->
  29. <view class="giftbox-bottom">
  30. <view class="giftbox-left">剩余{{ gifts[selectedIndex].count }} </view>
  31. <view class="giftbox-buy">
  32. <button class="buy-btn" @click="buyGift">购买</button>
  33. <uv-number-box v-model="buyCount" :min="1" :max="gifts[selectedIndex].count" />
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import BackArrow from './components/BackArrow.vue';
  40. export default {
  41. components: {
  42. 'uv-navbar': () => import('@/uni_modules/uv-navbar/components/uv-navbar/uv-navbar.vue'),
  43. 'uv-number-box': () => import('@/uni_modules/uv-number-box/components/uv-number-box/uv-number-box.vue'),
  44. BackArrow
  45. },
  46. data() {
  47. return {
  48. gifts: [
  49. { id: 1, name: '小星星', emoji: '🌟', count: 6, price: 1 },
  50. { id: 2, name: '爱你哟', emoji: '🧡', count: 5, price: 1 },
  51. { id: 3, name: '加油鸭', emoji: '🦆', count: 5, price: 1 },
  52. { id: 4, name: '蓝色烟花', emoji: '🎆', count: 5, price: 1 },
  53. { id: 5, name: '沙滩椅', emoji: '🏖️', count: 5, price: 1 },
  54. { id: 6, name: '菠萝', emoji: '🍍', count: 5, price: 1 },
  55. { id: 7, name: '咖啡', emoji: '☕', count: 5, price: 1 },
  56. { id: 8, name: '早餐', emoji: '🥐', count: 5, price: 1 },
  57. { id: 9, name: '花花', emoji: '🌷', count: 5, price: 1 },
  58. { id: 10, name: '玫瑰', emoji: '🌹', count: 5, price: 1 },
  59. { id: 11, name: '玫瑰花', emoji: '🥀', count: 5, price: 1 },
  60. { id: 12, name: '跑车', emoji: '🏎️', count: 5, price: 1 },
  61. ],
  62. selectedIndex: 0,
  63. buyCount: 1,
  64. }
  65. },
  66. methods: {
  67. selectGift(idx) {
  68. this.selectedIndex = idx
  69. this.buyCount = 1
  70. },
  71. buyGift() {
  72. // 跳转到礼物购买页面,并传递选中礼物信息
  73. const gift = this.gifts[this.selectedIndex]
  74. uni.navigateTo({
  75. url: `/pages_order/novel/Giftpurchases?name=${encodeURIComponent(gift.name)}&price=${gift.price}&count=${this.buyCount}`
  76. })
  77. },
  78. },
  79. }
  80. </script>
  81. <style scoped lang="scss">
  82. .giftbox-container {
  83. min-height: 100vh;
  84. background: #f8f8f8;
  85. padding-bottom: 120rpx;
  86. }
  87. .gift-list {
  88. display: flex;
  89. flex-wrap: wrap;
  90. gap: 24rpx;
  91. padding: 32rpx 16rpx 0 16rpx;
  92. }
  93. .gift-item {
  94. width: 30%;
  95. background: #fff;
  96. border-radius: 18rpx;
  97. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.03);
  98. margin-bottom: 24rpx;
  99. display: flex;
  100. flex-direction: column;
  101. align-items: center;
  102. padding: 24rpx 0 16rpx 0;
  103. border: 2rpx solid transparent;
  104. transition: border 0.2s;
  105. }
  106. .gift-item.selected {
  107. border: 2rpx solid #223a7a;
  108. box-shadow: 0 4rpx 16rpx 0 rgba(34,58,122,0.08);
  109. }
  110. .gift-img {
  111. width: 80rpx;
  112. height: 80rpx;
  113. display: flex;
  114. align-items: center;
  115. justify-content: center;
  116. margin-bottom: 8rpx;
  117. }
  118. .gift-emoji {
  119. font-size: 56rpx;
  120. }
  121. .gift-name {
  122. font-size: 28rpx;
  123. color: #222;
  124. margin-bottom: 4rpx;
  125. }
  126. .gift-info {
  127. display: flex;
  128. align-items: center;
  129. gap: 8rpx;
  130. font-size: 22rpx;
  131. color: #888;
  132. }
  133. .giftbox-bottom {
  134. position: fixed;
  135. left: 0;
  136. right: 0;
  137. bottom: 90rpx;
  138. background: #fff;
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. height: 100rpx;
  143. padding: 0 32rpx;
  144. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  145. z-index: 10;
  146. }
  147. .giftbox-left {
  148. font-size: 28rpx;
  149. color: #666;
  150. }
  151. .giftbox-buy {
  152. display: flex;
  153. align-items: center;
  154. gap: 18rpx;
  155. }
  156. .buy-btn {
  157. background: #223a7a;
  158. color: #fff;
  159. font-size: 28rpx;
  160. border-radius: 32rpx;
  161. padding: 0 36rpx;
  162. height: 68rpx;
  163. line-height: 68rpx;
  164. border: none;
  165. }
  166. </style>