import React,{Component} from 'react';
import {Form, Input, Modal, Spin, Radio, Button, Icon, Upload, message, Checkbox} from "antd";
import TextArea from "antd/es/input/TextArea";
import {
splitUrl,
beforeUploadFile,
} from "@/tools.js";
import $ from "jquery/src/ajax";
import {companyList, getCompanyValueArray} from "../../../../common/configure";
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
// 上传文件
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: "",
fileList: this.props.pictureUrl
};
},
getDefaultProps() {
return {
changeClick: this.modifyChange
};
},
handleCancel() {
this.setState({ previewVisible: false });
},
handlePreview(file) {
this.setState({
previewImage: file.url || file.thumbUrl,
previewVisible: true
});
},
handleChange(info) {
let fileList = info.fileList;
this.setState({ fileList });
this.props.fileList(fileList);
},
componentWillReceiveProps(nextProps) {
this.state.fileList = nextProps.pictureUrl;
},
render() {
const { previewVisible, previewImage, fileList } = this.state;
// 点击上传
const uploadButton = (
);
return (
//上传组件
{fileList && fileList.length >= 1 ? null : uploadButton}
{
this.setState({ previewVisible: false });
}}
>
);
}
});
class ActivityOperation extends Component{
constructor(props) {
super(props);
this.state={
loading: false,
pictureUrl: [],
details: {},
locations: [],
}
this.submit = this.submit.bind(this);
this.getOrgCodeUrl = this.getOrgCodeUrl.bind(this);
}
submit(e){
e.preventDefault();
let _this = this;
this.props.form.validateFields((err, values) => {
if(values.title.length > 6){
message.warning('标题最多六个字');
return;
}
if(this.state.locations.length === 0){
message.warning('请选择城市');
return;
}
if (!err) {
this.setState({
loading: true
})
values.pictureUrl = values.pictureUrl ? values.pictureUrl[0].response.data : undefined;
let url = this.props.id ? "/api/admin/activity/update" : "/api/admin/activity/add";
if(this.props.id){
values.id = this.props.id;
}
values.locations = this.state.locations.join(',')
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + url,
data: values,
success: function(data) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
} else {
message.success('添加成功')
_this.props.onCancel();
}
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
}
});
}
getOrgCodeUrl(e) {
this.setState({ pictureUrl: e });
this.props.form.setFieldsValue({
pictureUrl: e
})
}
getSelect(){
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/activity/select",
data: {
id:this.props.id,
},
success: function(data) {
if (data.error.length) {
message.warning(data.error[0].message);
} else {
this.props.form.setFieldsValue({
title:data.data.title,
publisher:data.data.publisher,
sort:data.data.sort,
releaseStatus:data.data.releaseStatus,
content:data.data.content,
pictureUrl:data.data.pictureUrl
? splitUrl(
data.data.pictureUrl,
",",
globalConfig.avatarUploadHost
)
: []
});
this.setState({
locations:data.data.locations,
checked:data.data.locations.length === companyList.length,
indeterminate: data.data.locations.length < companyList.length,
pictureUrl:data.data.pictureUrl
? splitUrl(
data.data.pictureUrl,
",",
globalConfig.avatarUploadHost
)
: []
})
}
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
}
componentDidMount() {
if(this.props.id){
this.getSelect();
}
}
render() {
const { getFieldDecorator } = this.props.form;
return (
);
}
}
const ActivityOperationForm = Form.create()(ActivityOperation);
export default ActivityOperationForm;