wallet-recharge.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="pl-30 pr-30">
  3. <view class="pay">
  4. <view class="title pt-30 pb-30">充值金额</view>
  5. <view class="flex-wrap">
  6. <view
  7. :class="[
  8. 'option',
  9. 'flex-center',
  10. `option-${index === payOption && !payValue ? 'active' : ''}`,
  11. ]"
  12. v-for="(item, index) in payOptions"
  13. :key="index"
  14. @click="changeOption(index)"
  15. >
  16. <view
  17. class="tag fs-24 color-fff fw-500"
  18. v-if="payOptionsDiscount[index]"
  19. >{{ payOptionsDiscount[index] }}</view
  20. >
  21. {{ item }}
  22. </view>
  23. </view>
  24. <view v-if="payOptionsDiscountDay[payOption]" class="flex-align-center">
  25. <view class="fs-30 color-666"
  26. >折扣优惠有效期{{ payOptionsDiscountDay[payOption] }}天</view
  27. >
  28. <view class="ml-12 color-primary fs-30" @click="toDesc">
  29. <text>详细规则</text>
  30. <text class="fs-24 ml-6">>></text>
  31. </view>
  32. </view>
  33. <view class="title pt-60 pb-30">自定义金额</view>
  34. <style-input
  35. :value="payValue > 0 ? payValue : ''"
  36. title="金额"
  37. type="digit"
  38. @input="input"
  39. />
  40. </view>
  41. </view>
  42. <style-bottom-view>
  43. <view class="pl-60 pr-60 pb-20">
  44. <style-button size="small" type="primary" @click="confirm"
  45. >充值</style-button
  46. >
  47. </view>
  48. </style-bottom-view>
  49. </template>
  50. <script setup lang="ts">
  51. import { ref } from "vue";
  52. import { fetchProfile, insertMoney } from "../../api/user";
  53. import { onLoad } from "@dcloudio/uni-app";
  54. import { to } from "@/utils/navigate";
  55. const balance = ref(0);
  56. const payOption = ref(0);
  57. const payOptions = ref([30, 50, 100, 200, 500, 1000]);
  58. const payOptionsDiscount = ref(["", "", "", "", "", ""]);
  59. const payOptionsDiscountDay = ref([0, 0, 0, 0, 0, 0]);
  60. const payValue = ref(0);
  61. const activityId = ref();
  62. const input = (e: any) => {
  63. payValue.value = e.value;
  64. };
  65. const changeOption = (index: number) => {
  66. payValue.value = 0;
  67. payOption.value = index;
  68. };
  69. const confirm = () => {
  70. if (payValue.value && !/^[0-9]*(\.\d{1,2})?$/.test(`${payValue.value}`)) {
  71. uni.showModal({
  72. title: "温馨提示",
  73. content: "请输入正确的金额",
  74. showCancel: false,
  75. confirmColor: "#347DFF",
  76. });
  77. return;
  78. }
  79. const params = payValue.value
  80. ? Number(payValue.value)
  81. : payOptions.value[payOption.value];
  82. if (params > 10000 || params <= 0) {
  83. uni.showModal({
  84. title: "温馨提示",
  85. content: "每次最大充值金额10000,请修改金额",
  86. showCancel: false,
  87. confirmColor: "#347DFF",
  88. });
  89. return;
  90. }
  91. uni.showLoading({
  92. title: "加载中",
  93. });
  94. insertMoney(params)
  95. .then(() => {
  96. return fetchProfile();
  97. })
  98. .then((res) => {
  99. payValue.value = 0;
  100. balance.value = res.balance;
  101. uni.hideLoading();
  102. uni.showToast({
  103. title: "已支付",
  104. icon: "success",
  105. });
  106. to("/pages-user/wallet/wallet");
  107. })
  108. .catch((err) => {
  109. if (/cancel/.test(err.errMsg)) {
  110. return;
  111. }
  112. uni.showModal({
  113. content: `${err.errMsg},请重试`,
  114. });
  115. });
  116. };
  117. const toDesc = () => {
  118. to(`/pages-common/activity/activity?id=${activityId.value}&back=1`);
  119. };
  120. onLoad(() => {
  121. fetchProfile().then((res) => {
  122. // console.log(res);
  123. balance.value = res.balance;
  124. if (res && res.activityList && res.activityList.length) {
  125. res.activityList[0].rechargeRightsList.forEach((item: any) => {
  126. const val = Number((Number(item.amountMin) / 100).toFixed(2));
  127. const fi = payOptions.value.findIndex((o) => o === val);
  128. if (fi >= 0) {
  129. payOptionsDiscount.value[fi] = item.rightsDesc;
  130. payOptionsDiscountDay.value[fi] = item.validity;
  131. }
  132. });
  133. activityId.value = res.activityList[0].id;
  134. }
  135. });
  136. });
  137. </script>
  138. <style lang="scss">
  139. .pay {
  140. .title {
  141. font-weight: 500;
  142. font-size: 32rpx;
  143. color: #000;
  144. }
  145. .option {
  146. position: relative;
  147. width: 214rpx;
  148. height: 140rpx;
  149. background: var(--color-sec);
  150. border-radius: 10rpx;
  151. margin-left: 20rpx;
  152. margin-bottom: 20rpx;
  153. font-size: 36rpx;
  154. color: #000;
  155. font-weight: 500;
  156. overflow: hidden;
  157. &:nth-child(3n + 1) {
  158. margin-left: 0;
  159. }
  160. .tag {
  161. position: absolute;
  162. top: 0px;
  163. right: 0px;
  164. border-radius: 30rpx 0px 0px 30rpx;
  165. box-sizing: content-box;
  166. padding: 2rpx 10rpx;
  167. background: linear-gradient(90deg, #f366ff 0%, #5e98ff 100%);
  168. white-space: nowrap;
  169. }
  170. }
  171. .option-active {
  172. background-color: var(--color-primary);
  173. color: #fff;
  174. }
  175. }
  176. </style>