zhouxiantao
8 days ago 03193b2a27a2c23e10f3a2f298de9c1142116780
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
 * @author 韩天尊
 * @time 2024-01-15
 * @version 1.0.0
 * @description 活动签到页面组件
 */
import React, { useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useAppContext } from '../context/AppContext';
import PageHeader from '../components/PageHeader';
 
const ActivityCheckinPage: React.FC = () => {
    const { id } = useParams<{ id: string }>();
    const navigate = useNavigate();
    const { state, dispatch } = useAppContext();
    
    // 根据ID获取活动信息
    const activity = state.activities.find(a => a.id === Number(id));
    const [checkinLocation, setCheckinLocation] = useState('');
    const [checkinNotes, setCheckinNotes] = useState('');
 
    if (!activity) {
        return (
            <div className="page">
                <PageHeader title="活动签到" />
                <div style={{ padding: '20px', textAlign: 'center' }}>
                    活动不存在
                </div>
            </div>
        );
    }
 
    // 处理签到
    const handleCheckin = () => {
        if (!checkinLocation) {
            alert('请填写签到地点');
            return;
        }
 
        // 创建签到记录
        const checkinRecord = {
            id: Date.now(),
            activityId: activity.id,
            activityTitle: activity.title,
            checkinTime: new Date().toLocaleString(),
            checkinLocation: checkinLocation,
            checkoutTime: '',
            checkoutLocation: '',
            status: 'checked'
        };
 
        // 添加到签到记录
        dispatch({ type: 'ADD_CHECKIN_RECORD', payload: checkinRecord });
 
        // 更新用户积分
        dispatch({ type: 'UPDATE_USER_POINTS', payload: activity.points });
 
        // 跳转到成功页面
        navigate('/checkin-success');
    };
 
    return (
        <div className="page">
            <PageHeader title="活动签到" />
            
            <div className="checkin-container">
                {/* 活动信息 */}
                <div style={{ 
                    background: 'white', 
                    borderRadius: 'var(--border-radius)', 
                    padding: '16px',
                    marginBottom: '16px',
                    boxShadow: 'var(--shadow)'
                }}>
                    <h3 style={{ marginBottom: '12px', fontSize: '16px', fontWeight: '600', color: 'var(--text-color)' }}>
                        <i className="fas fa-info-circle" style={{ color: 'var(--primary-color)', marginRight: '8px' }}></i>
                        活动信息
                    </h3>
                    <div style={{ fontSize: '14px', color: 'var(--text-color)', lineHeight: '1.6' }}>
                        <div style={{ marginBottom: '8px' }}>
                            <strong>活动名称:</strong>{activity.title}
                        </div>
                        <div style={{ marginBottom: '8px' }}>
                            <strong>活动时间:</strong>{activity.time}
                        </div>
                        <div style={{ marginBottom: '8px' }}>
                            <strong>活动地点:</strong>{activity.location}
                        </div>
                        <div style={{ marginBottom: '8px' }}>
                            <strong>可获得积分:</strong>
                            <span className="activity-points" style={{ marginLeft: '8px' }}>
                                +{activity.points}分
                            </span>
                        </div>
                    </div>
                </div>
 
                {/* 签到表单 */}
                <div className="checkin-form">
                    <div className="form-group">
                        <label>签到地点 *</label>
                        <input 
                            type="text" 
                            placeholder="请输入签到地点"
                            value={checkinLocation}
                            onChange={(e) => setCheckinLocation(e.target.value)}
                        />
                    </div>
 
                    <div className="form-group">
                        <label>备注(可选)</label>
                        <textarea 
                            placeholder="请输入备注信息"
                            value={checkinNotes}
                            onChange={(e) => setCheckinNotes(e.target.value)}
                        />
                    </div>
 
                    {/* 提交按钮 */}
                    <button className="submit-btn" onClick={handleCheckin}>
                        <i className="fas fa-check-circle" style={{ marginRight: '8px' }}></i>
                        确认签到
                    </button>
                </div>
 
                {/* 签到说明 */}
                <div style={{ 
                    background: 'white', 
                    borderRadius: 'var(--border-radius)', 
                    padding: '16px',
                    marginTop: '16px',
                    boxShadow: 'var(--shadow)'
                }}>
                    <h4 style={{ marginBottom: '8px', color: 'var(--text-color)' }}>
                        <i className="fas fa-info-circle" style={{ color: 'var(--primary-color)', marginRight: '8px' }}></i>
                        签到说明
                    </h4>
                    <ul style={{ 
                        margin: 0, 
                        paddingLeft: '20px', 
                        color: 'var(--text-light)',
                        fontSize: '14px',
                        lineHeight: '1.6'
                    }}>
                        <li>请确保在活动开始前完成签到</li>
                        <li>签到地点必须与活动地点一致</li>
                        <li>签到成功后即可获得相应积分</li>
                        <li>如需签退,请在活动结束后操作</li>
                    </ul>
                </div>
            </div>
        </div>
    );
};
 
export default ActivityCheckinPage;