hejianhao
2026-03-05 f3c2249c1d150ddbefa593a51ca73fd7fb45cf4c
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
115
import Taro from '@tarojs/taro';
import { View, Text, Image } from '@tarojs/components';
import { useEffect, useState } from 'react';
import './css-folder/cancel-popup.less'
 
type Props = {
    show?: boolean;
    cancelType?: number;
    startSite?: any;
    endSite?: any;
    waitMinutes?: number;
    discountAmount?: number;
    onClose?: () => void;
    onConfirm?: () => void;
}
 
export default function CancelPopup({ show = false, cancelType = 1, startSite, endSite, waitMinutes, discountAmount, onClose, onConfirm }: Props) {
    const [visible, setVisible] = useState(false);
    const [animationData, setAnimationData] = useState<any>();
    const cachedStartSite = startSite || Taro.getStorageSync('startSite') || {};
    const cachedEndSite = endSite || Taro.getStorageSync('endSite') || {};
    const startSiteName = cachedStartSite?.name || cachedStartSite?.address || '-';
    const endSiteName = cachedEndSite?.name || cachedEndSite?.address || '-';
    const waitMinutesValue = typeof waitMinutes === 'number' && !Number.isNaN(waitMinutes) ? waitMinutes : 2;
    const discountAmountValue = typeof discountAmount === 'number' && !Number.isNaN(discountAmount) ? discountAmount : 0;
 
    const STATUS_MAP = {
        1: {
            title: `${waitMinutesValue}分钟内预计有车,确定取消吗?`,
            tip: `本单限时优惠${discountAmountValue}元,重新叫车可能等待更久`,
        },
        2: {
            title: '正在为您重新派车中...',
            tip: '当前车辆无法继续服务',
        },
        3: {
            title: '附近没有空余车辆,已为您取消订单',
            tip: '当前运力紧张,建议您稍后重新发起订单',
        },
        4: {
            title: '订单已取消',
            tip: '已为您取消订单,期待您下次体验',
        },
    }
 
    useEffect(() => {
        if (show && !visible) {
            setVisible(true);
            const animation = Taro.createAnimation({
                duration: 300,
                timingFunction: 'ease-out'
            });
            animation.translateY(0).step();
            setAnimationData(animation.export());
        } else if (!show && visible) {
            const animation = Taro.createAnimation({
                duration: 300,
                timingFunction: 'ease-in'
            });
            animation.translateY(500).step();
            setAnimationData(animation.export());
 
            setTimeout(() => {
                setVisible(false);
            }, 300);
        }
    }, [show]);
 
    if (!visible) return null;
 
    return (
        <View className='cancel-popup' catchMove>
            <View className='cancel-mask'></View>
            <View className='cancel-content' animation={animationData}>
                <View className='cancel-box'>
                    <Image onClick={onClose} className='cancel-icon' src={require('../../../assets/close-icon.png')} />
                </View>
                <View className='cancel-tip-box'>
                    <View className='cancel-tip-box-title'>{STATUS_MAP[cancelType].title}</View>
                    {
                        ((discountAmountValue > 0 && cancelType === 1) || cancelType !== 1) &&
                        <View className='cancel-tip-box-desc color1'>
                            本单限时优惠{discountAmountValue}元,重新叫车可能等待更久
                        </View>
                    }
                    <View className={`cancel-tip-box-desc ${cancelType === 4 && 'color1'}`}>{STATUS_MAP[cancelType].tip}</View>
                </View>
                {
                    [3, 4].includes(cancelType) ?
                        <View>
                            <View className='cancel-site-box'>
                                <View className='cancel-site-box-icon'>
                                    <View className='cancel-site-box-icon-start'></View>
                                    <Image src={require('../../../assets/dotted-line.png')} />
                                    <View className='cancel-site-box-icon-end'></View>
                                </View>
                                <View className='cancel-site-box-content'>
                                    <View>{startSiteName}</View>
                                    <View>{endSiteName}</View>
                                </View>
                            </View>
                            <View className='cancel-btn-box'>
                                <View className='cancel-btn-again' onClick={onConfirm}>再来一单</View>
                            </View>
                        </View>
                        :
                        <View className='cancel-btn-box'>
                            <View className='cancel-btn-cancel' onClick={onConfirm}>确认取消</View>
                            <View className='cancel-btn-again' onClick={onClose}>再等等</View>
                        </View>
                }
            </View>
        </View>
    )
}