index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="packet-page">
  3. <!-- Background -->
  4. <image src="/packet/static/index/background.png" class="bg-image" mode="widthFix"></image>
  5. <!-- Main Content -->
  6. <view class="content-wrapper">
  7. <!-- Headline -->
  8. <image src="/packet/static/index/headline.png" class="headline-image" mode="widthFix"></image>
  9. <!-- Red Envelope Section -->
  10. <view class="envelope-section">
  11. <!-- Red Envelope Image -->
  12. <image src="/packet/static/index/red_envelope.png" class="envelope-image" mode="widthFix"></image>
  13. <!-- Amount Display -->
  14. <view class="amount-wrapper">
  15. <view class="amount-display">
  16. <text class="currency">¥</text>
  17. <text class="amount-value">{{ amount }}</text>
  18. </view>
  19. </view>
  20. <!-- Receive Button -->
  21. <view class="receive-btn-wrapper" @click="handleReceive">
  22. <image src="/packet/static/index/btn_receive.png" class="btn-image" mode="widthFix"></image>
  23. <text class="btn-text" v-if="!redBagData.drawStatus">领{{ amount }}元红包 | 买书卖书都能用</text>
  24. <text class="btn-text" v-else>已领取</text>
  25. </view>
  26. </view>
  27. <!-- Info Card -->
  28. <view class="info-card-section">
  29. <image src="/packet/static/index/info_frame.png" class="info-frame" mode="widthFix"></image>
  30. <view class="info-content">
  31. <view class="info-list">
  32. <view class="info-item">
  33. <text>买书立减</text>
  34. <text class="spacer"></text>
  35. <text>卖书加价</text>
  36. </view>
  37. <view class="info-item">
  38. <text>伴你轻松度过大学四年</text>
  39. </view>
  40. <view class="info-item">
  41. <text>官方补贴</text>
  42. <text class="spacer"></text>
  43. <text>无门槛使用</text>
  44. </view>
  45. </view>
  46. <view class="rule-footer">
  47. <text class="rule-text">活动规则</text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. amount: '1.58',
  59. bianhao: '', // 红包编号
  60. redBagData: null // 红包数据
  61. }
  62. },
  63. onLoad(options) {
  64. let bianhao = options.bianhao;
  65. // 兼容扫码进入场景,当前页的 scene 里带了 bianhao
  66. if (!bianhao && options.scene) {
  67. const decodeScene = decodeURIComponent(options.scene);
  68. const paramPairs = decodeScene.split('&');
  69. paramPairs.forEach((pair) => {
  70. const [key, value] = pair.split('=');
  71. if (key === 'bianhao') {
  72. bianhao = value;
  73. }
  74. });
  75. }
  76. // 兼容从 App.vue 缓存中获取 (因为如果是扫小程序码直接进入这个页面,App.vue的onLaunch会先执行并存入缓存,然后执行页面的onLoad)
  77. if (!bianhao) {
  78. bianhao = uni.getStorageSync('scene_bianhao');
  79. }
  80. if (bianhao) {
  81. this.bianhao = bianhao;
  82. uni.removeStorageSync('scene_bianhao');
  83. // 调用扫码接口获取红包信息
  84. this.scanRedBag();
  85. }
  86. },
  87. onShow() {
  88. // 如果是从其他页面返回,重新获取红包数据
  89. if (this.bianhao) {
  90. this.scanRedBag();
  91. }
  92. },
  93. methods: {
  94. // 扫码获取红包信息
  95. async scanRedBag() {
  96. if (!this.bianhao) {
  97. // 如果没有编号,提示用户扫码
  98. uni.showModal({
  99. title: '提示',
  100. content: '请扫描红包二维码',
  101. showCancel: false
  102. });
  103. return;
  104. }
  105. try {
  106. const res = await this.$u.api.scanRedBagAjax(this.bianhao);
  107. if (res.code === 200 || res.code === 0) {
  108. this.redBagData = res.data;
  109. this.amount = res.data.redPrice;
  110. } else {
  111. uni.showToast({
  112. title: res.msg || '获取红包信息失败',
  113. icon: 'none'
  114. });
  115. }
  116. } catch (e) {
  117. console.error('扫码获取红包信息失败:', e);
  118. uni.showToast({
  119. title: '网络错误',
  120. icon: 'none'
  121. });
  122. }
  123. },
  124. // 领取红包
  125. async handleReceive() {
  126. // 如果已领取,提示用户
  127. if (this.redBagData && this.redBagData.drawStatus === 1) {
  128. uni.showToast({
  129. title: '红包已领取',
  130. icon: 'none'
  131. });
  132. return;
  133. }
  134. if (!this.bianhao) {
  135. uni.showToast({
  136. title: '红包编号缺失',
  137. icon: 'none'
  138. });
  139. return;
  140. }
  141. // 显示领取中提示
  142. uni.showLoading({
  143. title: '领取中...'
  144. });
  145. try {
  146. const res = await this.$u.api.getRedBagAjax(this.bianhao);
  147. uni.hideLoading();
  148. if (res.code === 200) {
  149. // 更新红包数据
  150. this.redBagData = res.data;
  151. uni.showToast({
  152. title: '领取成功',
  153. icon: 'success'
  154. });
  155. // 跳转到 get 页面,并传递红包数据
  156. setTimeout(() => {
  157. uni.redirectTo({
  158. url: '/packet/pages/get?bianhao=' + this.bianhao
  159. });
  160. }, 1500);
  161. } else {
  162. uni.showToast({
  163. title: res.msg || '领取失败',
  164. icon: 'none'
  165. });
  166. }
  167. } catch (e) {
  168. uni.hideLoading();
  169. console.error('领取红包失败:', e);
  170. uni.showToast({
  171. title: '网络错误',
  172. icon: 'none'
  173. });
  174. }
  175. },
  176. handleShare() {
  177. // Share logic
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .packet-page {
  184. height: 100vh;
  185. position: relative;
  186. display: flex;
  187. flex-direction: column;
  188. align-items: center;
  189. overflow: hidden;
  190. .bg-image {
  191. position: absolute;
  192. top: 0;
  193. left: 0;
  194. width: 100%;
  195. height: 100%;
  196. z-index: 0;
  197. }
  198. .content-wrapper {
  199. position: relative;
  200. z-index: 1;
  201. width: 100%;
  202. padding: 40rpx 30rpx;
  203. box-sizing: border-box;
  204. .headline-image {
  205. width: 80%;
  206. margin-left: 10%;
  207. margin-bottom: 30rpx;
  208. margin-top: 30rpx;
  209. }
  210. .envelope-section {
  211. position: relative;
  212. .envelope-image {
  213. width: 90%;
  214. display: block;
  215. margin: 0 auto;
  216. }
  217. .amount-wrapper {
  218. position: absolute;
  219. top: 12%;
  220. left: 50%;
  221. transform: translateX(-50%);
  222. text-align: center;
  223. .amount-display {
  224. display: flex;
  225. align-items: baseline;
  226. justify-content: center;
  227. .currency {
  228. font-size: 78rpx;
  229. color: #FF4444;
  230. font-weight: bold;
  231. margin-right: 4rpx;
  232. }
  233. .amount-value {
  234. font-size: 156rpx;
  235. color: #FF4444;
  236. font-weight: bold;
  237. }
  238. }
  239. }
  240. .receive-btn-wrapper {
  241. position: absolute;
  242. bottom: 15%;
  243. left: 52%;
  244. transform: translateX(-50%);
  245. width: 84%;
  246. .btn-image {
  247. width: 100%;
  248. height: auto;
  249. }
  250. .btn-text {
  251. position: absolute;
  252. top: 45%;
  253. left: 50%;
  254. transform: translate(-50%, -50%);
  255. font-size: 32rpx;
  256. color: #D73800;
  257. font-weight: 500;
  258. white-space: nowrap;
  259. }
  260. }
  261. }
  262. .info-card-section {
  263. position: relative;
  264. margin-bottom: 20rpx;
  265. .info-frame {
  266. width: 100%;
  267. display: block;
  268. }
  269. .info-content {
  270. position: absolute;
  271. top: 20%;
  272. left: 0;
  273. right: 0;
  274. bottom: 0;
  275. padding: 30rpx;
  276. box-sizing: border-box;
  277. .info-list {
  278. padding: 0 20rpx;
  279. .info-item {
  280. font-family: Fotor_HelloFont_GongYiTi;
  281. font-size: 40rpx;
  282. color: #000000;
  283. line-height: 64rpx;
  284. text-align: center;
  285. .spacer {
  286. flex: 1;
  287. margin: 0 16rpx;
  288. }
  289. .star {
  290. color: #FFB300;
  291. margin-left: 8rpx;
  292. }
  293. }
  294. }
  295. .rule-footer {
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. margin-top: 30rpx;
  300. .rule-text {
  301. font-size: 26rpx;
  302. color: #666;
  303. text-decoration: underline;
  304. }
  305. .share-btn-wrapper {
  306. position: absolute;
  307. bottom: 20rpx;
  308. right: 20rpx;
  309. width: 120rpx;
  310. height: 120rpx;
  311. .share-btn-image {
  312. width: 100%;
  313. height: 100%;
  314. }
  315. .share-text {
  316. position: absolute;
  317. top: 50%;
  318. left: 50%;
  319. transform: translate(-50%, -50%);
  320. font-size: 22rpx;
  321. color: #fff;
  322. font-weight: bold;
  323. text-align: center;
  324. line-height: 1.3;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. </style>