hookehuyr

支付金额为0时逻辑调整

1 /* 1 /*
2 * @Date: 2023-12-22 10:29:37 2 * @Date: 2023-12-22 10:29:37
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-12-28 09:55:37 4 + * @LastEditTime: 2024-01-17 15:56:50
5 * @FilePath: /meihuaApp/src/api/index.js 5 * @FilePath: /meihuaApp/src/api/index.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -20,6 +20,7 @@ const Api = { ...@@ -20,6 +20,7 @@ const Api = {
20 ORDER_CANCEL: '/srv/?a=room_data&t=order_cancel', 20 ORDER_CANCEL: '/srv/?a=room_data&t=order_cancel',
21 PAY: '/srv/?a=pay', 21 PAY: '/srv/?a=pay',
22 PAY_CHECK: '/srv/?a=pay_check', 22 PAY_CHECK: '/srv/?a=pay_check',
23 + ORDER_SUCCESS: '/srv/?a=room_data&t=order_success',
23 } 24 }
24 25
25 /** 26 /**
...@@ -118,3 +119,10 @@ export const myOrderAPI = (params) => fn(fetch.get(Api.MY_ORDER, params)); ...@@ -118,3 +119,10 @@ export const myOrderAPI = (params) => fn(fetch.get(Api.MY_ORDER, params));
118 * @returns 119 * @returns
119 */ 120 */
120 export const orderCancelAPI = (params) => fn(fetch.post(Api.ORDER_CANCEL, params)); 121 export const orderCancelAPI = (params) => fn(fetch.post(Api.ORDER_CANCEL, params));
122 +
123 +/**
124 + * @description: 订单成功
125 + * @param id
126 + * @returns
127 + */
128 +export const orderSuccessAPI = (params) => fn(fetch.post(Api.ORDER_SUCCESS, params));
......
1 <!-- 1 <!--
2 * @Date: 2023-12-20 14:11:11 2 * @Date: 2023-12-20 14:11:11
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-12-29 17:59:42 4 + * @LastEditTime: 2024-01-17 16:00:33
5 * @FilePath: /meihuaApp/src/components/payCard.vue 5 * @FilePath: /meihuaApp/src/components/payCard.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 import Taro from '@tarojs/taro' 22 import Taro from '@tarojs/taro'
23 import { ref, watch, onMounted, onUnmounted } from 'vue' 23 import { ref, watch, onMounted, onUnmounted } from 'vue'
24 import { getCurrentPageUrl } from "@/utils/weapp"; 24 import { getCurrentPageUrl } from "@/utils/weapp";
25 -import { payAPI, payCheckAPI } from '@/api/index' 25 +import { payAPI, payCheckAPI, orderSuccessAPI } from '@/api/index'
26 26
27 /** 27 /**
28 * 格式化时间 28 * 格式化时间
...@@ -90,43 +90,62 @@ onUnmounted(() => { ...@@ -90,43 +90,62 @@ onUnmounted(() => {
90 }) 90 })
91 91
92 const goToPay = async () => { 92 const goToPay = async () => {
93 - // 获取支付参数 93 + if (price.value > 0) { // 金额大于0
94 - const { code, data } = await payAPI({ order_id: id.value }); 94 + // 获取支付参数
95 - if (code) { 95 + const { code, data } = await payAPI({ order_id: id.value });
96 - let pay = data; 96 + if (code) {
97 - // 触发微信支付操作 97 + let pay = data;
98 - wx.requestPayment({ 98 + // 触发微信支付操作
99 - timeStamp: pay.timeStamp, 99 + wx.requestPayment({
100 - nonceStr: pay.nonceStr, 100 + timeStamp: pay.timeStamp,
101 - package: pay.package, 101 + nonceStr: pay.nonceStr,
102 - signType: pay.signType, 102 + package: pay.package,
103 - paySign: pay.paySign, 103 + signType: pay.signType,
104 - success: async (result) => { 104 + paySign: pay.paySign,
105 - emit('close'); // 关闭支付弹框 105 + success: async (result) => {
106 - Taro.showToast({ 106 + emit('close'); // 关闭支付弹框
107 - title: '支付成功', 107 + Taro.showToast({
108 - icon: 'success', 108 + title: '支付成功',
109 - duration: 1000 109 + icon: 'success',
110 - }); 110 + duration: 1000
111 - // 支付成功后,调用检查接口 111 + });
112 - const pay_success = await payCheckAPI({ order_id: id.value }); 112 + // 支付成功后,调用检查接口
113 - if (pay_success.code) { 113 + const pay_success = await payCheckAPI({ order_id: id.value });
114 - let current_page = getCurrentPageUrl(); 114 + if (pay_success.code) {
115 - if (current_page === 'pages/my/index') { // 我的页面打开 115 + let current_page = getCurrentPageUrl();
116 - // 刷新当前页面 116 + if (current_page === 'pages/my/index') { // 我的页面打开
117 - Taro.reLaunch({ 117 + // 刷新当前页面
118 - url: '/pages/my/index?tab_index=5' 118 + Taro.reLaunch({
119 - }); 119 + url: '/pages/my/index?tab_index=5'
120 - } 120 + });
121 - if (current_page === 'pages/detail/index') { // 订房确认页打开 121 + }
122 - // 跳转订单成功页 122 + if (current_page === 'pages/detail/index') { // 订房确认页打开
123 - Taro.navigateTo({ 123 + // 跳转订单成功页
124 - url: '/pages/payInfo/index', 124 + Taro.navigateTo({
125 - }); 125 + url: '/pages/payInfo/index',
126 + });
127 + }
126 } 128 }
127 } 129 }
130 + });
131 + }
132 + } else { // 金额等于0
133 + const { code, data } = await orderSuccessAPI({ id: id.value });
134 + if (code) {
135 + let current_page = getCurrentPageUrl();
136 + if (current_page === 'pages/my/index' || current_page === 'pages/confirm/index') { // 我的页面打开获取确认订单页价格为零
137 + // 刷新当前页面
138 + Taro.reLaunch({
139 + url: '/pages/my/index?tab_index=5'
140 + });
128 } 141 }
129 - }); 142 + if (current_page === 'pages/detail/index') { // 订房确认页打开
143 + // 跳转订单成功页
144 + Taro.navigateTo({
145 + url: '/pages/payInfo/index',
146 + });
147 + }
148 + }
130 } 149 }
131 } 150 }
132 </script> 151 </script>
......