import React,{Component} from 'react'; import SpinContainer from "../../../SpinContainer"; import {Button, Form, Icon, Input, message, Modal, Select, Upload} from "antd"; import {beforeUploadFile,splitUrl} from "@/tools.js"; import Editors from "@/richTextEditors"; import $ from "jquery/src/ajax"; const FormItem = Form.Item; //上传图片组件 const PicturesWall = React.createClass({ getInitialState() { return { previewVisible: false, previewImage: "", fileList: this.props.pictureUrl, type:'' }; }, getDefaultProps() { return { changeClick: this.modifyChange }; }, handleCancel() { this.setState({ previewVisible: false }); }, handlePreview(file) { let type = ''; if(file.type){ let str = file.type; let index = str.indexOf("/"); type =str.substring(0,index); }else{ let str = file.url || file.thumbUrl; let index = str.indexOf("."); type =str.substring(index+1); } this.setState({ type, 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.state.type=== 'image' ? : this.state.type=== 'video' ? : this.state.type=== 'audio' ? : '' }
); } }); class Add extends Component{ constructor(props) { super(props); this.state={ loading: false, projectType: '', sort:'', name:'', pictureVideoUrl: '', pictureImgUrl: '', content: '', amount: '', projectList: [], host: 0, } this.getOrgCodeUrl = this.getOrgCodeUrl.bind(this); this.getVideoOrgCodeUrl = this.getVideoOrgCodeUrl.bind(this); this.onOk = this.onOk.bind(this); this.getProjectList = this.getProjectList.bind(this); } componentDidMount() { this.getProjectList(); } getOrgCodeUrl(e) { this.setState({ pictureImgUrl: e }); } getVideoOrgCodeUrl(e) { this.setState({ pictureVideoUrl: e }); } onOk(releaseStatus = 0){ if(!this.state.name){ message.warning('请输入产品名称'); return false; } if(isNaN(parseInt(this.state.projectType))){ message.warning('请输入产品分类'); return false; } if(isNaN(parseInt(this.state.amount))){ message.warning('请输入正确的金额'); return false; } if(this.state.pictureVideoUrl.length === 0){ message.warning('请上传视频/音频'); return false; } if(this.state.pictureImgUrl.length === 0){ message.warning('请上传略缩图'); return false; } if(!this.state.content){ message.warning('请输入简介'); return false; } this.setState({ loading: true }); let url = this.props.id ? "/api/admin/project/update" : "/api/admin/project/add" $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + url, data: { name: this.state.name || undefined, sort:this.state.sort || undefined, content: this.state.content || undefined, id: this.props.id || undefined, type: this.state.projectType, amount: this.state.amount || undefined, commodityUrl: this.state.pictureVideoUrl[0].response.data || undefined, thumbnailUrl: this.state.pictureImgUrl[0].response.data || undefined, host: this.state.host, releaseStatus, }, success: function(data) { if (data.error && data.error.length) { message.warning(data.error[0].message); } else { message.success(this.state.id ? '修改成功' : '添加成功'); this.props.onOk(); } }.bind(this) }).always( function() { this.setState({ loading: false }); }.bind(this) ); } getProjectList() { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/open/projectList", data: {} }).done((data1) => { if (data1.error.length !== 0) { message.warning(data1.error[0].message); } else { this.setState({ projectList: data1.data, },()=>{ if(this.props.infor){ this.setState({ name: this.props.infor.name, sort:this.props.infor.sort, content: this.props.infor.content, projectType: this.props.infor.type, amount: this.props.infor.amount, pictureVideoUrl: this.props.infor.commodityUrl ? splitUrl(this.props.infor.commodityUrl, ',', globalConfig.avatarHost + '/upload') : [], pictureImgUrl: this.props.infor.thumbnailUrl ? splitUrl(this.props.infor.thumbnailUrl, ',', globalConfig.avatarHost + '/upload') : [], host: this.props.infor.host, }) } }); } }).always(function () { this.setState({ loading: false }); }.bind(this)) } render() { return (
{ this.setState({ name: e.target.value }); }} /> { this.setState({ amount: e.target.value }); }} /> { this.setState({ sort: e.target.value }); }} />

数字越大,排序越前

支持MP3/MP4/RMVB/MKV/AVI

{ this.setState({ content: value }); }} />
) } } export default Add;