import React from 'react'; import $ from 'jquery/src/ajax'; import { Icon, Modal, message, Spin, Upload, Input, Button, Form, Select } from 'antd'; import { videoType } from '@/dataDic.js'; import { getVideoType} from '@/tools.js'; import VideoComponent from '@/crop/video'; import Crop from '@/crop/cropBlock'; const NewDetailForm = Form.create()(React.createClass({ getInitialState() { return { visible: false, loading: false, auditStatus: 0, textFileList: [], videoImg: [], vedioUrl:[] }; }, loadData(id) { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/policy/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 proArr=[]; this.setState({ id:thisData.id, data: thisData, auditStatus:thisData.auditStatus, videoUrl:[], videoImg: 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) => { //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) { this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", async:true, url: this.props.data.id ? globalConfig.context + '/api/admin/policy/update' : globalConfig.context + '/api/admin/policy/apply', data: { id: this.props.data.id, type:0, title: values.title, author: values.author, titleImg: thePictureUrl.length?thePictureUrl:'', content:this.state.edit.content, hot:values.hot, source:values.source, sourceUrl:values.sourceUrl, keyword:values.keyword, auditStatus:index, 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.state.edit={}; this.props.closeDesc(); }, componentWillMount() { if (this.props.data.id) { this.loadData(this.props.data.id); } else { this.state.data = {}; this.state.videoImg = []; this.state.videoUrl=[]; }; }, componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { if (nextProps.data.id) { this.loadData(nextProps.data.id); } else { this.state.data = {}; this.state.videoImg = []; this.state.theData={}; this.state.videoUrl=[]; }; 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 (