珠宝小程序前端代码
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.

293 lines
6.6 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 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.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. return this.getShareData(res)
  69. },
  70. //2.分享到朋友圈
  71. onShareTimeline(res) {
  72. return this.getShareData(res)
  73. },
  74. methods: {
  75. getShareData(res){
  76. let o = {
  77. title : `${this.configList.logo_name}用户${this.userInfo.nickName}挑选了1份礼物送给你,请收下这份心意`,
  78. path : '/pages_order/order/receiveGift?id=' + this.id,
  79. imageUrl : this.giftList[this.selectedIndex].image,
  80. }
  81. if(this.userInfo.id){
  82. o.path += '&shareId=' + this.userInfo.id
  83. }
  84. return o
  85. },
  86. navigateBack() {
  87. uni.navigateBack()
  88. },
  89. selectGift(index) {
  90. this.selectedIndex = index
  91. },
  92. // 获取祝福背景图
  93. getRiceBlessing(){
  94. this.$api('getRiceBlessing')
  95. .then(res => {
  96. if(res.code == 200){
  97. this.giftList = res.result
  98. }
  99. })
  100. },
  101. // 随机获取祝福语
  102. getRiceBlessingWords(){
  103. this.$api('getRiceBlessingWords')
  104. .then(res => {
  105. if(res.code == 200){
  106. this.giveTitle = res.result
  107. }
  108. })
  109. },
  110. startCountdown() {
  111. this.countdownTimer = setInterval(() => {
  112. if (this.countdown > 0) {
  113. this.countdown--
  114. } else {
  115. clearInterval(this.countdownTimer)
  116. }
  117. }, 1000)
  118. },
  119. submit(){
  120. this.$api('updateOrderBlessing', {
  121. orderId : this.id,
  122. giveTitle : this.blessing || this.giveTitle,
  123. giveImage : this.giftList[this.selectedIndex].image,
  124. }).then(res => {
  125. if(res.code == 200){
  126. // 调用微信小程序转发功能
  127. }
  128. })
  129. },
  130. },
  131. onLoad(args){
  132. this.id = args.id
  133. },
  134. mounted() {
  135. // this.startCountdown()
  136. this.getRiceBlessing()
  137. this.getRiceBlessingWords()
  138. },
  139. beforeDestroy() {
  140. if (this.countdownTimer) {
  141. clearInterval(this.countdownTimer)
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .instant-gift {
  148. min-height: 100vh;
  149. background: #fff;
  150. .nav-header {
  151. display: flex;
  152. align-items: center;
  153. height: 88rpx;
  154. padding: 0 30rpx;
  155. .back-icon, .more-icon {
  156. width: 60rpx;
  157. text-align: center;
  158. }
  159. .title {
  160. flex: 1;
  161. text-align: center;
  162. font-size: 32rpx;
  163. font-weight: 500;
  164. }
  165. }
  166. .main-image {
  167. width: 100%;
  168. height: 400rpx;
  169. image {
  170. width: 100%;
  171. height: 100%;
  172. }
  173. }
  174. .gift-list {
  175. padding: 30rpx;
  176. white-space: nowrap;
  177. .gift-item {
  178. display: inline-block;
  179. width: 200rpx;
  180. margin-right: 20rpx;
  181. text-align: center;
  182. position: relative;
  183. z-index: 1;
  184. border: 4rpx solid transparent;
  185. padding: 0 10rpx 10rpx 10rpx;
  186. &.active {
  187. position: relative;
  188. z-index: 2;
  189. border: 4rpx solid $uni-color;
  190. border-radius: 12rpx;
  191. }
  192. image {
  193. width: 100%;
  194. height: 200rpx;
  195. border-radius: 12rpx;
  196. }
  197. .gift-name {
  198. display: block;
  199. font-size: 28rpx;
  200. margin-top: 10rpx;
  201. }
  202. }
  203. }
  204. .blessing-area {
  205. padding: 30rpx;
  206. .blessing-header {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. margin-bottom: 20rpx;
  211. .blessing-title {
  212. font-size: 30rpx;
  213. color: #666;
  214. }
  215. .refresh-btn {
  216. display: flex;
  217. align-items: center;
  218. color: #666;
  219. font-size: 26rpx;
  220. text {
  221. margin-left: 6rpx;
  222. }
  223. }
  224. }
  225. .blessing-input {
  226. background: #FFF5F5;
  227. padding: 20rpx;
  228. border-radius: 12rpx;
  229. border: 2rpx solid #FFE0E0;
  230. input {
  231. width: 100%;
  232. height: 60rpx;
  233. color: #333;
  234. font-size: 28rpx;
  235. }
  236. }
  237. }
  238. .bottom-area {
  239. position: fixed;
  240. left: 0;
  241. bottom: 0;
  242. width: 100%;
  243. box-sizing: border-box;
  244. padding: 20rpx 30rpx calc(30rpx + env(safe-area-inset-bottom)) 30rpx;
  245. background: #fff;
  246. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  247. z-index: 10;
  248. .countdown {
  249. text-align: center;
  250. font-size: 28rpx;
  251. color: #666;
  252. margin-bottom: 20rpx;
  253. font-weight: 500;
  254. }
  255. .send-btn {
  256. width: calc(100%);
  257. height: 88rpx;
  258. line-height: 88rpx;
  259. background: linear-gradient(to right, #FF4B4B, $uni-color);
  260. color: #fff;
  261. border-radius: 44rpx;
  262. font-size: 32rpx;
  263. font-weight: 500;
  264. }
  265. }
  266. }
  267. </style>