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

305 lines
6.8 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month 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.title}}</text>
  19. </view>
  20. </scroll-view>
  21. <!-- 祝福语区域 -->
  22. <view class="blessing-area">
  23. <view class="blessing-header">
  24. <view class="blessing-title">送祝福给TA</view>
  25. <view class="refresh-btn" @click="getRiceBlessingWords">
  26. <uv-icon name="reload" size="32" color="#666"></uv-icon>
  27. <text>换一个</text>
  28. </view>
  29. </view>
  30. <view class="blessing-input">
  31. <input type="text" v-model="blessing" :placeholder="giveTitle" />
  32. </view>
  33. </view>
  34. <!-- 底部区域 -->
  35. <view class="bottom-area">
  36. <!-- <view class="countdown">距离礼包失效{{countdownText}}</view> -->
  37. <button class="send-btn"
  38. open-type="share"
  39. @click="submit">立即送礼</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. selectedIndex: 0,
  48. blessing: '',
  49. countdown: 24 * 60 * 60, // 倒计时秒数
  50. countdownTimer: null,
  51. giftList: [],
  52. giveTitle : '',
  53. id : 0,
  54. }
  55. },
  56. computed: {
  57. selectedGift() {
  58. return this.giftList[this.selectedIndex]
  59. },
  60. countdownText() {
  61. const hours = Math.floor(this.countdown / 3600)
  62. const minutes = Math.floor((this.countdown % 3600) / 60)
  63. const seconds = this.countdown % 60
  64. return `${hours}${minutes}${seconds}`
  65. }
  66. },
  67. onShareAppMessage(res) {
  68. let o = {
  69. title : this.blessing || this.giveTitle,
  70. path : '/pages_order/order/receiveGift?id=' + this.id,
  71. imageUrl : this.giftList[this.selectedIndex].image,
  72. }
  73. if(this.userInfo.id){
  74. o.path = this.Gshare.path + '?shareId=' + this.userInfo.id
  75. }
  76. return o
  77. },
  78. //2.分享到朋友圈
  79. onShareTimeline(res) {
  80. let o = {
  81. title : this.blessing || this.giveTitle,
  82. path : '/pages_order/order/receiveGift?id=' + this.id,
  83. imageUrl : this.giftList[this.selectedIndex].image,
  84. }
  85. if(this.userInfo.id){
  86. o.path = this.Gshare.path + '?shareId=' + this.userInfo.id
  87. }
  88. return o
  89. },
  90. methods: {
  91. navigateBack() {
  92. uni.navigateBack()
  93. },
  94. selectGift(index) {
  95. this.selectedIndex = index
  96. },
  97. sendGift() {
  98. // 实现送礼逻辑
  99. uni.showToast({
  100. title: '送礼成功',
  101. icon: 'success'
  102. })
  103. },
  104. // 获取祝福背景图
  105. getRiceBlessing(){
  106. this.$api('getRiceBlessing')
  107. .then(res => {
  108. if(res.code == 200){
  109. this.giftList = res.result
  110. }
  111. })
  112. },
  113. // 随机获取祝福语
  114. getRiceBlessingWords(){
  115. this.$api('getRiceBlessingWords')
  116. .then(res => {
  117. if(res.code == 200){
  118. this.giveTitle = res.result
  119. }
  120. })
  121. },
  122. startCountdown() {
  123. this.countdownTimer = setInterval(() => {
  124. if (this.countdown > 0) {
  125. this.countdown--
  126. } else {
  127. clearInterval(this.countdownTimer)
  128. }
  129. }, 1000)
  130. },
  131. submit(){
  132. this.$api('updateOrderBlessing', {
  133. orderId : this.id,
  134. giveTitle : this.blessing || this.giveTitle,
  135. giveImage : this.giftList[this.selectedIndex].image,
  136. }).then(res => {
  137. if(res.code == 200){
  138. // 调用微信小程序转发功能
  139. }
  140. })
  141. },
  142. },
  143. onLoad(args){
  144. this.id = args.id
  145. },
  146. mounted() {
  147. // this.startCountdown()
  148. this.getRiceBlessing()
  149. this.getRiceBlessingWords()
  150. },
  151. beforeDestroy() {
  152. if (this.countdownTimer) {
  153. clearInterval(this.countdownTimer)
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .instant-gift {
  160. min-height: 100vh;
  161. background: #fff;
  162. .nav-header {
  163. display: flex;
  164. align-items: center;
  165. height: 88rpx;
  166. padding: 0 30rpx;
  167. .back-icon, .more-icon {
  168. width: 60rpx;
  169. text-align: center;
  170. }
  171. .title {
  172. flex: 1;
  173. text-align: center;
  174. font-size: 32rpx;
  175. font-weight: 500;
  176. }
  177. }
  178. .main-image {
  179. width: 100%;
  180. height: 400rpx;
  181. image {
  182. width: 100%;
  183. height: 100%;
  184. }
  185. }
  186. .gift-list {
  187. padding: 30rpx;
  188. white-space: nowrap;
  189. .gift-item {
  190. display: inline-block;
  191. width: 200rpx;
  192. margin-right: 20rpx;
  193. text-align: center;
  194. position: relative;
  195. z-index: 1;
  196. border: 4rpx solid transparent;
  197. padding: 0 10rpx 10rpx 10rpx;
  198. &.active {
  199. position: relative;
  200. z-index: 2;
  201. border: 4rpx solid $uni-color;
  202. border-radius: 12rpx;
  203. }
  204. image {
  205. width: 100%;
  206. height: 200rpx;
  207. border-radius: 12rpx;
  208. }
  209. .gift-name {
  210. display: block;
  211. font-size: 28rpx;
  212. margin-top: 10rpx;
  213. }
  214. }
  215. }
  216. .blessing-area {
  217. padding: 30rpx;
  218. .blessing-header {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. margin-bottom: 20rpx;
  223. .blessing-title {
  224. font-size: 30rpx;
  225. color: #666;
  226. }
  227. .refresh-btn {
  228. display: flex;
  229. align-items: center;
  230. color: #666;
  231. font-size: 26rpx;
  232. text {
  233. margin-left: 6rpx;
  234. }
  235. }
  236. }
  237. .blessing-input {
  238. background: #FFF5F5;
  239. padding: 20rpx;
  240. border-radius: 12rpx;
  241. border: 2rpx solid #FFE0E0;
  242. input {
  243. width: 100%;
  244. height: 60rpx;
  245. color: #333;
  246. font-size: 28rpx;
  247. }
  248. }
  249. }
  250. .bottom-area {
  251. position: fixed;
  252. left: 0;
  253. bottom: 0;
  254. width: 100%;
  255. box-sizing: border-box;
  256. padding: 20rpx 30rpx calc(30rpx + env(safe-area-inset-bottom)) 30rpx;
  257. background: #fff;
  258. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  259. z-index: 10;
  260. .countdown {
  261. text-align: center;
  262. font-size: 28rpx;
  263. color: #666;
  264. margin-bottom: 20rpx;
  265. font-weight: 500;
  266. }
  267. .send-btn {
  268. width: calc(100%);
  269. height: 88rpx;
  270. line-height: 88rpx;
  271. background: linear-gradient(to right, #FF4B4B, $uni-color);
  272. color: #fff;
  273. border-radius: 44rpx;
  274. font-size: 32rpx;
  275. font-weight: 500;
  276. }
  277. }
  278. }
  279. </style>