topupConsumptionPoints.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!-- 消费分充值 -->
  2. <template>
  3. <s-layout :title="t('wallet.points_recharge')">
  4. <view class="bg-white ss-modal-box ss-flex-col">
  5. <!-- 提现金额 -->
  6. <view class="modal-content ss-m-t-30">
  7. <uni-forms :model="state.model" :rules="state.rules" validateTrigger="bind" labelPosition="left" border
  8. class="form-box" labelWidth='200' ref="FormRef">
  9. <view class="bg-white ss-p-x-30">
  10. <uni-forms-item name="quota" :label="t('wallet.recharge_amount')" :required="true">
  11. <uni-easyinput v-model="state.payPrice" type="number" :placeholder="t('wallet.enter_recharge_amount')"
  12. :inputBorder="false" :clearable="false" @input="validateInput" :maxlength="9" />
  13. </uni-forms-item>
  14. <uni-forms-item name="quota" :label="t('wallet.actual_points_received')">
  15. <view class="ss-flex ss-h-100">
  16. {{consumption}}
  17. </view>
  18. </uni-forms-item>
  19. </view>
  20. </uni-forms>
  21. <view class="ss-flex ss-row-center ss-col-center ss-m-t-30 text-red text-center">
  22. {{ t('wallet.note_recharge_bonus',{amount:state.percentage.triggerMagnificationPoints,multiplier:parseFloat(state.percentage.consumptionMagnification)}) }}
  23. </view>
  24. </view>
  25. <view class="modal-footer ss-flex ss-row-center ss-col-center ss-m-t-80 ss-m-b-40 ss-flex-5">
  26. <button class="ss-reset-button save-btn" @tap="submit">
  27. {{ t('common.confirm') }}
  28. </button>
  29. </view>
  30. </view>
  31. </s-layout>
  32. </template>
  33. <script setup>
  34. import {
  35. computed,
  36. reactive,
  37. watchEffect,
  38. nextTick,
  39. onUnmounted
  40. } from 'vue';
  41. import {
  42. onLoad
  43. } from '@dcloudio/uni-app';
  44. import sheep from '@/sheep';
  45. import {
  46. clone
  47. } from 'lodash';
  48. import {
  49. fen2yuan,
  50. points2point
  51. } from '@/sheep/hooks/useGoods';
  52. import md5 from 'blueimp-md5';
  53. import PayWalletApi from '@/sheep/api/pay/wallet';
  54. import WithdrawalApi from '@/sheep/api/distri/withdrawal';
  55. import {
  56. showAuthModal,
  57. showShareModal
  58. } from '@/sheep/hooks/useModal';
  59. import { t } from '@/locale'
  60. const userWallet = computed(() => sheep.$store('user').userWallet);
  61. const userInfo = computed(() => sheep.$store('user').userInfo);
  62. const state = reactive({
  63. model: {},
  64. payPrice: undefined,
  65. percentage: {
  66. consumptionMagnification: 0,
  67. userTopUpConsumptionPoints: 0,
  68. triggerMagnificationPoints: 0
  69. }
  70. });
  71. const consumption = computed(() => {
  72. if (!state.payPrice) {
  73. return 0;
  74. }
  75. let result;
  76. if (state.payPrice >= parseFloat(state.percentage.triggerMagnificationPoints)) {
  77. result = (parseFloat(state.percentage.consumptionMagnification) * state.payPrice).toFixed(2)
  78. } else {
  79. result = state.payPrice
  80. }
  81. return result;
  82. });
  83. // 确保输入是整数
  84. async function validateInput(value) {
  85. const intValue = parseInt(value);
  86. const strPoints = value.toString()
  87. const [integerPart, decimalPart] = strPoints.split('.')
  88. if (decimalPart) {
  89. nextTick(() => {
  90. // state.payPrice = integerPart;
  91. });
  92. }
  93. }
  94. const submit = async () => {
  95. if (!state.payPrice) {
  96. sheep.$helper.toast(t('wallet.enter_recharge_amount'));
  97. return;
  98. }
  99. if (parseFloat(state.payPrice) < state.percentage.userTopUpConsumptionPoints) {
  100. sheep.$helper.toast(t('wallet.recharge_amount_less_than',{point:state.percentage.userTopUpConsumptionPoints}));
  101. return;
  102. }
  103. let {
  104. code,
  105. data
  106. } = await PayWalletApi.topupConsumptionPointsCreate({
  107. payPrice: state.payPrice,
  108. topUpConsumptionPoints: state.payPrice,
  109. userName: userInfo.value.username,
  110. });
  111. if (code === 0) {
  112. sheep.$router.redirect('/pages/pay/index', {
  113. id: data.payOrderId,
  114. type: 2
  115. });
  116. }
  117. };
  118. const getpercentage = async () => {
  119. const {
  120. code,
  121. data
  122. } = await WithdrawalApi.getWithdrawalPercentage();
  123. if (code === 0) {
  124. state.percentage = data;
  125. }
  126. }
  127. onLoad(async (options) => {
  128. await getpercentage();
  129. });
  130. </script>
  131. <style lang="scss" scoped>
  132. .all-btn {
  133. height: 60rpx;
  134. line-height: 60rpx;
  135. min-width: 80rpx;
  136. padding: 0 30rpx;
  137. border-radius: 30rpx;
  138. font-size: 26rpx;
  139. margin-right: 10rpx;
  140. border: 2rpx solid var(--ui-BG-Main);
  141. color: var(--ui-BG-Main);
  142. }
  143. .out-icon {
  144. width: 36rpx;
  145. height: 36rpx;
  146. margin-right: 26rpx;
  147. }
  148. .ss-modal-box {
  149. height: calc(100vh - 88rpx);
  150. // max-height: 1000rpx;
  151. .input-money {
  152. width: 90%;
  153. padding: 0 10rpx;
  154. // text-indent: 20rpx;
  155. height: 80rpx;
  156. border: 1px solid #bbbbbb;
  157. border-radius: 10rpx;
  158. margin: 15rpx auto;
  159. font-size: 28rpx;
  160. input {
  161. width: 100%;
  162. height: 100%;
  163. font-size: 28rpx;
  164. }
  165. }
  166. .modal-header {
  167. position: relative;
  168. padding: 60rpx 20rpx 40rpx;
  169. .money-text {
  170. color: $red;
  171. font-size: 46rpx;
  172. font-weight: bold;
  173. font-family: OPPOSANS;
  174. &::before {
  175. content: '¥';
  176. font-size: 30rpx;
  177. }
  178. }
  179. .time-text {
  180. font-size: 26rpx;
  181. color: $gray-b;
  182. }
  183. .close-icon {
  184. position: absolute;
  185. top: 10rpx;
  186. right: 20rpx;
  187. font-size: 46rpx;
  188. opacity: 0.2;
  189. }
  190. }
  191. .modal-content {
  192. overflow-y: auto;
  193. .out-title {
  194. font-size: 26rpx;
  195. font-weight: 500;
  196. color: #333333;
  197. }
  198. .out-tip {
  199. font-size: 26rpx;
  200. color: #bbbbbb;
  201. }
  202. .out-item {
  203. height: 86rpx;
  204. }
  205. .disabled-out-item {
  206. .out-title {
  207. color: #999999;
  208. }
  209. }
  210. .userInfo-money {
  211. font-size: 26rpx;
  212. color: #bbbbbb;
  213. line-height: normal;
  214. }
  215. }
  216. .save-btn {
  217. width: 710rpx;
  218. height: 80rpx;
  219. border-radius: 40rpx;
  220. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  221. color: $white;
  222. }
  223. .disabled-btn {
  224. background: #e5e5e5;
  225. color: #999999;
  226. }
  227. .past-due-btn {
  228. width: 710rpx;
  229. height: 80rpx;
  230. border-radius: 40rpx;
  231. background-color: #999;
  232. color: #fff;
  233. }
  234. }
  235. </style>