index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. // 从二维码扫描进入时,获取编号参数
  65. if (options.bianhao) {
  66. this.bianhao = options.bianhao;
  67. // 调用扫码接口获取红包信息
  68. this.scanRedBag();
  69. }
  70. },
  71. onShow() {
  72. // 如果是从其他页面返回,重新获取红包数据
  73. if (this.bianhao) {
  74. this.scanRedBag();
  75. }
  76. },
  77. methods: {
  78. // 扫码获取红包信息
  79. async scanRedBag() {
  80. if (!this.bianhao) {
  81. // 如果没有编号,提示用户扫码
  82. uni.showModal({
  83. title: '提示',
  84. content: '请扫描红包二维码',
  85. showCancel: false
  86. });
  87. return;
  88. }
  89. try {
  90. const res = await this.$u.api.scanRedBagAjax(this.bianhao);
  91. if (res.code === 200 || res.code === 0) {
  92. this.redBagData = res.data;
  93. this.amount = res.data.redPrice;
  94. } else {
  95. uni.showToast({
  96. title: res.msg || '获取红包信息失败',
  97. icon: 'none'
  98. });
  99. }
  100. } catch (e) {
  101. console.error('扫码获取红包信息失败:', e);
  102. uni.showToast({
  103. title: '网络错误',
  104. icon: 'none'
  105. });
  106. }
  107. },
  108. // 领取红包
  109. async handleReceive() {
  110. // 如果已领取,提示用户
  111. if (this.redBagData && this.redBagData.drawStatus === 1) {
  112. uni.showToast({
  113. title: '红包已领取',
  114. icon: 'none'
  115. });
  116. return;
  117. }
  118. if (!this.bianhao) {
  119. uni.showToast({
  120. title: '红包编号缺失',
  121. icon: 'none'
  122. });
  123. return;
  124. }
  125. // 显示领取中提示
  126. uni.showLoading({
  127. title: '领取中...'
  128. });
  129. try {
  130. const res = await this.$u.api.getRedBagAjax(this.bianhao);
  131. uni.hideLoading();
  132. if (res.code === 200) {
  133. // 更新红包数据
  134. this.redBagData = res.data;
  135. uni.showToast({
  136. title: '领取成功',
  137. icon: 'success'
  138. });
  139. // 跳转到 get 页面,并传递红包数据
  140. setTimeout(() => {
  141. uni.redirectTo({
  142. url: '/packet/pages/get?bianhao=' + this.bianhao
  143. });
  144. }, 1500);
  145. } else {
  146. uni.showToast({
  147. title: res.msg || '领取失败',
  148. icon: 'none'
  149. });
  150. }
  151. } catch (e) {
  152. uni.hideLoading();
  153. console.error('领取红包失败:', e);
  154. uni.showToast({
  155. title: '网络错误',
  156. icon: 'none'
  157. });
  158. }
  159. },
  160. handleShare() {
  161. // Share logic
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .packet-page {
  168. height: 100vh;
  169. position: relative;
  170. display: flex;
  171. flex-direction: column;
  172. align-items: center;
  173. overflow: hidden;
  174. .bg-image {
  175. position: absolute;
  176. top: 0;
  177. left: 0;
  178. width: 100%;
  179. height: 100%;
  180. z-index: 0;
  181. }
  182. .content-wrapper {
  183. position: relative;
  184. z-index: 1;
  185. width: 100%;
  186. padding: 40rpx 30rpx;
  187. box-sizing: border-box;
  188. .headline-image {
  189. width: 80%;
  190. margin-left: 10%;
  191. margin-bottom: 30rpx;
  192. margin-top: 30rpx;
  193. }
  194. .envelope-section {
  195. position: relative;
  196. .envelope-image {
  197. width: 90%;
  198. display: block;
  199. margin: 0 auto;
  200. }
  201. .amount-wrapper {
  202. position: absolute;
  203. top: 12%;
  204. left: 50%;
  205. transform: translateX(-50%);
  206. text-align: center;
  207. .amount-display {
  208. display: flex;
  209. align-items: baseline;
  210. justify-content: center;
  211. .currency {
  212. font-size: 78rpx;
  213. color: #FF4444;
  214. font-weight: bold;
  215. margin-right: 4rpx;
  216. }
  217. .amount-value {
  218. font-size: 156rpx;
  219. color: #FF4444;
  220. font-weight: bold;
  221. }
  222. }
  223. }
  224. .receive-btn-wrapper {
  225. position: absolute;
  226. bottom: 15%;
  227. left: 52%;
  228. transform: translateX(-50%);
  229. width: 84%;
  230. .btn-image {
  231. width: 100%;
  232. height: auto;
  233. }
  234. .btn-text {
  235. position: absolute;
  236. top: 45%;
  237. left: 50%;
  238. transform: translate(-50%, -50%);
  239. font-size: 32rpx;
  240. color: #D73800;
  241. font-weight: 500;
  242. white-space: nowrap;
  243. }
  244. }
  245. }
  246. .info-card-section {
  247. position: relative;
  248. margin-bottom: 20rpx;
  249. .info-frame {
  250. width: 100%;
  251. display: block;
  252. }
  253. .info-content {
  254. position: absolute;
  255. top: 20%;
  256. left: 0;
  257. right: 0;
  258. bottom: 0;
  259. padding: 30rpx;
  260. box-sizing: border-box;
  261. .info-list {
  262. padding: 0 20rpx;
  263. .info-item {
  264. font-family: Fotor_HelloFont_GongYiTi;
  265. font-size: 40rpx;
  266. color: #000000;
  267. line-height: 64rpx;
  268. text-align: center;
  269. .spacer {
  270. flex: 1;
  271. margin: 0 16rpx;
  272. }
  273. .star {
  274. color: #FFB300;
  275. margin-left: 8rpx;
  276. }
  277. }
  278. }
  279. .rule-footer {
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. margin-top: 30rpx;
  284. .rule-text {
  285. font-size: 26rpx;
  286. color: #666;
  287. text-decoration: underline;
  288. }
  289. .share-btn-wrapper {
  290. position: absolute;
  291. bottom: 20rpx;
  292. right: 20rpx;
  293. width: 120rpx;
  294. height: 120rpx;
  295. .share-btn-image {
  296. width: 100%;
  297. height: 100%;
  298. }
  299. .share-text {
  300. position: absolute;
  301. top: 50%;
  302. left: 50%;
  303. transform: translate(-50%, -50%);
  304. font-size: 22rpx;
  305. color: #fff;
  306. font-weight: bold;
  307. text-align: center;
  308. line-height: 1.3;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. </style>