forked from nsjcy/frontEnd/nsjcy

bug
liuwh
2020-03-24 51351c2d8c7297cb3f96e572c0e1a110ce8a5073
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
 
import React from 'react';
 
import { Row, Col, Input, DatePicker, Button, Modal, Upload, Icon, message, Divider, Breadcrumb, Badge, Select, Popconfirm, Spin } from 'antd';
const { TextArea } = Input;
import HeadView from '../view/HeadView';
import BusDetailView from '../view/BusDetailView';
import TableView from '../view/TableView';
import ImageBoxView from '../view/ImageBoxView'
// 引入编辑器以及编辑器样式
import Fetch from '../fetch';
import moment from 'moment';
const format = 'HH:mm';
const { Option } = Select;
const yearFormat = 'YYYY-MM-DD';
const divStyle = {
    margin: '20px'
}
const domain = Fetch.domain;
 
function typeStatus(type) {
    switch (type) {
        case 1:
            return "待审核";
        case 2:
            return "未签到";
        case 3:
            return "已签到";
        case 4:
            return "不通过";
        case 99:
            return "取消";
    }
}
export default class ApplyForEdit extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            dateSource: [],
            savedate: {},
            formdata: {},
            fileList: [],
            previewVisible: false,
            previewImage: '',
            visible: false,
            hitList: [],
            num: 0,
            taskType: 1,
            disabled: true,
            status: '',
            loading: false,
        };
    }
 
    componentDidMount() {
        document.title = '入职申请详情';
        this.getDetail();
    }
 
    getDetail = () => {
        const { id } = this.props.match.params;
        this.setState({ loading: true })
        Fetch.entryFind(id)
            .then(res => {
                console.log(res)
                this.setState({
                    savedate: {
                        ...res,
                    },
                    disabled: res.status ? true : false,
                    loading: false,
                    fileList: res.list ? res.list.map((item, index) => ({ uid: index, id: item.id, name: item.name, status: 'done', url: domain + `/api/v1/attachment/download/${item.id}?online=false` })) : []
                });
 
            })
    }
 
    saveInputChange = ({ target: { value, name } }) => {
        this.setState(({ savedate }) => ({
            savedate: {
                ...savedate,
                [name]: value
            }
        }))
    }
 
    submit = () => {
        const { savedate, fileList } = this.state;
        console.log(fileList);
        if (!savedate.reason) {
            message.warning("申请理由不能为空");
            return;
        }
        if (fileList === []) {
            message.warning("请上传申请附件");
            return;
        }
 
        Fetch.entrySave(savedate)
            .then(res => {
                if (res.statuscode === 1) {
                    message.success("提交成功!");
                    this.props.history.push("/entry/applyFor")
                } else {
                    message.error('保存失败,请联系管理员', 2)
                }
            });
    }
 
    cancle = () => {
        this.props.history.push("/entry/applyFor");
    }
    handlePreview = (file) => {
        this.setState({
            previewImage: file.url || file.thumbUrl,
            previewVisible: true,
        });
    }
 
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
 
    handleCancelModel = (e) => {
        this.setState({
            visible: false,
        });
    }
 
    handleOk = e => {
        const { savedate } = this.state;
        console.log(savedate);
 
        this.setState({
            loading: true
        });
        Fetch.socialUpdate(savedate.id)
            .then(res => {
                if (res.code === 0) {
                    message.success("结束任务成功!");
                    this.setState({ loading: false })
                    this.props.history.push("/entry/applyFor")
                } else {
                    this.setState({ loading: false })
                    message.error('保存失败,请联系管理员', 2)
                }
            });
    };
 
    getNum = (e) => {
        console.log(e.target.value)
        this.setState({
            num: e.target.value
        })
    }
    getPerson = () => {
        const { num } = this.state;
        const { id } = this.state.savedate;
        if (!num) {
            message.error("请输入摇号数量")
            return;
        }
        if (isNaN(num)) {
            message.error("请输入数字")
            return;
        }
        Fetch.getActPerson(id, num)
            .then(res => {
                this.setState({
                    hitList: res.data
                })
            });
    }
 
 
    publishResult = () => {
        const { hitList, savedate } = this.state;
        Fetch.publishResult(hitList, savedate.id)
            .then(res => {
                if (res.code === 0) {
                    message.success("发布成功!");
                    this.setState({
                        visible: false,
                    }, this.getDetail);
                } else {
                    message.error('发布失败,请联系管理员', 2)
                }
            });
    }
 
    confirm = (e) => {
        console.log(e);
        const data = { id: e, status: 2 };
        this.setState({ loading: true })
        Fetch.auditPerson(data).then(res => {
            if (res.code == 0) {
                console.log(res)
                this.setState({ loading: false })
                message.success('审核通过');
                this.getDetail();
            } else {
                this.setState({ loading: false })
                message.error('请求失败,请联系管理员', 2)
            }
        }
        )
    }
 
    cancel = (e) => {
        console.log(e);
        const data = { id: e, status: 4 };
        this.setState({ loading: true })
        Fetch.auditPerson(data).then(res => {
            if (res.code == 0) {
                console.log(res)
                this.setState({ loading: false })
                message.error('审核不通过');
                this.getDetail();
            } else {
                this.setState({ loading: false })
                message.error('请求失败,请联系管理员', 2)
            }
        }
        )
    }
 
    handleCancel = () => this.setState({ previewVisible: false })
    render() {
        const { savedate, previewVisible, fileList, dateSource, hitList, taskType, disabled, loading } = this.state;
        console.log('list', fileList)
        const props = {
            action: domain + `api/v1/attachment/materials?associateTypeId=1019&entityId=` + savedate.id,
            onChange: ({ file, fileList }) => {
                if (file.status !== 'uploading') {
                    console.log(file);
                    console.log(fileList);
 
                }
                this.setState({ fileList });
            },
            fileList: fileList,
            onDownload: (file) => {
                Fetch.attachmentDownload(file.id)
                    .then(res => {
                        message.success("下载成功!");
                    });
            },
            onRemove: (file) => {
                Fetch.deleteAttachment(file.uid)
                    .then(res => {
                        message.success("移除成功!");
                    });
                this.setState(({ fileList }) => {
                    const index = fileList.indexOf(file);
                    const newFileList = fileList.slice();
                    newFileList.splice(index, 1);
                    return {
                        fileList: newFileList,
                    };
                });
            }
        };
 
 
        return (
            <div className="app-page">
                <Spin spinning={loading}>
                    <HeadView history={this.props.history} />
                    <Breadcrumb style={{ padding: '20px' }}>
                        <Breadcrumb.Item><a href="index.html#/entry/applyFor">入职查询</a></Breadcrumb.Item>
                        <Breadcrumb.Item>入职申请</Breadcrumb.Item>
                    </Breadcrumb>
                    <BusDetailView type='入职申请' >
                        <div style={divStyle}>
                            <Row type="flex" align='middle' justify="space-around">
                                <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>申请理由</span></Col>
                                <Col span={18} push={0} >
                                    <TextArea disabled={disabled} rows={4} placeholder="请输入申请理由" style={{ width: '92%' }} value={savedate.reason || ""} onChange={this.saveInputChange} name='reason' /></Col>
                            </Row>
                        </div>
                        <div style={divStyle}>
                            <Row type="flex" align='middle' justify="space-around">
                                <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>申请附件</span></Col>
                                <Col span={18} push={0} >
                                    <Upload {...props}>
                                        <Button>
                                            <Icon type="upload" /> 上传附件
                                        </Button>
                                    </Upload>
                                </Col>
                            </Row>
                        </div>
                        {
 
                            savedate ?
                                <div style={{ display: 'flex', justifyContent: 'center' }}>
                                    <Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.cancle}>返回</Button>
                                </div>
                                :
                                <div style={{ display: 'flex', justifyContent: 'center' }}>
                                    <Button style={{ marginRight: '15px', width: '150px' }} type="primary" onClick={this.submit}>提交</Button>
                                    <Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.cancle}>返回</Button>
                                </div>
                        }
 
                    </BusDetailView>
 
                    <Modal
                        title="结束任务"
                        visible={this.state.visible}
                        onOk={this.handleOk}
                        onCancel={this.handleCancelModel}
                        width='300px'
                    >
                        <p>确认结束任务吗?</p>
                    </Modal>
                </Spin>
            </div>
        );
    }
 
}