zjk
2026-07-29 429208957f30ab9eedc5533a81aaa284048d09f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import Taro, { useDidShow } from '@tarojs/taro';
import { View, Text, Image } from '@tarojs/components';
import { useCallback, useState } from 'react';
import { getPayPwd, RobotaxiPaySettingStatus, setPayPwd } from '../../api/payment';
import { withRobotaxiWhitelist } from '../../../utils/whitelist';
import { showToast } from '../../components/toast';
import { withToast } from '../../components/toast/with-toast';
 
import './index.less';
 
function PaymentSettingDetail() {
  const [isPayEnabled, setIsPayEnabled] = useState(true); // 当前免密支付状态
  const [isOperating, setIsOperating] = useState(false); // 当前是否正在关闭
 
  /**
   * 刷新当前支付设置状态。
   */
  const refreshPayStatus = useCallback(async () => {
    const response = await getPayPwd();
    const nextStatus = response === true;
    setIsPayEnabled(nextStatus);
    return nextStatus;
  }, []);
 
  /**
   * 返回上一页,不存在上一页时回个人中心。
   */
  const navigateBackToList = useCallback(() => {
    Taro.navigateBack({
      fail: () => {
        Taro.reLaunch({ url: '/robotaxi/pages/payment-setting/index' });
      }
    });
  }, []);
 
  /**
   * 关闭微信免密支付。
   */
  const handleClosePayment = async () => {
    if (isOperating || !isPayEnabled) {
      return;
    }
 
    const modalResult = await Taro.showModal({
      title: '',
      content: '确定关闭微信免密支付吗?',
      cancelText: '取消',
      confirmText: '确认',
      confirmColor: '#5A960A'
    });
 
    if (!modalResult.confirm) {
      return;
    }
 
    try {
      setIsOperating(true);
      await setPayPwd(RobotaxiPaySettingStatus.Disable);
      showToast({
        title: '微信免密支付已关闭',
        icon: 'none'
      });
      setTimeout(() => {
        navigateBackToList();
      }, 300);
    } catch (error) {
      showToast({
        title: '关闭失败',
        icon: 'none'
      });
    } finally {
      setIsOperating(false);
    }
  };
 
  useDidShow(() => {
    refreshPayStatus()
      .then((nextStatus) => {
        if (!nextStatus) {
          navigateBackToList();
        }
      })
      .catch(() => {
        showToast({
          title: '查询支付设置失败',
          icon: 'none'
        });
      });
  });
 
  return (
    <View className='payment-setting-detail-page'>
      <View className='payment-setting-detail-content'>
        <Image className='payment-setting-detail-icon' src="https://s.xiaopeng.com/xp-fe/robot-taxi/imgs/pay-max-icon.png" />
        <View className='payment-setting-detail-title'>已开通微信免密支付</View>
        <Text className='payment-setting-detail-description'>
          将优先从您指定的扣款方式扣款,若无法扣除,
        </Text>
        <Text className='payment-setting-detail-description'>
          则从其他支付方式扣款
        </Text>
      </View>
 
      <View
        className={`payment-setting-detail-close ${isOperating ? 'payment-setting-detail-close-disabled' : ''}`}
        onClick={handleClosePayment}
      >
        关闭微信免密支付
      </View>
    </View>
  );
}
 
export default withRobotaxiWhitelist(withToast(PaymentSettingDetail));