import React from 'react';
import $ from 'jquery/src/ajax';
import {
message,
Spin,
Input,
Button,
Radio,
Form,
Select,
} from 'antd';
import {productType} from '@/dataDic.js';
import {getProStatus} from '@/tools.js'
import Editors from '@/richTextEditors';
import Crop from '@/crop/cropBlock';
import KeyWordTagGroup from '@/crop/keyword';
const NewDetailForm = Form.create()(React.createClass({
getInitialState() {
return {
visible: false,
loading: false,
auditStatus: 0,
textFileList: [],
videoFileList: [],
pictureUrl: [],
tags:[],
edit:{},
edits:{}
};
},
loadData(id) {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/community/getCommunintyById' ,
data: {
id: id
},
success: function (data) {
let thisData = data.data;
if (!thisData) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thisData = {};
};
this.setState({
id:thisData.id,
data: thisData,
tags:(thisData.keyword).split(',')||[],
status:thisData.status,
edit:thisData.content,
pictureUrl: thisData.picUrl ? thisData.picUrl.split(',') : []
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
handleSubmit(e,index) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
// if (!this.state.pictureUrl.length) {
// message.warning('请上传专栏图片!');
// return false;
// };
if((this.state.edit)==undefined||!this.state.edit||(this.state.edit)=='
'){
message.warning('请填写专栏正文');
return false;
}
if (!err) {
this.setState({
loading: true
});
$.ajax({
method: "post",
dataType: "json",
async:true,
url: this.props.data.id ? globalConfig.context + '/api/admin/community/updateCommunity' : globalConfig.context + '/api/admin/community/insertCommunity',
data: {
id: this.props.data.id,
title: values.title,
picUrl: this.state.pictureUrl.join(','),
content:this.state.edit,
category:values.category,
recommend:values.recommend,
top:values.top,
status:index,
keyword: this.state.tags ? this.state.tags.join(",") : '',
summary: values.summary,
}
}).done(function (data) {
this.setState({
loading: false
});
if (!data.error.length) {
message.success('操作成功!');
this.setState({
visible: false
});
this.props.handOk();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
}
});
},
cancelFun(){
this.props.closeDesc();
},
componentWillMount() {
if (this.props.data.id) {
this.loadData(this.props.data.id);
} else {
this.state.visible=true;
this.state.data = {};
this.state.tags=[];
this.state.edit='
';
this.state.pictureUrl = [];
};
},
componentWillReceiveProps(nextProps) {
if (!this.props.visible && nextProps.visible) {
this.state.textFileList = [];
this.state.videoFileList = [];
if (nextProps.data.id) {
this.loadData(nextProps.data.id);
} else {
this.state.visible=true;
this.state.data = {};
this.state.tags=[];
this.state.edit='
';
this.state.pictureUrl = [];
this.state.theData={};
};
this.props.form.resetFields();
};
},
render() {
const theData = this.state.data || {};
const { getFieldDecorator } = this.props.form;
const FormItem = Form.Item
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 12 },
};
return (
)
}
}));
export default NewDetailForm;