小说小程序前端代码仓库(小程序)
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.

166 lines
4.3 KiB

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