forked from nsjcy/frontEnd/nsjcy

xuxj
2020-04-08 4a76c06e7f754e232338ce7e075c08924cffe209
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React from 'react';
 
import HeadView from '../view/HeadView';
import TableBtnView from '../view/TableBtnView';
import CommonSearchForm from '../view/CommonSearchForm';
import TableView from '../view/TableView';
import { Input, Button, DatePicker, Divider, message, Popconfirm, Select, Badge, Tooltip } from 'antd';
import moment from 'moment';
import Fetch from '../fetch';
const Option = Select.Option;
function typeOfName(type) {
    switch (type) {
        case 1:
            return "待处理";
        case 2:
            return "已受理";
        case 3:
            return "已反馈";
    }
}
 
const activityStatusIds = {
    1: '待处理',
    2: '已受理',
    3: '已反馈',
}
 
const activityStatusList = [
    1,
    2,
    3,
]
export default class ApplyFor extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            formData: {
                __key: Date.now(),
                page: 1,
                size: 10,
            },
            resetKey: Date.now(),
            loading: false
        };
    }
 
    componentDidMount() {
 
        document.title = '入职申请';
        this.getData();
    }
 
    setFormData = data => {
        console.log('form', data);
        this.setState({
            formData: data,
        });
    }
 
    searchonClick = data => {
        console.log('form', data);
        this.setState({
            formData: data,
        });
        this.setState({ loading: true })
        Fetch.entryQuery({ ...data, type: 1 })
            .then(res => {
                console.log(res)
                for (var i = 0; i < res.rows.length; i++) {
                    res.rows[i]['index'] = i + 1;
                }
                this.setState({
                    data: res.rows,
                    loading: false
                });
            });
    }
 
    getData = () => {
        this.setState({ loading: true })
        Fetch.entryQuery({ ...this.state.formData, type: 1 })
            .then(res => {
                console.log(res)
                for (var i = 0; i < res.rows.length; i++) {
                    res.rows[i]['index'] = i + 1;
                }
                this.setState({
                    data: res.rows,
                    loading: false
                });
            });
    }
    onInputChange = ({ target: { value, name } }) => {
        this.setState(({ formdata }) => ({
            formdata: {
                ...formdata,
                [name]: value
            }
        }))
    }
    showModal = (id) => {
        this.props.history.push("/entry/ApplyForEdit/" + id);
    }
 
    Seaech = () => {
        const { formdata } = this.state;
        Fetch.getSweeping(formdata)
            .then(res => {
                for (var i = 0; i < res.length; i++) {
                    res[i]['index'] = i + 1;
                }
                this.setState({
                    data: res
                });
            });
    }
    Reset = () => {
        this.setState({
            resetKey: Date.now(),
            formdata: {}
        }, this.getData);
    }
 
    confirm = (e) => {
        console.log(e);
        this.setState({ loading: true })
        Fetch.socialDelete(e).then(res => {
            if (res.code == 0) {
                console.log(res)
                this.setState({ loading: false })
                message.success('删除成功');
                this.getData();
            } else {
                this.setState({ loading: false })
                message.error('删除失败,请联系管理员', 2)
            }
        }
        )
    }
    render() {
        const columns = [{
            title: '申请人',
            dataIndex: 'createrName',
            key: 'createrName'
        }, {
            title: '申请时间',
            dataIndex: 'createTime',
            key: 'createTime',
            render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
        }, {
            title: '申请理由',
            dataIndex: 'reason',
            key: 'reason',
            render: text => <Tooltip title={text}>
                <span width='500px'>{text}</span>
            </Tooltip>
        }, {
            title: '状态',
            dataIndex: 'status',
            key: 'status',
            render: text => (
                text == 1 ? <Badge style={{ backgroundColor: '#6C757C' }} count={'待处理'} /> : text == 2 ? <Badge style={{ backgroundColor: '#F1C40F' }} count={'已受理'} /> : <Badge style={{ backgroundColor: '#2ECC71' }} count={'已反馈'} />
            )
        }, {
            title: '操作',
            key: 'action',
            render: (text, record) => (
                <span>
                    <a onClick={() => this.showModal(record.id)}>详情</a>
                    {
                        record.status == 1 ?
                            <React.Fragment>
                                <Divider type="vertical" />
                                <Popconfirm
                                    title="确认删除任务吗?"
                                    id={record.id}
                                    onConfirm={e => this.confirm(record.id)}
                                    okText="确定"
                                    cancelText="取消"
                                >
                                    <a href="#">删除</a>
                                </Popconfirm>
                            </React.Fragment> : ''
                    }
                </span>
            ),
        }];
        const { data, loading, resetKey, formData } = this.state;
        return (
            <div className="app-page">
                <HeadView history={this.props.history} />
                <div style={{ marginLeft: '90%', marginBottom: '20px', marginTop: '20px' }}>
                    <Button type="primary" size='large' onClick={() => this.showModal('new')}>添加申请</Button>
                </div>
                <div style={{ background: '#fff', margin: 20 }}>
                    <CommonSearchForm
                        {...this.props}
                        formData={formData}
                        setFormData={this.setFormData}
                        searchonClick={this.searchonClick}
                        pathName={this.props.location.pathname}
                        data={[
                            {
                                type: 'select', name: '状态', label: '活动状态', key: 'status', list: activityStatusList.map(key => ({
                                    id: key,
                                    name: activityStatusIds[key]
                                })),
                            },
                            {
                                type: 'rangePicker',
                                label: '申请时间',
                                name: JSON.stringify(['开始时间', '结束时间']),
                                key: JSON.stringify(['startTime', 'endTime']),
                                keylistName: 'rangeTimelist',
                            },
                        ]} />
                    <TableView columns={columns} data={data} pageSize='10' size='default' loading={loading} />
                </div>
            </div>
        );
    }
 
}