recharge.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. import { WxaSubscribeTemplate } from '@/sheep/util/const';
  50. const userWallet = computed(() => sheep.$store('user').userWallet);
  51. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  52. const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');
  53. const state = reactive({
  54. recharge_money: '', // 输入的充值金额
  55. packageList: [],
  56. });
  57. // 点击卡片,选择充值金额
  58. function onCard(e) {
  59. state.recharge_money = fen2yuan(e);
  60. }
  61. // 获得钱包充值套餐列表
  62. async function getRechargeTabs() {
  63. const { code, data } = await PayWalletApi.getWalletRechargePackageList();
  64. if (code !== 0) {
  65. return;
  66. }
  67. state.packageList = data;
  68. }
  69. // 发起支付
  70. async function onConfirm() {
  71. const { code, data } = await PayWalletApi.createWalletRecharge({
  72. packageId: state.packageList.find((item) => fen2yuan(item.payPrice) === state.recharge_money)?.id,
  73. payPrice: state.recharge_money * 100,
  74. });
  75. if (code !== 0) {
  76. return;
  77. }
  78. // #ifdef MP
  79. sheep.$platform.useProvider('wechat').subscribeMessage(WxaSubscribeTemplate.PAY_WALLET_RECHARGER_SUCCESS);
  80. // #endif
  81. sheep.$router.go('/pages/pay/index', {
  82. id: data.payOrderId,
  83. orderType: 'recharge',
  84. });
  85. }
  86. onLoad(() => {
  87. getRechargeTabs();
  88. });
  89. </script>
  90. <style lang="scss" scoped>
  91. :deep() {
  92. .uni-input-input {
  93. font-family: OPPOSANS !important;
  94. }
  95. }
  96. .wallet-num-box {
  97. padding: 0 40rpx 80rpx;
  98. background: var(--ui-BG-Main) v-bind(headerBg) center/750rpx 100% no-repeat;
  99. border-radius: 0 0 5% 5%;
  100. .num-title {
  101. font-size: 26rpx;
  102. font-weight: 500;
  103. color: $white;
  104. margin-bottom: 20rpx;
  105. }
  106. .wallet-num {
  107. font-size: 60rpx;
  108. font-weight: 500;
  109. color: $white;
  110. font-family: OPPOSANS;
  111. }
  112. .log-btn {
  113. width: 170rpx;
  114. height: 60rpx;
  115. line-height: 60rpx;
  116. border: 1rpx solid $white;
  117. border-radius: 30rpx;
  118. padding: 0;
  119. font-size: 26rpx;
  120. font-weight: 500;
  121. color: $white;
  122. }
  123. }
  124. .recharge-box {
  125. position: relative;
  126. padding: 0 30rpx;
  127. margin-top: -60rpx;
  128. }
  129. .save-btn {
  130. width: 620rpx;
  131. height: 86rpx;
  132. border-radius: 44rpx;
  133. font-size: 30rpx;
  134. }
  135. .recharge-card-box {
  136. width: 690rpx;
  137. background: var(--ui-BG);
  138. border-radius: 20rpx;
  139. padding: 30rpx;
  140. box-sizing: border-box;
  141. .input-label {
  142. font-size: 30rpx;
  143. font-weight: 500;
  144. color: #333;
  145. }
  146. .unit {
  147. display: flex;
  148. align-items: center;
  149. font-size: 48rpx;
  150. font-weight: 500;
  151. }
  152. .uni-easyinput__placeholder-class {
  153. font-size: 30rpx;
  154. height: 60rpx;
  155. display: flex;
  156. align-items: center;
  157. }
  158. :deep(.uni-easyinput__content-input) {
  159. font-size: 48rpx;
  160. }
  161. .face-value-btn {
  162. width: 200rpx;
  163. height: 144rpx;
  164. border: 1px solid var(--ui-BG-Main);
  165. border-radius: 10rpx;
  166. position: relative;
  167. z-index: 1;
  168. margin-bottom: 15rpx;
  169. margin-right: 15rpx;
  170. &:nth-of-type(3n) {
  171. margin-right: 0;
  172. }
  173. .face-value-title {
  174. font-size: 36rpx;
  175. font-weight: 500;
  176. color: var(--ui-BG-Main);
  177. font-family: OPPOSANS;
  178. &::after {
  179. content: '元';
  180. font-size: 24rpx;
  181. margin-left: 6rpx;
  182. }
  183. }
  184. .face-value-tag {
  185. position: absolute;
  186. z-index: 2;
  187. height: 40rpx;
  188. line-height: 40rpx;
  189. background: var(--ui-BG-Main);
  190. opacity: 0.8;
  191. border-radius: 10rpx 0 20rpx 0;
  192. top: 0;
  193. left: -2rpx;
  194. padding: 0 16rpx;
  195. font-size: 22rpx;
  196. color: $white;
  197. font-family: OPPOSANS;
  198. }
  199. &::before {
  200. position: absolute;
  201. content: ' ';
  202. width: 100%;
  203. height: 100%;
  204. background: var(--ui-BG-Main);
  205. opacity: 0.1;
  206. z-index: 0;
  207. left: 0;
  208. top: 0;
  209. }
  210. }
  211. .btn-active {
  212. z-index: 1;
  213. &::before {
  214. content: '';
  215. background: var(--ui-BG-Main);
  216. opacity: 1;
  217. }
  218. .face-value-title {
  219. color: $white;
  220. position: relative;
  221. z-index: 1;
  222. font-family: OPPOSANS;
  223. }
  224. .face-value-tag {
  225. background: $white;
  226. color: var(--ui-BG-Main);
  227. font-family: OPPOSANS;
  228. }
  229. }
  230. }
  231. </style>