get.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. this.redBagData = res.data;
  138. } else {
  139. uni.showToast({
  140. title: res.msg || '获取红包信息失败',
  141. icon: 'none'
  142. });
  143. }
  144. } catch (e) {
  145. console.error('获取红包详情失败:', e);
  146. uni.showToast({
  147. title: '网络错误',
  148. icon: 'none'
  149. });
  150. }
  151. },
  152. handleUse() {
  153. // 跳转到商城页面
  154. uni.switchTab({
  155. url: '/pages/sell/index'
  156. });
  157. },
  158. handleInvite() {
  159. // 邀请好友逻辑 - 此方法会在用户点击分享按钮时触发
  160. // 实际分享内容由 onShareAppMessage 控制
  161. },
  162. handleScan() {
  163. // 继续扫码逻辑
  164. uni.scanCode({
  165. success: (scanRes) => {
  166. //获取扫描结果中 bianhao 参数
  167. const bianhao = scanRes.result.split('=')[1];
  168. if (!bianhao) {
  169. uni.showToast({
  170. title: '扫描结果格式错误',
  171. icon: 'none'
  172. });
  173. return;
  174. }
  175. // 扫描到新红包,跳转到 index 页面
  176. uni.redirectTo({
  177. url: '/packet/pages/index?bianhao=' + bianhao
  178. });
  179. }
  180. });
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .get-page {
  187. height: 100vh;
  188. position: relative;
  189. display: flex;
  190. flex-direction: column;
  191. align-items: center;
  192. .bg-image {
  193. position: absolute;
  194. top: 0;
  195. left: 0;
  196. bottom: 0;
  197. width: 100%;
  198. height: 100%;
  199. z-index: 0;
  200. }
  201. .content-wrapper {
  202. position: relative;
  203. z-index: 1;
  204. width: 100%;
  205. padding: 40rpx 30rpx;
  206. box-sizing: border-box;
  207. .header-section {
  208. text-align: center;
  209. margin-bottom: 40rpx;
  210. margin-top: 30rpx;
  211. .header-logo {
  212. width: 80%;
  213. display: block;
  214. margin: 0 auto 20rpx;
  215. }
  216. .header-title {
  217. font-size: 48rpx;
  218. font-weight: bold;
  219. color: #1a1a1a;
  220. display: block;
  221. }
  222. }
  223. .white-card {
  224. border-radius: 20rpx;
  225. padding: 40rpx 30rpx;
  226. background: url('/packet/static/get/frame.png') no-repeat center center;
  227. background-size: 100% 100%;
  228. margin-top: 110rpx;
  229. .top-amount-row {
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. margin: 10rpx 60rpx 30rpx 60rpx;
  234. .received-text {
  235. font-size: 40rpx;
  236. font-weight: bold;
  237. color: #333;
  238. }
  239. .use-btn-wrapper {
  240. position: relative;
  241. width: 160rpx;
  242. height: 50rpx;
  243. background: url('/packet/static/get/use-button.png') no-repeat center center;
  244. background-size: 100% 100%;
  245. border-radius: 25rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. margin-left: 20rpx;
  250. .use-btn-image {
  251. width: 100%;
  252. height: 100%;
  253. }
  254. .use-btn-text {
  255. font-size: 28rpx;
  256. color: #333;
  257. font-weight: 500;
  258. }
  259. }
  260. }
  261. .promo-box {
  262. position: relative;
  263. margin-bottom: 30rpx;
  264. padding: 0 10rpx;
  265. .inner-box-bg {
  266. width: 100%;
  267. display: block;
  268. }
  269. .promo-content {
  270. position: absolute;
  271. top: 0;
  272. left: 0;
  273. right: 0;
  274. bottom: 0;
  275. box-sizing: border-box;
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. .promo-header {
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. margin-bottom: 16rpx;
  284. .promo-amount {
  285. font-size: 64rpx;
  286. font-weight: bold;
  287. color: #333;
  288. }
  289. }
  290. .promo-desc {
  291. font-size: 28rpx;
  292. color: #666;
  293. margin-bottom: 12rpx;
  294. }
  295. .promo-detail {
  296. font-size: 24rpx;
  297. color: #666;
  298. line-height: 1.5;
  299. .highlight-red {
  300. color: #ff4444;
  301. font-weight: bold;
  302. }
  303. }
  304. }
  305. }
  306. .invite-btn-wrapper {
  307. position: relative;
  308. width: 300rpx;
  309. height: 90rpx;
  310. margin: 0 auto 40rpx;
  311. background: url('/packet/static/get/button1.png') no-repeat center center;
  312. background-size: 100% 100%;
  313. display: flex;
  314. align-items: center;
  315. justify-content: center;
  316. border: none;
  317. padding: 0;
  318. line-height: normal;
  319. font-size: 0;
  320. &::after {
  321. border: none;
  322. }
  323. .invite-btn-text {
  324. font-family: Adobe Heiti Std;
  325. font-size: 42rpx;
  326. color: #FFFFFF;
  327. text-align: center;
  328. }
  329. }
  330. .red-packets-section {
  331. display: flex;
  332. justify-content: center;
  333. gap: 20rpx;
  334. margin-bottom: 30rpx;
  335. .packet-card {
  336. flex: 1;
  337. position: relative;
  338. background: url('/packet/static/get/red-packet.png') no-repeat center center;
  339. background-size: 100% 100%;
  340. height: 184rpx;
  341. max-width: 194rpx;
  342. display: flex;
  343. flex-direction: column;
  344. align-items: center;
  345. padding-top: 24rpx;
  346. .packet-text {
  347. font-size: 26rpx;
  348. color: #003C14;
  349. text-align: center;
  350. }
  351. }
  352. }
  353. .progress-section {
  354. margin-bottom: 30rpx;
  355. padding: 0 30rpx;
  356. .progress-bar-bg {
  357. position: relative;
  358. width: 100%;
  359. height: 15rpx;
  360. background: #BDFAAD;
  361. border-radius: 6rpx;
  362. .progress-bar-fill {
  363. position: absolute;
  364. left: 0;
  365. top: 0;
  366. height: 100%;
  367. background: linear-gradient(90deg, #4CAF50, #8BC34A);
  368. border-radius: 6rpx;
  369. transition: width 0.3s ease;
  370. }
  371. .progress-dot {
  372. position: absolute;
  373. top: 50%;
  374. transform: translateX(-50%) translateY(-50%);
  375. width: 40rpx;
  376. height: 40rpx;
  377. }
  378. }
  379. .progress-text {
  380. display: block;
  381. text-align: center;
  382. font-size: 26rpx;
  383. color: #666;
  384. margin-top: 16rpx;
  385. }
  386. }
  387. .scan-btn-wrapper {
  388. position: relative;
  389. width: 300rpx;
  390. height: 90rpx;
  391. margin: 0 auto 30rpx;
  392. background: url('/packet/static/get/button1.png') no-repeat center center;
  393. background-size: 100% 100%;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. .scan-btn-text {
  398. font-family: Adobe Heiti Std;
  399. font-size: 42rpx;
  400. color: #FFFFFF;
  401. text-align: center;
  402. }
  403. }
  404. .bottom-text {
  405. font-family: Adobe Heiti Std;
  406. font-size: 38rpx;
  407. color: #003C14;
  408. text-align: center;
  409. font-style: normal;
  410. margin: 0 auto;
  411. margin-left: 60rpx;
  412. }
  413. }
  414. }
  415. }
  416. </style>