敢为人鲜小程序前端代码仓库
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.

237 lines
4.6 KiB

3 months ago
  1. <template>
  2. <view class="instant-gift">
  3. <navbar title="立即送礼" leftClick @leftClick="$utils.navigateBack" />
  4. <!-- 主图片展示区 -->
  5. <view class="main-image">
  6. <image :src="selectedGift.image" mode="aspectFill"></image>
  7. </view>
  8. <!-- 礼品选择列表 -->
  9. <scroll-view scroll-x class="gift-list">
  10. <view
  11. class="gift-item"
  12. v-for="(item, index) in giftList"
  13. :key="index"
  14. :class="{ active: selectedIndex === index }"
  15. @click="selectGift(index)"
  16. >
  17. <image :src="item.image" mode="aspectFill"></image>
  18. <text class="gift-name">{{item.name}}</text>
  19. </view>
  20. </scroll-view>
  21. <!-- 祝福语区域 -->
  22. <view class="blessing-area">
  23. <view class="blessing-title">送祝福给TA</view>
  24. <view class="blessing-input">
  25. <input type="text" v-model="blessing" placeholder="蛇年到,福气绕。钱包满满当当!" />
  26. </view>
  27. </view>
  28. <!-- 底部区域 -->
  29. <view class="bottom-area">
  30. <view class="countdown">距离礼包失效{{countdownText}}</view>
  31. <button class="send-btn" @click="sendGift">立即送礼</button>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. selectedIndex: 0,
  40. blessing: '',
  41. countdown: 24 * 60 * 60, // 倒计时秒数
  42. countdownTimer: null,
  43. giftList: [
  44. {
  45. name: '蛇行大运',
  46. image: 'https://picb3.photophoto.cn/38/090/38090873_1.jpg'
  47. },
  48. {
  49. name: '蛇来运转',
  50. image: 'https://picb3.photophoto.cn/38/090/38090873_1.jpg'
  51. },
  52. {
  53. name: '2025',
  54. image: 'https://picb3.photophoto.cn/38/090/38090873_1.jpg'
  55. },
  56. {
  57. name: '身体健康',
  58. image: 'https://picb3.photophoto.cn/38/090/38090873_1.jpg'
  59. }
  60. ]
  61. }
  62. },
  63. computed: {
  64. selectedGift() {
  65. return this.giftList[this.selectedIndex]
  66. },
  67. countdownText() {
  68. const hours = Math.floor(this.countdown / 3600)
  69. const minutes = Math.floor((this.countdown % 3600) / 60)
  70. const seconds = this.countdown % 60
  71. return `${hours}${minutes}${seconds}`
  72. }
  73. },
  74. methods: {
  75. navigateBack() {
  76. uni.navigateBack()
  77. },
  78. selectGift(index) {
  79. this.selectedIndex = index
  80. },
  81. sendGift() {
  82. // 实现送礼逻辑
  83. uni.showToast({
  84. title: '送礼成功',
  85. icon: 'success'
  86. })
  87. },
  88. startCountdown() {
  89. this.countdownTimer = setInterval(() => {
  90. if (this.countdown > 0) {
  91. this.countdown--
  92. } else {
  93. clearInterval(this.countdownTimer)
  94. }
  95. }, 1000)
  96. }
  97. },
  98. mounted() {
  99. this.startCountdown()
  100. },
  101. beforeDestroy() {
  102. if (this.countdownTimer) {
  103. clearInterval(this.countdownTimer)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .instant-gift {
  110. min-height: 100vh;
  111. background: #fff;
  112. .nav-header {
  113. display: flex;
  114. align-items: center;
  115. height: 88rpx;
  116. padding: 0 30rpx;
  117. .back-icon, .more-icon {
  118. width: 60rpx;
  119. text-align: center;
  120. }
  121. .title {
  122. flex: 1;
  123. text-align: center;
  124. font-size: 32rpx;
  125. font-weight: 500;
  126. }
  127. }
  128. .main-image {
  129. width: 100%;
  130. height: 400rpx;
  131. image {
  132. width: 100%;
  133. height: 100%;
  134. }
  135. }
  136. .gift-list {
  137. padding: 30rpx;
  138. white-space: nowrap;
  139. .gift-item {
  140. display: inline-block;
  141. width: 200rpx;
  142. margin-right: 20rpx;
  143. text-align: center;
  144. position: relative;
  145. z-index: 1;
  146. border: 4rpx solid transparent;
  147. padding: 0 10rpx 10rpx 10rpx;
  148. &.active {
  149. position: relative;
  150. z-index: 2;
  151. border: 4rpx solid $uni-color;
  152. border-radius: 12rpx;
  153. }
  154. image {
  155. width: 100%;
  156. height: 200rpx;
  157. border-radius: 12rpx;
  158. }
  159. .gift-name {
  160. display: block;
  161. font-size: 28rpx;
  162. margin-top: 10rpx;
  163. }
  164. }
  165. }
  166. .blessing-area {
  167. padding: 30rpx;
  168. .blessing-title {
  169. font-size: 30rpx;
  170. color: #666;
  171. margin-bottom: 20rpx;
  172. }
  173. .blessing-input {
  174. background: #FFF5F5;
  175. padding: 20rpx;
  176. border-radius: 12rpx;
  177. border: 2rpx solid #FFE0E0;
  178. input {
  179. width: 100%;
  180. height: 60rpx;
  181. color: #333;
  182. font-size: 28rpx;
  183. }
  184. }
  185. }
  186. .bottom-area {
  187. position: fixed;
  188. left: 0;
  189. bottom: 0;
  190. width: 100%;
  191. box-sizing: border-box;
  192. padding: 20rpx 30rpx calc(30rpx + env(safe-area-inset-bottom)) 30rpx;
  193. background: #fff;
  194. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  195. z-index: 10;
  196. .countdown {
  197. text-align: center;
  198. font-size: 28rpx;
  199. color: #666;
  200. margin-bottom: 20rpx;
  201. font-weight: 500;
  202. }
  203. .send-btn {
  204. width: calc(100%);
  205. height: 88rpx;
  206. line-height: 88rpx;
  207. background: linear-gradient(to right, #FF4B4B, $uni-color);
  208. color: #fff;
  209. border-radius: 44rpx;
  210. font-size: 32rpx;
  211. font-weight: 500;
  212. }
  213. }
  214. }
  215. </style>