| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- <template>
- <view class="payment-container">
- <!-- 收货地址 -->
- <view class="address-section">
- <view class="address-content" v-if="orderInfo">
- <view class="contact-info">
- <text class="name">{{orderInfo.name}}</text>
- <text class="phone">{{orderInfo.mobile}}</text>
- </view>
- <view class="address-detail">
- {{orderInfo.province}}{{orderInfo.city}}{{orderInfo.area}}{{orderInfo.address}}
- </view>
- </view>
- </view>
- <!-- 商品信息 -->
- <view class="goods-section">
- <view class="goods-title">商品信息</view>
- <view class="goods-item" v-for="(item, index) in orderDetails" :key="index">
- <image :src="item.productImage" mode="aspectFill" class="goods-img"></image>
- <view class="goods-info">
- <view class="goods-name">{{item.productName}}</view>
- <view class="goods-spec">{{item.skuName}}</view>
- <view class="price-num">
- <text class="price">¥{{item.unitPrice}}</text>
- <text class="num">x{{item.quantity}}</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 支付方式 -->
- <view class="pay-section">
- <view class="pay-title">支付方式</view>
- <view class="pay-method">
- <view class="method-item">
- <image src="/static/images/wxpay.png" mode="aspectFit" class="pay-icon"></image>
- <text>微信支付</text>
- </view>
- </view>
- </view>
- <!-- 订单金额信息 -->
- <view class="amount-section">
- <view class="amount-item">
- <text>商品总价</text>
- <text>¥{{orderInfo.paymentPrice}}</text>
- </view>
- <view class="amount-item total">
- <text>实付金额</text>
- <text class="total-price">¥{{orderInfo.paymentPrice}}</text>
- </view>
- </view>
- <!-- 底部支付按钮 -->
- <view class="footer">
- <view class="total-section">
- <text>实付金额:</text>
- <text class="total-price">¥{{orderInfo.paymentPrice}}</text>
- </view>
- <view class="pay-btn" @click="handlePay">
- 立即支付
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- getOrderPayDetail,
- getWxPayParams
- } from '@/config/api.js';
- export default {
- data() {
- return {
- orderId: '',
- orderInfo: {},
- orderDetails: []
- }
- },
- onLoad(options) {
- if (options.orderId) {
- console.log(this.orderId, "ORDER")
- this.orderId = options.orderId;
- this.getOrderDetail();
- } else {
- uni.showToast({
- title: '订单参数错误',
- icon: 'none'
- });
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- }
- },
- methods: {
- // 获取订单详情
- async getOrderDetail() {
- try {
- uni.showLoading({
- title: '加载中...'
- });
- const res = await getOrderPayDetail(this.orderId);
- if (res.code === 200 && res.data) {
- this.orderInfo = res.data.orderInfo.order;
- this.orderDetails = res.data.orderDetails;
- // 如果订单状态不是待付款,提示并返回
- if (this.orderInfo.status !== 1) {
- uni.showToast({
- title: '订单状态已改变',
- icon: 'none'
- });
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- }
- } else {
- uni.showToast({
- title: res.msg || '获取订单信息失败',
- icon: 'none'
- });
- }
- } catch (e) {
- console.error('获取订单详情失败:', e);
- uni.showToast({
- title: '获取订单信息失败',
- icon: 'none'
- });
- } finally {
- uni.hideLoading();
- }
- },
- // 处理支付
- async handlePay() {
- if (!this.orderInfo) {
- return uni.showToast({
- title: '订单信息错误',
- icon: 'none'
- });
- }
- try {
- // 调用后端获取支付参数
- const payRes = await getWxPayParams(this.orderId);
- if (payRes.code !== 200 || !payRes.data) {
- throw new Error(payRes.msg || '获取支付参数失败');
- }
- // 调起微信支付
- uni.requestPayment({
- provider: 'wxpay',
- timeStamp: payRes.data.timestamp,
- nonceStr: payRes.data.noncestr,
- package: payRes.data.package,
- signType: payRes.data.signType,
- paySign: payRes.data.sign,
- success: (res) => {
- uni.showToast({
- title: '支付成功',
- icon: 'success'
- });
- // 支付成功后跳转到订单列表
- setTimeout(() => {
- uni.redirectTo({
- url: '/packageOrder/pages/list/index?status=2'
- });
- }, 1500);
- },
- fail: (err) => {
- console.error('支付失败:', err);
- uni.showToast({
- title: '支付失败',
- icon: 'none'
- });
- setTimeout(() => {
- uni.redirectTo({
- url: '/packageOrder/pages/list/index?status=1'
- });
- }, 1000);
- }
- });
- } catch (e) {
- console.error('支付异常:', e);
- uni.showToast({
- title: e.message || '支付失败',
- icon: 'none'
- });
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .payment-container {
- min-height: 100vh;
- background-color: #f8f8f8;
- padding-bottom: 120rpx;
- }
- .address-section {
- background-color: #fff;
- padding: 30rpx;
- margin-bottom: 20rpx;
- .address-content {
- .contact-info {
- margin-bottom: 10rpx;
- .name {
- font-size: 32rpx;
- font-weight: bold;
- margin-right: 20rpx;
- }
- .phone {
- font-size: 28rpx;
- color: #666;
- }
- }
- .address-detail {
- font-size: 28rpx;
- color: #333;
- line-height: 1.4;
- }
- }
- }
- .goods-section {
- background-color: #fff;
- margin-bottom: 20rpx;
- .goods-title {
- font-size: 32rpx;
- font-weight: bold;
- padding: 30rpx;
- border-bottom: 1rpx solid #f5f5f5;
- }
- .goods-item {
- display: flex;
- padding: 30rpx;
- border-bottom: 1rpx solid #f5f5f5;
- .goods-img {
- width: 160rpx;
- height: 160rpx;
- border-radius: 8rpx;
- margin-right: 20rpx;
- }
- .goods-info {
- flex: 1;
- .goods-name {
- font-size: 28rpx;
- color: #333;
- margin-bottom: 10rpx;
- }
- .goods-spec {
- font-size: 24rpx;
- color: #999;
- margin-bottom: 20rpx;
- }
- .price-num {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .price {
- font-size: 32rpx;
- color: #ff4b4b;
- font-weight: bold;
- }
- .num {
- font-size: 28rpx;
- color: #999;
- }
- }
- }
- }
- }
- .pay-section {
- background-color: #fff;
- margin-bottom: 20rpx;
- .pay-title {
- font-size: 32rpx;
- font-weight: bold;
- padding: 30rpx;
- border-bottom: 1rpx solid #f5f5f5;
- }
- .pay-method {
- padding: 30rpx;
- .method-item {
- display: flex;
- align-items: center;
- .pay-icon {
- width: 48rpx;
- height: 48rpx;
- margin-right: 20rpx;
- }
- text {
- font-size: 28rpx;
- color: #333;
- }
- }
- }
- }
- .amount-section {
- background-color: #fff;
- padding: 30rpx;
- .amount-item {
- display: flex;
- justify-content: space-between;
- margin-bottom: 20rpx;
- text {
- font-size: 28rpx;
- color: #666;
- }
- &.total {
- margin-top: 30rpx;
- border-top: 1rpx solid #f5f5f5;
- padding-top: 30rpx;
- text {
- font-size: 32rpx;
- color: #333;
- font-weight: bold;
- &.total-price {
- color: #ff4b4b;
- }
- }
- }
- }
- }
- .footer {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- height: 100rpx;
- background-color: #fff;
- display: flex;
- align-items: center;
- padding: 0rpx 30rpx;
- box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
- .total-section {
- flex: 1;
- text {
- font-size: 28rpx;
- color: #333;
- &.total-price {
- font-size: 36rpx;
- color: #ff4b4b;
- font-weight: bold;
- }
- }
- }
- .pay-btn {
- width: 240rpx;
- height: 80rpx;
- background-color: #F95B5B;
- color: #fff;
- font-size: 32rpx;
- font-weight: bold;
- border-radius: 40rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- }
- </style>
|