Liuyi
2024-11-12 0ed8e370659ad4e0582301ae31cfa155da114590
pages/recharge/index.vue
@@ -1,9 +1,10 @@
<script setup>
   import{ ref ,onMounted} from 'vue'
   import { wxPayApi } from '../../api/index.js'
   import { wxPayApi,rechargeApi } from '../../api/index.js'
   
   const choosedMoney = ref(50)
   const disabled = ref(true)
   const userInfo = JSON.parse(uni.getStorageSync('userInfo'))
   //选择金额
   const moneyList = ref([
      {value:50,active:true},
@@ -51,7 +52,6 @@
   //    payList.value[index1].checked = true
   //    payMethod.value = payList.value[index1].value
   // }
   const e = ref('123125')
   async function submit(){
      let money = ''
      if(disabled.value){
@@ -59,8 +59,27 @@
      }else{
         money = Number(otherMoney.value)
      }
      await wxPayApi({businessType:1,tradeAmount:money}).then((res) =>{
            e.value = res
      let data = {
              cardNumber:userInfo.waterCardNumber,
              paymentMethod:1,
              rechargeAmount:money
          }
      //生成订单
      await rechargeApi(data).then(async(res) =>{
         if(res.code == 200){
            let data = {
               businessType:1,
               businessNo:res.data
               }
            //发起支付
            await wxPay(data)
         }
      })
   }
   //微信支付
   async function wxPay(data){
      await wxPayApi(data).then((res) =>{
         if(res.code == 200){
            //调用微信官方支付接口弹出付款界面,输入密码扣款
            wx.requestPayment({
@@ -143,7 +162,6 @@
               </view>
            </view>
         </view>
         <text>{{e}}</text>
         <view class="submit-btn" @click="submit()">立即充值</view>
      </view>
   </view>