hookehuyr

fix(payCard): 添加支付按钮加载状态防止重复点击

添加isPaymentLoading状态控制支付按钮,防止用户重复点击
处理支付过程中可能出现的错误并显示相应提示
确保在支付完成或失败后清除加载状态
...@@ -28,10 +28,11 @@ ...@@ -28,10 +28,11 @@
28 <nut-button 28 <nut-button
29 block 29 block
30 color="#fb923c" 30 color="#fb923c"
31 - :disabled="!hasAgreed && !isChecked" 31 + :disabled="(!hasAgreed && !isChecked) || isPaymentLoading"
32 + :loading="isPaymentLoading"
32 @tap="goToPay" 33 @tap="goToPay"
33 > 34 >
34 - 立即支付 35 + {{ isPaymentLoading ? '处理中...' : '立即支付' }}
35 </nut-button> 36 </nut-button>
36 </view> 37 </view>
37 </nut-action-sheet> 38 </nut-action-sheet>
...@@ -110,6 +111,9 @@ const isChecked = ref(false); ...@@ -110,6 +111,9 @@ const isChecked = ref(false);
110 const hasAgreed = ref(false); 111 const hasAgreed = ref(false);
111 const protocolVisible = ref(false); 112 const protocolVisible = ref(false);
112 113
114 +// 支付loading状态
115 +const isPaymentLoading = ref(false);
116 +
113 // 支付协议内容 117 // 支付协议内容
114 const protocolContent = ref(` 118 const protocolContent = ref(`
115 1. 用户在使用捡个电驴支付服务时,需遵守相关法律法规。 119 1. 用户在使用捡个电驴支付服务时,需遵守相关法律法规。
...@@ -220,10 +224,14 @@ const handleAgreeProtocol = async () => { ...@@ -220,10 +224,14 @@ const handleAgreeProtocol = async () => {
220 } 224 }
221 } catch (error) { 225 } catch (error) {
222 console.error('更新协议状态失败:', error) 226 console.error('更新协议状态失败:', error)
227 + throw error // 重新抛出错误,让goToPay函数处理
223 } 228 }
224 } 229 }
225 230
226 const goToPay = async () => { 231 const goToPay = async () => {
232 + // 防止重复点击
233 + if (isPaymentLoading.value) return
234 +
227 // 检查协议状态 235 // 检查协议状态
228 if (!hasAgreed.value && !isChecked.value) { 236 if (!hasAgreed.value && !isChecked.value) {
229 Taro.showToast({ 237 Taro.showToast({
...@@ -233,6 +241,10 @@ const goToPay = async () => { ...@@ -233,6 +241,10 @@ const goToPay = async () => {
233 return 241 return
234 } 242 }
235 243
244 + // 设置loading状态
245 + isPaymentLoading.value = true
246 +
247 + try {
236 // 如果用户勾选了协议但还未提交,先处理协议同意 248 // 如果用户勾选了协议但还未提交,先处理协议同意
237 if (!hasAgreed.value && isChecked.value) { 249 if (!hasAgreed.value && isChecked.value) {
238 await handleAgreeProtocol() 250 await handleAgreeProtocol()
...@@ -286,10 +298,24 @@ const goToPay = async () => { ...@@ -286,10 +298,24 @@ const goToPay = async () => {
286 showCancel: false, 298 showCancel: false,
287 }); 299 });
288 } 300 }
301 + },
302 + complete: () => {
303 + // 支付完成后清除loading状态
304 + isPaymentLoading.value = false
289 } 305 }
290 }); 306 });
291 } 307 }
292 } 308 }
309 + } catch (error) {
310 + console.error('支付过程出错:', error)
311 + Taro.showToast({
312 + title: '支付失败,请重试',
313 + icon: 'error'
314 + })
315 + } finally {
316 + // 确保loading状态被清除
317 + isPaymentLoading.value = false
318 + }
293 } 319 }
294 </script> 320 </script>
295 321
......