recharge.vue 6.5 KB

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