/**
|
* 徐祥健<xuxj@hugeinfo.com.cn>
|
* 2018年8月29日 16:19
|
*
|
*/
|
import React from 'react';
|
|
import { Row, Col, Input, DatePicker, Button, Modal, Upload, Icon, message, Divider, TimePicker, Badge } 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 yearFormat = 'YYYY-MM-DD';
|
const divStyle = {
|
margin: '20px'
|
}
|
const domain = Fetch.domain;
|
export default class ActiveManageEdit extends React.Component {
|
constructor(props) {
|
super(props);
|
this.state = {
|
dateSource: [],
|
savedate: {},
|
formdata: {},
|
fileList: [],
|
previewVisible: false,
|
previewImage: '',
|
visible: false,
|
hitList: [],
|
num: 0
|
};
|
}
|
|
componentDidMount() {
|
document.title = '活动发布';
|
this.getDetail();
|
}
|
|
getDetail = () => {
|
const { id } = this.props.match.params;
|
Fetch.getActiveDetail(id)
|
.then(res => {
|
let { startTime, endTime } = res.activity;
|
if (startTime == null) {
|
startTime = Date.now();
|
}
|
if (endTime == null) {
|
endTime = Date.now();
|
}
|
this.setState({
|
savedate: {
|
...res.activity,
|
startDate: moment(startTime).format(yearFormat),
|
startHour: moment(startTime).format(format),
|
endDate: moment(endTime).format(yearFormat),
|
endHour: moment(endTime).format(format)
|
},
|
dateSource: res.personList || [],
|
fileList: res.attachments || []
|
});
|
})
|
}
|
|
saveInputChange = ({ target: { value, name } }) => {
|
this.setState(({ savedate }) => ({
|
savedate: {
|
...savedate,
|
[name]: value
|
}
|
}))
|
}
|
|
submit = () => {
|
const { savedate } = this.state;
|
savedate.startTime = moment(savedate.startDate + " " + moment(savedate.startHour).format(format), 'YYYY-MM-DD HH:mm')
|
savedate.endTime = moment(savedate.endDate + " " + moment(savedate.endHour).format(format), 'YYYY-MM-DD HH:mm')
|
console.log(savedate);
|
if(!savedate.activityPersonQuota){
|
message.warning("活动人数不能为空");
|
return;
|
}
|
if (savedate.activityPhone) {
|
if (!validator.phone(savedate.activityPhone)) {
|
return message.warning("联系电话格式不正确");
|
}
|
}
|
Fetch.saveActive(savedate)
|
.then(res => {
|
if (res.code === 0) {
|
message.success("提交成功!");
|
this.props.history.push("/activeManage")
|
} else {
|
message.error('保存失败,请联系管理员', 2)
|
}
|
});
|
}
|
|
cancle = () => {
|
this.props.history.push("/activeManage");
|
}
|
handlePreview = (file) => {
|
this.setState({
|
previewImage: file.url || file.thumbUrl,
|
previewVisible: true,
|
});
|
}
|
|
showModal = () => {
|
this.setState({
|
visible: true,
|
});
|
}
|
|
handleCancelModel = (e) => {
|
this.setState({
|
visible: false,
|
});
|
}
|
|
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)
|
}
|
});
|
}
|
|
handleCancel = () => this.setState({ previewVisible: false })
|
render() {
|
const { savedate, previewVisible, previewImage, fileList, dateSource, hitList } = this.state;
|
const props = {
|
action: domain + 'api/v1/attachment/materials?entityId=' + savedate.id,
|
onChange: ({ file, fileList }) => {
|
this.setState({ fileList });
|
},
|
fileList: fileList,
|
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,
|
};
|
});
|
}
|
};
|
const columns = [{
|
title: '姓名',
|
dataIndex: 'proposerName',
|
key: 'proposerName'
|
}, {
|
title: '联系电话',
|
dataIndex: 'proposerPhone',
|
key: 'proposerPhone',
|
}, {
|
title: '是否中奖',
|
dataIndex: 'isHit',
|
key: 'isHit',
|
render: text => ((
|
savedate.activityStatus < 3 ?
|
<span>未开奖</span> :
|
(
|
text == 0 ? <span>未中奖</span> : <Badge count={'中奖'} style={{ backgroundColor: '#52c41a' }} />
|
)
|
)
|
)
|
}];
|
return (
|
<div className="app-page">
|
<HeadView history={this.props.history} />
|
<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={6} push={0} ><Input placeholder="请输入活动标题" style={{ width: '300px' }} name='activityTitle' onChange={this.saveInputChange} value={savedate.activityTitle || ""} /></Col>
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>主办方电话</span></Col>
|
<Col span={6} push={0} ><Input placeholder="请输入活动主办方联系电话" style={{ width: '300px' }} name='activityPhone' onChange={this.saveInputChange} value={savedate.activityPhone || ""} /></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={6} push={0} >
|
<DatePicker style={{ width: '165px' }} onChange={(_, value) => this.saveInputChange({ target: { name: 'startDate', value } })} value={moment(savedate.startDate, yearFormat)} format={yearFormat} />
|
<TimePicker minuteStep={30} onChange={(value) => this.saveInputChange({ target: { name: 'startHour', value } })} value={moment(savedate.startHour, format)} format={format} /></Col>
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>结束时间</span></Col>
|
<Col span={6} push={0} >
|
<DatePicker style={{ width: '165px' }} onChange={(_, value) => this.saveInputChange({ target: { name: 'endDate', value } })} value={moment(savedate.endDate, yearFormat)} format={yearFormat} />
|
<TimePicker minuteStep={30} onChange={(value) => this.saveInputChange({ target: { name: 'endHour', value } })} value={moment(savedate.endHour, format)} format={format} /></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={6} push={0} ><Input placeholder="请输入详细地址" style={{ width: '300px' }} name='activityAddress' onChange={this.saveInputChange} value={savedate.activityAddress || ""} /></Col>
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>活动人数</span></Col>
|
<Col span={6} push={0} >
|
<Input style={{ width: '300px' }} name='activityPersonQuota' onChange={this.saveInputChange} value={savedate.activityPersonQuota || ""} />
|
</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} ><TextArea rows={4} placeholder="请输入活动描述" style={{ width: '92%' }} value={savedate.activityDesc || ""} onChange={this.saveInputChange} name='activityDesc' /></Col>
|
</Row>
|
</div>
|
|
<div style={divStyle}>
|
<Row type="flex" align='top' justify="space-around">
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>添加图片</span></Col>
|
<Col span={18} push={0} >
|
<Upload listType="picture-card" onPreview={this.handlePreview} {...props}>
|
<div>
|
<Icon type="plus" />
|
<div className="ant-upload-text">上传图片</div>
|
</div>
|
</Upload>
|
<Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
|
<img alt="example" style={{ width: '100%' }} src={previewImage} />
|
</Modal>
|
</Col>
|
</Row>
|
</div>
|
|
{
|
dateSource.length > 0 ?
|
<div style={divStyle}>
|
<Divider orientation="left" style={{ margin: '20px', width: '97%' }}>报名人员信息</Divider>
|
<TableView columns={columns} data={dateSource} pageSize='6' size='small' />
|
</div>
|
: null
|
|
}
|
{
|
savedate.activityStatus == null || savedate.activityStatus == 0 ?
|
< 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>
|
: (
|
savedate.activityStatus == 3 ?
|
< div style={{ display: 'flex', justifyContent: 'center' }}>
|
<Button style={{ marginRight: '15px', width: '150px' }} type="primary" onClick={this.showModal}>活动摇号</Button>
|
<Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.cancle}>返回</Button>
|
</div>
|
:
|
< div style={{ display: 'flex', justifyContent: 'center' }}>
|
<Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.cancle}>返回</Button>
|
</div>
|
)
|
}
|
|
</BusDetailView>
|
|
<Modal
|
title="活动摇号"
|
visible={this.state.visible}
|
onCancel={this.handleCancelModel}
|
footer={null}
|
width='1000px'
|
>
|
<div style={divStyle}>
|
<Row type="flex" align='middle' justify="space-around">
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>活动报名人数</span></Col>
|
<Col span={6} push={0} ><Input placeholder="请输入活动标题" style={{ width: '200px' }} name='activityTitle' value={savedate.activityPersonQuota} disabled /></Col>
|
<Col span={6} pull={0} style={{ textAlign: 'center' }}><span>摇号名额</span></Col>
|
<Col span={6} push={0} ><Input placeholder="请输入摇号名额" style={{ width: '200px' }} onChange={this.getNum} /></Col>
|
</Row>
|
</div>
|
|
<div style={{ display: 'flex', marginBottom: '20px', justifyContent: 'space-around' }}>
|
{
|
hitList.map((data) => (
|
<ImageBoxView url={data.headimgurl} userName={data.userName} />
|
))
|
}
|
</div>
|
|
|
{
|
hitList.length > 0 ?
|
< div style={{ display: 'flex', justifyContent: 'center' }}>
|
<Button style={{ marginRight: '15px', width: '150px' }} type="primary" onClick={this.publishResult}>发布结果</Button>
|
<Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.getPerson}>重新摇号</Button>
|
</div>
|
:
|
< div style={{ display: 'flex', justifyContent: 'center' }}>
|
<Button style={{ marginRight: '15px', width: '150px' }} type="primary" onClick={this.getPerson}>活动摇号</Button>
|
<Button style={{ marginLeft: '15px', width: '150px' }} onClick={this.handleCancelModel}>返回</Button>
|
</div>
|
}
|
|
</Modal>
|
|
</div>
|
);
|
}
|
|
}
|