recharge.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!-- 充值界面 -->
  2. <template>
  3. <s-layout title="充值" class="withdraw-wrap" navbar="inner">
  4. <view class="wallet-num-box ss-flex ss-col-center ss-row-between" :style="[
  5. {
  6. marginTop: '-' + Number(statusBarHeight + 88) + 'rpx',
  7. paddingTop: Number(statusBarHeight + 108) + 'rpx',
  8. },
  9. ]">
  10. <view class="">
  11. <view class="num-title">当前余额(元)</view>
  12. <view class="wallet-num">{{ fen2yuan(userWallet.balance) }}</view>
  13. </view>
  14. <button class="ss-reset-button log-btn" @tap="sheep.$router.go('/pages/pay/recharge-log')">
  15. 充值记录
  16. </button>
  17. </view>
  18. <view class="recharge-box">
  19. <view class="recharge-card-box">
  20. <view class="input-label ss-m-b-50">充值金额</view>
  21. <view class="input-box ss-flex border-bottom ss-p-b-20">
  22. <view class="unit">¥</view>
  23. <uni-easyinput v-model="state.recharge_money" type="digit" placeholder="请输入充值金额"
  24. :inputBorder="false" />
  25. </view>
  26. <view class="face-value-box ss-flex ss-flex-wrap ss-m-y-40">
  27. <button class="ss-reset-button face-value-btn" v-for="item in state.packageList" :key="item.money"
  28. :class="[{ 'btn-active': state.recharge_money === fen2yuan(item.payPrice) }]"
  29. @tap="onCard(item.payPrice)">
  30. <text class="face-value-title">{{ fen2yuan(item.payPrice) }}</text>
  31. <view v-if="item.bonusPrice" class="face-value-tag">
  32. 送 {{ fen2yuan(item.bonusPrice) }} 元
  33. </view>
  34. </button>
  35. </view>
  36. <button class="ss-reset-button save-btn ui-BG-Main-Gradient ss-m-t-60 ui-Shadow-Main" @tap="onConfirm">
  37. 确认充值
  38. </button>
  39. </view>
  40. </view>
  41. </s-layout>
  42. </template>
  43. <script setup>
  44. import { computed, reactive } from 'vue';
  45. import sheep from '@/sheep';
  46. import { onLoad } from '@dcloudio/uni-app';
  47. import { fen2yuan } from '@/sheep/hooks/useGoods';
  48. import PayWalletApi from '@/sheep/api/pay/wallet';
  49. const userWallet = computed(() => sheep.$store('user').userWallet);
  50. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  51. const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');
  52. const state = reactive({
  53. recharge_money: '', // 输入的充值金额
  54. packageList: [],
  55. });
  56. // 点击卡片,选择充值金额
  57. function onCard(e) {
  58. state.recharge_money = fen2yuan(e);
  59. }
  60. // 获得钱包充值套餐列表
  61. async function getRechargeTabs() {
  62. const { code, data } = await PayWalletApi.getWalletRechargePackageList();
  63. if (code !== 0) {
  64. return;
  65. }
  66. state.packageList = data;
  67. }
  68. // 发起支付
  69. async function onConfirm() {
  70. const { code, data } = await PayWalletApi.createWalletRecharge({
  71. packageId: state.packageList.find((item) => fen2yuan(item.payPrice) === state.recharge_money)?.id,
  72. payPrice: state.recharge_money * 100
  73. });
  74. if (code !== 0) {
  75. return;
  76. }
  77. // #ifdef MP
  78. sheep.$platform.useProvider('wechat').subscribeMessage('money_change');
  79. // #endif
  80. sheep.$router.go('/pages/pay/index', {
  81. id: data.payOrderId,
  82. orderType: 'recharge'
  83. });
  84. }
  85. onLoad(() => {
  86. getRechargeTabs();
  87. });
  88. </script>
  89. <style lang="scss" scoped>
  90. :deep() {
  91. .uni-input-input {
  92. font-family: OPPOSANS !important;
  93. }
  94. }
  95. .wallet-num-box {
  96. padding: 0 40rpx 80rpx;
  97. background: var(--ui-BG-Main) v-bind(headerBg) center/750rpx 100% no-repeat;
  98. border-radius: 0 0 5% 5%;
  99. .num-title {
  100. font-size: 26rpx;
  101. font-weight: 500;
  102. color: $white;
  103. margin-bottom: 20rpx;
  104. }
  105. .wallet-num {
  106. font-size: 60rpx;
  107. font-weight: 500;
  108. color: $white;
  109. font-family: OPPOSANS;
  110. }
  111. .log-btn {
  112. width: 170rpx;
  113. height: 60rpx;
  114. line-height: 60rpx;
  115. border: 1rpx solid $white;
  116. border-radius: 30rpx;
  117. padding: 0;
  118. font-size: 26rpx;
  119. font-weight: 500;
  120. color: $white;
  121. }
  122. }
  123. .recharge-box {
  124. position: relative;
  125. padding: 0 30rpx;
  126. margin-top: -60rpx;
  127. }
  128. .save-btn {
  129. width: 620rpx;
  130. height: 86rpx;
  131. border-radius: 44rpx;
  132. font-size: 30rpx;
  133. }
  134. .recharge-card-box {
  135. width: 690rpx;
  136. background: var(--ui-BG);
  137. border-radius: 20rpx;
  138. padding: 30rpx;
  139. box-sizing: border-box;
  140. .input-label {
  141. font-size: 30rpx;
  142. font-weight: 500;
  143. color: #333;
  144. }
  145. .unit {
  146. display: flex;
  147. align-items: center;
  148. font-size: 48rpx;
  149. font-weight: 500;
  150. }
  151. .uni-easyinput__placeholder-class {
  152. font-size: 30rpx;
  153. height: 60rpx;
  154. display: flex;
  155. align-items: center;
  156. }
  157. :deep(.uni-easyinput__content-input) {
  158. font-size: 48rpx;
  159. }
  160. .face-value-btn {
  161. width: 200rpx;
  162. height: 144rpx;
  163. border: 1px solid var(--ui-BG-Main);
  164. border-radius: 10rpx;
  165. position: relative;
  166. z-index: 1;
  167. margin-bottom: 15rpx;
  168. margin-right: 15rpx;
  169. &:nth-of-type(3n) {
  170. margin-right: 0;
  171. }
  172. .face-value-title {
  173. font-size: 36rpx;
  174. font-weight: 500;
  175. color: var(--ui-BG-Main);
  176. font-family: OPPOSANS;
  177. &::after {
  178. content: '元';
  179. font-size: 24rpx;
  180. margin-left: 6rpx;
  181. }
  182. }
  183. .face-value-tag {
  184. position: absolute;
  185. z-index: 2;
  186. height: 40rpx;
  187. line-height: 40rpx;
  188. background: var(--ui-BG-Main);
  189. opacity: 0.8;
  190. border-radius: 10rpx 0 20rpx 0;
  191. top: 0;
  192. left: -2rpx;
  193. padding: 0 16rpx;
  194. font-size: 22rpx;
  195. color: $white;
  196. font-family: OPPOSANS;
  197. }
  198. &::before {
  199. position: absolute;
  200. content: ' ';
  201. width: 100%;
  202. height: 100%;
  203. background: var(--ui-BG-Main);
  204. opacity: 0.1;
  205. z-index: 0;
  206. left: 0;
  207. top: 0;
  208. }
  209. }
  210. .btn-active {
  211. z-index: 1;
  212. &::before {
  213. content: '';
  214. background: var(--ui-BG-Main);
  215. opacity: 1;
  216. }
  217. .face-value-title {
  218. color: $white;
  219. position: relative;
  220. z-index: 1;
  221. font-family: OPPOSANS;
  222. }
  223. .face-value-tag {
  224. background: $white;
  225. color: var(--ui-BG-Main);
  226. font-family: OPPOSANS;
  227. }
  228. }
  229. }
  230. </style>