topupConsumptionPoints.vue 5.5 KB

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