get.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <view class="get-page">
  3. <root-back-home ref="rootBackHome" />
  4. <!-- Background -->
  5. <image src="/packet/static/get/bg.png" class="bg-image" mode="widthFix"></image>
  6. <!-- Main Content -->
  7. <view class="content-wrapper">
  8. <!-- Header -->
  9. <view class="header-section">
  10. <image src="/packet/static/get/text.png" class="header-logo" mode="widthFix"></image>
  11. </view>
  12. <!-- White Card -->
  13. <view class="white-card">
  14. <!-- Top Amount Row -->
  15. <view class="top-amount-row">
  16. <text class="received-text">¥{{ redBagData.redPrice || 0 }} 红包已到账</text>
  17. <view class="use-btn-wrapper" @click="handleUse">
  18. <text class="use-btn-text">点击使用</text>
  19. </view>
  20. </view>
  21. <!-- Promo Box -->
  22. <view class="promo-box">
  23. <image src="/packet/static/get/inner-box.png" class="inner-box-bg" mode="widthFix"></image>
  24. <view class="promo-content">
  25. <view class="promo-header">
  26. <text class="promo-amount"><text style="font-size: 30rpx;">¥</text>{{
  27. redBagData.shareSumPrice }}</text>
  28. </view>
  29. <text class="promo-desc">好友助力解锁更高金额</text>
  30. <text class="promo-detail">每邀请 1 位好友最高:你得<text class="highlight-red">¥{{
  31. redBagData.shareGetPrice }}红包</text>,好友得<text class="highlight-red">¥{{
  32. redBagData.shareDGetPrice }}</text>红包</text>
  33. </view>
  34. </view>
  35. <!-- Invite Button -->
  36. <button class="invite-btn-wrapper" open-type="share" @getuserinfo="handleInvite">
  37. <text class="invite-btn-text">立即邀请</text>
  38. </button>
  39. <!-- Red Packet Cards -->
  40. <view class="red-packets-section">
  41. <view class="packet-card" v-for="(item, index) in 3" :key="index">
  42. <text class="packet-text">邀请好友</text>
  43. <text class="packet-text">双方得红包</text>
  44. </view>
  45. </view>
  46. <!-- Progress Bar -->
  47. <view class="progress-section">
  48. <view class="progress-bar-bg">
  49. <view class="progress-bar-fill" :style="{ width: progressWidth + '%' }"></view>
  50. <image src="/packet/static/get/circle.png" class="progress-dot"
  51. :style="{ left: progressWidth + '%' }" mode="aspectFit"></image>
  52. </view>
  53. <text class="progress-text">已邀请{{ redBagData.shareNum || 0 }}人,已领{{ redBagData.shareGetNum || 0
  54. }}元,最高还可得¥{{ maxGetPrice }} 元</text>
  55. </view>
  56. <!-- Continue Scan Button -->
  57. <view class="scan-btn-wrapper" @click="handleScan">
  58. <text class="scan-btn-text">继续扫码</text>
  59. </view>
  60. <!-- Bottom Text -->
  61. <text class="bottom-text">好友助力成功后,奖励实时到账</text>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import RootBackHome from '../components/root-back-home.vue'
  68. export default {
  69. components: {
  70. RootBackHome
  71. },
  72. data() {
  73. return {
  74. bianhao: '', // 红包编号
  75. redBagData: null, // 红包数据
  76. }
  77. },
  78. computed: {
  79. // 计算进度条宽度
  80. progressWidth() {
  81. return this.redBagData ? (this.redBagData.shareGetNum / (this.redBagData.shareSumPrice) * 100) : 0;
  82. },
  83. //最高还可得 redBagData.shareSumPrice - redBagData.shareGetNum 元
  84. maxGetPrice() {
  85. return this.redBagData ? this.redBagData.shareSumPrice - this.redBagData.shareGetNum : 0;
  86. }
  87. },
  88. onLoad(options) {
  89. // 从领取页面跳转过来时,获取编号参数
  90. if (options.bianhao) {
  91. this.bianhao = options.bianhao;
  92. // 调用获取红包接口
  93. this.getRedBagDetail();
  94. }
  95. },
  96. onShow() {
  97. // 下拉再次进入时,页面栈只有红包页,返回要去首页而不是退出
  98. const guard = this.$refs.rootBackHome
  99. if (guard) {
  100. guard.sync()
  101. return
  102. }
  103. this.$nextTick(() => {
  104. this.$refs.rootBackHome && this.$refs.rootBackHome.sync()
  105. })
  106. },
  107. onShareAppMessage() {
  108. // 设置分享内容
  109. return {
  110. title: '好友助力解锁最高' + (this.redBagData?.shareSumPrice) + '元红包',
  111. path: '/packet/pages/index?bianhao=' + this.bianhao,
  112. imageUrl: '../static/index/share.png'
  113. };
  114. },
  115. onShareTimeline() {
  116. // 设置分享内容
  117. return {
  118. title: '好友助力解锁最高' + (this.redBagData?.shareSumPrice) + '元红包',
  119. path: '/packet/pages/index?bianhao=' + this.bianhao,
  120. imageUrl: '../static/index/share.png'
  121. };
  122. },
  123. methods: {
  124. // 获取红包详情
  125. async getRedBagDetail() {
  126. if (!this.bianhao) {
  127. uni.showModal({
  128. title: '提示',
  129. content: '红包编号缺失',
  130. showCancel: false
  131. });
  132. return;
  133. }
  134. try {
  135. const res = await this.$u.api.getRedBagAjax(this.bianhao);
  136. if (res.code === 200 || res.code === 0) {
  137. // getWay: 0-扫码(A) 1-被分享(B);被分享用户无二次分享,直接回首页
  138. if (Number(res.data && res.data.getWay) === 1) {
  139. uni.switchTab({
  140. url: '/pages/sell/index'
  141. });
  142. return;
  143. }
  144. this.redBagData = res.data;
  145. } else {
  146. uni.showToast({
  147. title: res.msg || '获取红包信息失败',
  148. icon: 'none'
  149. });
  150. }
  151. } catch (e) {
  152. console.error('获取红包详情失败:', e);
  153. uni.showToast({
  154. title: '网络错误',
  155. icon: 'none'
  156. });
  157. }
  158. },
  159. handleUse() {
  160. // 跳转到商城页面
  161. uni.switchTab({
  162. url: '/pages/sell/index'
  163. });
  164. },
  165. handleInvite() {
  166. // 邀请好友逻辑 - 此方法会在用户点击分享按钮时触发
  167. // 实际分享内容由 onShareAppMessage 控制
  168. },
  169. handleScan() {
  170. // 继续扫码逻辑
  171. uni.scanCode({
  172. success: (scanRes) => {
  173. //获取扫描结果中 bianhao 参数
  174. const bianhao = scanRes.result.split('=')[1];
  175. if (!bianhao) {
  176. uni.showToast({
  177. title: '扫描结果格式错误',
  178. icon: 'none'
  179. });
  180. return;
  181. }
  182. // 扫描到新红包,跳转到 index 页面
  183. uni.redirectTo({
  184. url: '/packet/pages/index?bianhao=' + bianhao
  185. });
  186. }
  187. });
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .get-page {
  194. height: 100vh;
  195. position: relative;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. .bg-image {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. bottom: 0;
  204. width: 100%;
  205. height: 100%;
  206. z-index: 0;
  207. }
  208. .content-wrapper {
  209. position: relative;
  210. z-index: 1;
  211. width: 100%;
  212. padding: 40rpx 30rpx;
  213. box-sizing: border-box;
  214. .header-section {
  215. text-align: center;
  216. margin-bottom: 40rpx;
  217. margin-top: 30rpx;
  218. .header-logo {
  219. width: 80%;
  220. display: block;
  221. margin: 0 auto 20rpx;
  222. }
  223. .header-title {
  224. font-size: 48rpx;
  225. font-weight: bold;
  226. color: #1a1a1a;
  227. display: block;
  228. }
  229. }
  230. .white-card {
  231. border-radius: 20rpx;
  232. padding: 40rpx 30rpx;
  233. background: url('/packet/static/get/frame.png') no-repeat center center;
  234. background-size: 100% 100%;
  235. margin-top: 110rpx;
  236. .top-amount-row {
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. margin: 10rpx 60rpx 30rpx 60rpx;
  241. .received-text {
  242. font-size: 40rpx;
  243. font-weight: bold;
  244. color: #333;
  245. }
  246. .use-btn-wrapper {
  247. position: relative;
  248. width: 160rpx;
  249. height: 50rpx;
  250. background: url('/packet/static/get/use-button.png') no-repeat center center;
  251. background-size: 100% 100%;
  252. border-radius: 25rpx;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. margin-left: 20rpx;
  257. .use-btn-image {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. .use-btn-text {
  262. font-size: 28rpx;
  263. color: #333;
  264. font-weight: 500;
  265. }
  266. }
  267. }
  268. .promo-box {
  269. position: relative;
  270. margin-bottom: 30rpx;
  271. padding: 0 10rpx;
  272. .inner-box-bg {
  273. width: 100%;
  274. display: block;
  275. }
  276. .promo-content {
  277. position: absolute;
  278. top: 0;
  279. left: 0;
  280. right: 0;
  281. bottom: 0;
  282. box-sizing: border-box;
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. .promo-header {
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. margin-bottom: 16rpx;
  291. .promo-amount {
  292. font-size: 64rpx;
  293. font-weight: bold;
  294. color: #333;
  295. }
  296. }
  297. .promo-desc {
  298. font-size: 28rpx;
  299. color: #666;
  300. margin-bottom: 12rpx;
  301. }
  302. .promo-detail {
  303. font-size: 24rpx;
  304. color: #666;
  305. line-height: 1.5;
  306. .highlight-red {
  307. color: #ff4444;
  308. font-weight: bold;
  309. }
  310. }
  311. }
  312. }
  313. .invite-btn-wrapper {
  314. position: relative;
  315. width: 300rpx;
  316. height: 90rpx;
  317. margin: 0 auto 40rpx;
  318. background: url('/packet/static/get/button1.png') no-repeat center center;
  319. background-size: 100% 100%;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. border: none;
  324. padding: 0;
  325. line-height: normal;
  326. font-size: 0;
  327. &::after {
  328. border: none;
  329. }
  330. .invite-btn-text {
  331. font-family: Adobe Heiti Std;
  332. font-size: 42rpx;
  333. color: #FFFFFF;
  334. text-align: center;
  335. }
  336. }
  337. .red-packets-section {
  338. display: flex;
  339. justify-content: center;
  340. gap: 20rpx;
  341. margin-bottom: 30rpx;
  342. .packet-card {
  343. flex: 1;
  344. position: relative;
  345. background: url('/packet/static/get/red-packet.png') no-repeat center center;
  346. background-size: 100% 100%;
  347. height: 184rpx;
  348. max-width: 194rpx;
  349. display: flex;
  350. flex-direction: column;
  351. align-items: center;
  352. padding-top: 24rpx;
  353. .packet-text {
  354. font-size: 26rpx;
  355. color: #003C14;
  356. text-align: center;
  357. }
  358. }
  359. }
  360. .progress-section {
  361. margin-bottom: 30rpx;
  362. padding: 0 30rpx;
  363. .progress-bar-bg {
  364. position: relative;
  365. width: 100%;
  366. height: 15rpx;
  367. background: #BDFAAD;
  368. border-radius: 6rpx;
  369. .progress-bar-fill {
  370. position: absolute;
  371. left: 0;
  372. top: 0;
  373. height: 100%;
  374. background: linear-gradient(90deg, #4CAF50, #8BC34A);
  375. border-radius: 6rpx;
  376. transition: width 0.3s ease;
  377. }
  378. .progress-dot {
  379. position: absolute;
  380. top: 50%;
  381. transform: translateX(-50%) translateY(-50%);
  382. width: 40rpx;
  383. height: 40rpx;
  384. }
  385. }
  386. .progress-text {
  387. display: block;
  388. text-align: center;
  389. font-size: 26rpx;
  390. color: #666;
  391. margin-top: 16rpx;
  392. }
  393. }
  394. .scan-btn-wrapper {
  395. position: relative;
  396. width: 300rpx;
  397. height: 90rpx;
  398. margin: 0 auto 30rpx;
  399. background: url('/packet/static/get/button1.png') no-repeat center center;
  400. background-size: 100% 100%;
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. .scan-btn-text {
  405. font-family: Adobe Heiti Std;
  406. font-size: 42rpx;
  407. color: #FFFFFF;
  408. text-align: center;
  409. }
  410. }
  411. .bottom-text {
  412. font-family: Adobe Heiti Std;
  413. font-size: 38rpx;
  414. color: #003C14;
  415. text-align: center;
  416. font-style: normal;
  417. margin: 0 auto;
  418. margin-left: 60rpx;
  419. }
  420. }
  421. }
  422. }
  423. </style>