forked from nsjcy/frontEnd/nsjcy

liuwh
2020-02-20 6383764128f9f38513df1a55449b230a7b29092a
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
 * 徐祥健<xuxj@hugeinfo.com.cn>
 * 2018年8月28日 10:41
 *
 */
 
 
import React from 'react';
 
import HeadView from '../view/HeadView';
import TableBtnView from '../view/TableBtnView';
import { Divider, Modal, message, Tooltip, Progress } from 'antd'
import moment from 'moment'
import Fetch from '../fetch';
import { domain } from '../fetch/_fetch';
import TableView from '../view/TableView';
const confirm = Modal.confirm;
function typeOfName(type) {
    switch (type) {
        case 0:
            return '未发布';
        case 1:
            return '报名中';
        case 2:
            return '活动中';
        case 3:
            return '已结束';
        case 100:
            return '已摇号';
    }
}
 
function typeStatus(type) {
    switch (type) {
        case 'act_1':
            return "南检活动";
        case 'act_2':
            return "法治培训";
        case 'act_3':
            return "普法预约";
    }
}
export default class ActiveManage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            resetKey: Date.now()
        };
    }
 
    componentDidMount() {
        document.title = '活动管理';
        this.getData();
    }
    getData = () => {
        // this.setState({
        //     data: []
        // });
        Fetch.activeManage()
            .then(res => {
                for (var i = 0; i < res.length; i++) {
                    res[i]['index'] = i + 1;
                }
                this.setState({
                    data: res
                });
            });
    }
    showModal = (id) => {
        this.props.history.push("/activeManageEdit/" + id);
    }
 
    signIn= (id) => {
        window.open('index.html#/signIn/' + id);
    }
 
    pulish = (id) => {
        confirm({
            title: '确认要发布这条活动吗?',
            onOk: () => {
                Fetch.publishActive(id)
                    .then(data => {
                        if (data.code == 0) {
                            message.success("发布成功!")
                            this.setState({
                                resetKey: Date.now()
                            }, this.getData);
                        } else {
                            message.error('发布失败,请联系管理员', 2)
                        }
                    })
            }
        });
    }
    deleteItems = (id) => {
        confirm({
            title: '确认要删除这条数据吗?',
            onOk: () => {
                Fetch.deleteActive(id)
                    .then(data => {
                        if (data.code == 0) {
                            message.success("删除成功!")
                            this.setState({
                                resetKey: Date.now()
                            }, this.getData);
                        } else {
                            message.error('删除失败,请联系管理员', 2)
                        }
                    })
            }
        });
    }
    render() {
        const columns = [{
            title: '序号',
            dataIndex: 'index',
            key: 'index'
        }, {
            title: '活动类型',
            dataIndex: 'activityType',
            key: 'activityType',
            render: text => <span>{typeStatus(text)}</span>
        }, {
            title: '活动标题',
            dataIndex: 'title',
            key: 'title'
        }, {
            title: '发起人',
            dataIndex: 'createrName',
            key: 'createrName'
        }, {
            title: '起始时间',
            dataIndex: 'startTime',
            key: 'startTime',
            render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
        }, {
            title: '地点',
            dataIndex: 'address',
            key: 'address'
        }, {
            title: '活动状态',
            dataIndex: 'status',
            key: 'status',
            render: text => <span>{typeOfName(text)}</span>
 
        }, {
            title: '报名人数',
            dataIndex: 'totalNum',
            key: 'totalNum',
            render: (_, { totalNum, applyNum }) => <Progress percent={applyNum * 100 / totalNum} format={percent => `${applyNum}/${totalNum} `} />,
        }, {
            title: '操作',
            key: 'action',
            render: (text, record) => (
                (
                    record.status == 0 ?
                        <span>
                            <label className='theme-color' onClick={() => this.showModal(record.id)} style={{ cursor: 'pointer' }}>修改</label>
                            <Divider type="vertical" />
                            <label className='theme-color' onClick={() => this.pulish(record.id)} style={{ cursor: 'pointer' }}>发布</label>
                            <Divider type="vertical" />
                            <label className='theme-color' onClick={() => this.deleteItems(record.id)} style={{ cursor: 'pointer' }}>删除</label>
                        </span>
                        : 
                    record.status == 2 ?
                            <span>
                                <label className='theme-color' onClick={() => this.showModal(record.id)} style={{ cursor: 'pointer' }}>查看</label>
                                <Divider type="vertical" />
                                <label className='theme-color' onClick={() => this.signIn(record.id)} style={{ cursor: 'pointer' }}>签到上墙</label>
                            </span>
                    :
                    <span><label className='theme-color' onClick={() => this.showModal(record.id)} style={{ cursor: 'pointer' }}>查看</label></span>
 
                )
            ),
        }];
        const { data, resetKey } = this.state;
        return (
            <div className="app-page">
                <HeadView history={this.props.history} />
                <TableBtnView key={-resetKey} type="infoManage" name='活动一览' btnName='活动发布' onClick={() => this.showModal('new')}>
                </TableBtnView>
                <TableView columns={columns} data={data} pageSize='10' size='default' />
            </div>
        );
    }
 
}