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) === 'video' ? 1 : str.substring(0,index) === 'audio' ? 2 : 0; }else{ // let str = file.url || file.thumbUrl; // let index = str.lastIndexOf("."); // type = str.substring(index+1); type = this.props.type; } 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=== 0 ? : this.state.type=== 1 ? : this.state.type=== 2 ? : '' }
); } }); class Add extends Component{ constructor(props) { super(props); this.state={ loading: false, projectType: '', sort:'', summary:'', name:'', pictureVideoUrl: '', pictureImgUrl: '', content: '', commodityContent: '', amount: '', projectList: [], host: 0, commodityType: '', } 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) { if(e.length === 0){ this.setState({ pictureVideoUrl: '', commodityType: '', }); }else{ let str = e[0].type; let index = str.indexOf("/"); let type =str.substring(0,index); this.setState({ pictureVideoUrl: e, commodityType: type === 'video' ? 1 : type === 'audio' ? 2 : 0, }); } } 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.commodityContent){ 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, summary:this.state.summary || undefined, content: this.state.content || undefined, commodityContent: this.state.commodityContent || undefined, id: this.props.id || undefined, type: this.state.projectType, amount: !isNaN(parseInt(this.state.amount)) ? this.state.amount : undefined, commodityUrl: this.state.pictureVideoUrl ? this.state.pictureVideoUrl[0].response.data : '', commodityType: this.state.commodityType, 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/projectTypeList", 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, summary:this.props.infor.summary, content: this.props.infor.content, commodityContent: this.props.infor.commodityContent, 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, commodityType:this.props.infor.commodityType }) } }); } }).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 }); }} />

数字越大,排序越前

{ this.setState({ summary: e.target.value }); }} />

支持MP3/MP4/RMVB/MKV/AVI

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