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

243 lines
4.5 KiB

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