submitPay.vue 3.92 KB
<template>
  <view class="pay-order-container">
  

    <view class="order-info">
   
      <view class="info-item total-price">
        <text class="label">支付总费用:</text>
        <text class="value red">{{ price ?? 0 }}</text>
      </view>
    </view>

    <view class="pay-type-section">
      <text class="section-title">选择支付方式</text>
      <radio-group :value="payType" @change="handlePayTypeChange">
        <label class="radio-item">
          <radio value="0" color="#E60012" :checked="payType === '0'" />
          <view class="pay-method">
            <image class="icon" src="/static/min.png" mode="widthFix"></image>
            <text class="pay-name">民生付</text>
          </view>
        </label>
      </radio-group>
    </view>

    <!-- 底部支付按钮 -->
    <view class="fixed-bottom">
      <button class="pay-btn red-bg" :loading="payLoading" @click="handlePay">立即支付</button>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app';
import * as api from '@/common/api.js'

// 核心数据
const formData = ref({})       // 订单统计数据
const price = ref('')        // 核心业务ID
const payType = ref('0')       // 支付方式(默认0=民生付)
const payLoading = ref(false)  // 支付按钮加载状态

// 页面加载接收参数
onLoad(async (options) => {
  console.log('订单ID:', options.price)
  if (options.price) {
    price.value = options.price
  }
})


// 支付方式切换
function handlePayTypeChange(e) {
  payType.value = e.detail.value
}

// 立即支付核心逻辑
async function handlePay() {


  try {
    payLoading.value = true
    const res = await api.goPay()
    
    if (res.data?.orderId) {
      api.pcallBack2(res.data.orderId)
        uni.navigateTo({
        url: `/personal/sucPay`
      })
    }
    
    // 跳转到支付成功页
   
  } catch (err) {
    const errMsg = err?.data?.msg || err?.message || '支付失败,请稍后重试'
    uni.showToast({ title: errMsg, icon: 'none' })
  } finally {
    payLoading.value = false
  }
}
</script>

<style scoped lang="scss">
.pay-order-container {
  padding: 30rpx;
  background-color: #fff;
  min-height: 100vh;
  box-sizing: border-box;
}
.icon{
    width:30px;
}
// 页面头部
.page-header {
  text-align: center;
  padding: 20rpx 0;
  border-bottom: 1px solid #eee;
  margin-bottom: 40rpx;
  
  .title {
    font-size: 36rpx;
    font-weight: 600;
    color: #333;
  }
}

// 订单信息区域
.order-info {
  margin-bottom: 60rpx;
  
  .info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25rpx 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 32rpx;
    
    .label {
      color: #666;
    }
    
    .value {
      font-weight: 600;
      font-size: 34rpx;
    }
    
    .red {
      color: #E60012;
    }
  }
  
  .total-price {
    border-bottom: none;
    margin-top: 10rpx;
    
    .label {
      font-size: 34rpx;
      color: #333;
    }
    
    .value {
      font-size: 38rpx;
    }
  }
}

// 支付方式区域
.pay-type-section {
  margin-bottom: 80rpx;
  
  .section-title {
    font-size: 32rpx;
    color: #333;
    margin-bottom: 20rpx;
    display: block;
  }
  
  .radio-item {
    display: flex;
    align-items: center;
    font-size: 32rpx;
    padding: 10rpx 0;
    
    .pay-method {
      display: flex;
      align-items: center;
      margin-left: 10rpx;
      
      .pay-name {
        font-size: 32rpx;
        margin-left: 20rpx;
        color: #333;
      }
    }
  }
}

// 底部支付按钮
.fixed-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20rpx 30rpx 30rpx;
  background-color: #fff;
  border-top: 1px solid #eee;
  
  .pay-btn {
    width: 100%;
    height: 88rpx;
    line-height: 88rpx;
    border-radius: 44rpx;
    font-size: 34rpx;
    font-weight: 600;
  }
  
  .red-bg {
    background-color: #E60012;
    color: #fff;
  }
}
</style>