recharge.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="recharge padding30">
  3. <!-- 余额 -->
  4. <view class="blance color_fff border_radius_20">
  5. <view class="flex-center-between">
  6. <view class="font_size30 mr20">余额 ( {{appStore.moneyUnit}} )</view>
  7. <view class="font_size30" @click="toWallet">账户明细</view>
  8. </view>
  9. <view class="font_size60 bold mt30">{{appStore.userInfo?.rechargeBalance}}</view>
  10. </view>
  11. <!-- 充值金额 -->
  12. <view class="padding30 border_radius_20 bg_color_fff mt20">
  13. <view class="font_size30 bold">充值金额</view>
  14. <view class="grid-container mt30">
  15. <view class="flex-column-center bg_color_f5 border_radius_20 paddingTB20 rePrice"
  16. :class="{active: ruleId==item.ruleId }"
  17. @click="ruleId = item.ruleId;orderAmt = item.rechargeAmount"
  18. v-for="(item, index) in ruleList" :key="index">
  19. <view class="bold font_size40 color_price">{{item.rechargeAmount}}</view>
  20. <view class="font_size20 mt10 gray">{{item.offerTag}}</view>
  21. <image src="/static/img/check.png" mode="widthFix" class="checked_img" v-if="ruleId==item.ruleId"></image>
  22. </view>
  23. </view>
  24. <view class="mt30">
  25. <view class="bold font_size25">{{rechargeRuleInfo.agreementName}}</view>
  26. <view class="mt10 gary font_size25">
  27. 1.活动有效期为 {{ruleList[0]?.startTime}} 至 {{ruleList[0]?.endTime}}。
  28. </view>
  29. <view class="mt20 gary font_size25" v-html="rechargeRuleInfo.content"></view>
  30. </view>
  31. </view>
  32. <agreeRecharge ref="agreeRecharge" @setAloneChecked="setAloneChecked"></agreeRecharge>
  33. <!-- foot -->
  34. <view class="foot bg_color_fff">
  35. <view class="order_btn paddingTB20 flex_1 text_align_center" @click="submitForm">充值</view>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup>
  40. import { ref } from "vue";
  41. import { getRuleList } from "@/api/user";
  42. import { createOrder } from "@/api/order";
  43. import { wxPay,getUserInfo } from "@/utils/util.js";
  44. import { agreementRechargeRule } from "@/api/agreement";
  45. import { agreeRecharge } from "@/components/agreeRecharge.vue"
  46. import { useToast } from "@/hooks/useToast";
  47. const { Toast } = useToast();
  48. import { onLoad } from "@dcloudio/uni-app";
  49. import { useAppStore } from "@/stores/app";
  50. const appStore = useAppStore();
  51. const ruleList = ref([]);
  52. const orderId = ref('');
  53. const rechargeRuleInfo = ref('');
  54. const ruleId = ref('');
  55. const orderAmt = ref('');
  56. const aloneChecked = ref(false);
  57. onLoad(() => {
  58. getRuleListFn();
  59. agreementRechargeRuleFn();
  60. });
  61. async function submitForm(){
  62. if(!aloneChecked.value){
  63. Toast({ title: "请先阅读并同意充值协议", icon: 'none' });
  64. return;
  65. }
  66. const res = await createOrder({
  67. payMethod:0,//支付方式 0微信 1余额
  68. productType:1,//商品类型 0购买会员 1充值
  69. productId:ruleId.value,
  70. orderNum:1,//订单数量
  71. orderAmt:orderAmt.value//订单金额
  72. });
  73. //payData
  74. orderId.value = res.data.orderId;
  75. const payInfo = res.data.payData.prepayWithRequestPaymentResponse
  76. wxPay({
  77. timeStamp:payInfo.timeStamp,
  78. nonceStr:payInfo.nonceStr,
  79. packageVal:payInfo.packageVal,
  80. signType:payInfo.signType,
  81. paySign:payInfo.paySign,
  82. },to_success_pay);
  83. }
  84. function to_success_pay({isSuccess}){
  85. console.log('to_success_pay',isSuccess);
  86. uni.navigateTo({
  87. url: `/pages/recharge/success_pay?orderId=${orderId.value}&isSuccess=${isSuccess}&payMethod=0`
  88. })
  89. }
  90. function toWallet(){
  91. uni.navigateTo({
  92. url: '/pages/recharge/wallet'
  93. });
  94. }
  95. function getRuleListFn(){
  96. getRuleList().then(res => {
  97. if(res.code == 200){
  98. ruleList.value = res.data || [];
  99. if(ruleList.value.length > 0){
  100. ruleId.value = ruleList.value[0].ruleId || '';
  101. orderAmt.value = ruleList.value[0].rechargeAmount || '';
  102. }
  103. }
  104. })
  105. }
  106. function agreementRechargeRuleFn(){
  107. agreementRechargeRule().then(res => {
  108. if(res.code == 200){
  109. rechargeRuleInfo.value = res.data || {};
  110. }
  111. })
  112. }
  113. function setAloneChecked(value){
  114. aloneChecked.value = value;
  115. }
  116. </script>
  117. <style lang="less" scoped>
  118. .recharge{
  119. background: #f5f5f5;
  120. .blance{
  121. background-color: #fb7145;
  122. padding: 30rpx 30rpx 60rpx;
  123. }
  124. .rePrice{
  125. position: relative;
  126. border: 1rpx solid transparent;
  127. &.active{
  128. border: 1rpx solid #fb7145;
  129. }
  130. .checked_img{
  131. width: 40rpx;
  132. height: 40rpx;
  133. position: absolute;
  134. top: 50%;
  135. right: 20rpx;
  136. transform: translateY(-50%);
  137. }
  138. }
  139. .order_btn{
  140. background-color: #fb7145;
  141. }
  142. }
  143. </style>