import React from 'react'; import $ from 'jquery/src/ajax'; import { Icon, Modal, message, Spin, Upload, Input, Button, Radio, Form, Checkbox, Cascader, Row, Select, Col } from 'antd'; import { splitUrl} from '@/tools.js'; import {provinceSelect } from '@/NewDicProvinceList'; import Editors from '@/richTextEditors'; const PicturesWall = React.createClass({ getInitialState() { return { previewVisible: false, previewImage: '', fileList: [], tags: [] }; }, 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.length >= 2 ? null : uploadButton} example
); } }); 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/news/detail' , data: { id: id }, success: function (data) { let thisData = data.data,provice=[]; if (!thisData) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; thisData = {}; }; let publishPagesArr = []; let pageList = thisData.newsPublishs pageList.map(item=>{ publishPagesArr.push(item.publishPage) }); let pageK = publishPagesArr.length?publishPagesArr:['web_index','app_policy_index'] provice.push(thisData.provinceId); this.setState({ id:thisData.id, data: thisData, Province:provice, publishPages:pageK, auditStatus:thisData.auditStatus, edit:thisData.content, pictureUrl: thisData.titleImg ? splitUrl(thisData.titleImg, ',', globalConfig.avatarHost + '/upload') : [] }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getPictureUrl(e) { this.setState({ pictureUrl: e }); }, handleSubmit(e,index) { e.preventDefault(); this.props.form.validateFields((err, values) => { if((this.state.edit)==undefined||!this.state.edit||(this.state.edit)=='


'){ message.warning('请填写政策正文'); return false; } //url转化 let thePictureUrl = []; if (this.state.pictureUrl.length) { let picArr = []; this.state.pictureUrl.map(function (item) { if ( item.response && item.response.data && item.response.data.length ){ picArr.push(item.response.data); } }); thePictureUrl = picArr.join(","); }; if (!err) { // let publishPages =(values.publishPages).join(',') this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", async:true, url: this.props.data.id ? globalConfig.context + '/api/admin/news/updateNews' : globalConfig.context + '/api/admin/news/apply', data: { id: this.props.data.id, type:values.type, title: values.title, author: values.author, titleImg: thePictureUrl.length?thePictureUrl:'', content:this.state.edit, hot:values.hot, source:values.source, sourceUrl:values.sourceUrl, keyword:values.keyword, auditStatus:index, summary: values.summary, provinceId: (values.ProvinceCity)[0], // publishPages:publishPages } }).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.edit='


'; this.state.pictureUrl = []; this.state.Province=undefined; this.setState({ publishPages:['web_index','app_policy_index'] }) }; }, 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.Province=undefined; this.state.edit='


'; this.state.pictureUrl = []; this.state.theData={}; this.setState({ publishPages:['web_index','app_policy_index'] }) }; 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 }, }; const formItemLayouts = { labelCol: { span: 3 }, wrapperCol: { span: 18 }, }; return (
{this.handleSubmit(e,0)}} id="demand-form">
{getFieldDecorator('title', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.title })()} {getFieldDecorator('type', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.type!=undefined?String(theData.type):theData.type })( )}
{getFieldDecorator('hot', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.hot })( )} {getFieldDecorator('source', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.source })()} {getFieldDecorator('sourceUrl', { initialValue: theData.sourceUrl })()} {getFieldDecorator('ProvinceCity', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: this.state.Province })( )}
{getFieldDecorator('keyword', { initialValue: theData.keyword })()}
{getFieldDecorator('summary', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.summary })()}
* 新闻正文}> { this.state.edit = value; }} visible={this.state.visible} />
{theData.releaseStatus?'已发布':'未发布'}
{/*
{getFieldDecorator('publishPages', { rules: [ { required: false } ], initialValue: this.state.publishPages })( 网站新闻首页 网站申请首页 app新闻首页 APP科技服务首页 )}
*/}
) } })); export default NewDetailForm;