import React from 'react'; import $ from 'jquery/src/ajax'; import { Icon, Tabs, Table, Tooltip, Modal, Popover, message, Spin, Upload, Input, InputNumber, Select, DatePicker, Button, Radio, Form, Cascader, Tag, Checkbox, Row, Col } from 'antd'; import { splitUrl } from '@/tools.js'; import {industry} from '@/industryList'; const KeyWordTagGroup = React.createClass({ getInitialState() { return { tags: [], inputVisible: false, inputValue: '' }; }, handleClose(removedTag) { const tags = this.state.tags.filter(tag => tag !== removedTag); this.props.tagsArr(tags); this.setState({ tags }); }, showInput() { this.setState({ inputVisible: true }, () => this.input.focus()); }, handleInputChange(e) { this.setState({ inputValue: e.target.value }); }, handleInputConfirm() { const state = this.state; const inputValue = state.inputValue; let tags = state.tags; if (inputValue && tags.indexOf(inputValue) === -1 && inputValue.replace(/(^\s*)|(\s*$)/g, "").length != 0) { tags = [...tags, inputValue.replace(/(^\s*)|(\s*$)/g, "")]; } this.props.tagsArr(tags); this.setState({ tags, inputVisible: false, inputValue: '', }); }, componentWillMount() { this.state.tags = this.props.keyWordArr; }, componentWillReceiveProps(nextProps) { if (this.props.keyWordArr != nextProps.keyWordArr) { this.state.tags = nextProps.keyWordArr; }; }, render() { const { tags, inputVisible, inputValue } = this.state; return (
{tags.map((tag, index) => { const isLongTag = tag.length > 10; const tagElem = ( this.handleClose(tag)}> {isLongTag ? `${tag.slice(0, 10)}...` : tag} ); return isLongTag ? {tagElem} : tagElem; })} {inputVisible && ( this.input = input} type="text" style={{ width: 78 }} value={inputValue} onChange={this.handleInputChange} onBlur={this.handleInputConfirm} onPressEnter={this.handleInputConfirm} /> )} {!inputVisible && }
); } }); 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 >= 5 ? null : uploadButton} example
); } }); const DemandDetailForm = Form.create()(React.createClass({ getInitialState() { return { visible: false, loading: false, auditStatus: 0, textFileList: [], videoFileList: [], pictureUrlMin:[], pictureUrl: [], tags:[] }; }, loadData(id) { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/user/demand/demandDetail' , 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 = {}; }; let publishPagesArr = []; thisData.publishPages.map(item=>{ publishPagesArr.push(item.publishPage) }) this.setState({ id:thisData.id, tags: thisData.keyword ? thisData.keyword.split(",") : [], data: thisData, auditStatus:thisData.auditStatus, publishPagesArr:publishPagesArr, isHot:thisData.isHot, isUrgent:thisData.isUrgent, status:thisData.status, isHot:thisData.isHot, pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : [], pictureUrlMin: thisData.pictureUrlMin ? splitUrl(thisData.pictureUrlMin, ',', globalConfig.avatarHost + '/upload') : [] }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getTagsArr(e) { this.setState({ tags: e }); }, 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(","); }; let thepictureUrlMin = []; if (this.state.pictureUrlMin.length) { let picArr = []; this.state.pictureUrlMin.map(function (item) { if ( item.response && item.response.data && item.response.data.length ){ picArr.push(item.response.data); } }); thepictureUrlMin = picArr.join(","); }; if(!this.state.tags.length){ 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/user/demand/updateDemand' : globalConfig.context + '/api/user/demand/apply', data: { id: this.props.data.id, name: values.name, industryCategoryA: values.industryCategory ? values.industryCategory[0] : undefined, industryCategoryB: values.industryCategory ? values.industryCategory[1] : undefined, demandType: values.demandType, problemDes: values.problemDes, pictureUrl: thePictureUrl.length?thePictureUrl:'', pictureUrlMin: thepictureUrlMin.length?thepictureUrlMin:'', crowdCost:values.crowdCost, keyword: this.state.tags ? this.state.tags.join(",") : [], keywords: this.state.tags, budgetCost:values.budgetCost?values.budgetCost:0, urgentDays:this.state.isUrgent?values.urgentDays:0, urgentMoney:this.state.isUrgent?values.urgentMoney?values.urgentMoney:0:0, auditStatus:index, status: this.state.status, isUrgent: this.state.isUrgent, isHot:this.state.isHot, publishPages:values.publishPages, researchType:values.researchType } }).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)); } }); }, submission(e,index){ this.handleSubmit(e,index); $.ajax({ method: "POST", dataType: "json", crossDomain: false, async:true, url: globalConfig.context + "/api/user/demand/publishDemand", data: { id: this.state.id, auditStatus:index } }).done(function (data) { if (!data.error.length) { this.setState({ loading: false, }); } 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.data = {}; this.state.tags = []; this.state.pictureUrl=[]; this.state.pictureUrlMin=[]; this.setState({ publishPagesArr:['app_demand_list','web_demand_list'] }) }; }, 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.data = {}; this.state.isUrgent=undefined;//加急需求 this.state.isHot=undefined;//是否悬赏 this.state.status=undefined; this.state.pictureUrl = []; this.state.pictureUrlMin=[]; this.state.tags = []; this.setState({ publishPagesArr:['app_demand_list','web_demand_list'] }) }; this.props.form.resetFields(); }; }, render() { const theData = this.state.data || {}; const { getFieldDecorator,getFieldsValue } = this.props.form; const FormItem = Form.Item const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 12 }, }; let demandType =(getFieldsValue(['demandType']).demandType); return (
{this.handleSubmit(e,0)}} id="demand-form">
{getFieldDecorator('problemDes', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.problemDes })()} {getFieldDecorator('name', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.name })()}
*关键词} > {this.setState({tags:e})}} />
{getFieldDecorator('industryCategory', { rules: [ { type: 'array', required: true, message: '此项为必填项!' } ], initialValue: [ theData.industryCategoryA, theData.industryCategoryB ] })()}
{getFieldDecorator('demandType', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue:(theData.demandType||theData.demandType=='0'?theData.demandType.toString():undefined) })( )} {demandType=='5'||theData.demandType=='5'? {getFieldDecorator('budgetCost', { rules: [ { required: false } ], initialValue: theData.budgetCost?theData.budgetCost:undefined })()} 万元 :''} {demandType=='3'||theData.demandType=='3'?
{getFieldDecorator('crowdCost', { rules: [ { required: false } ], initialValue: theData.crowdCost })()} 万元 {getFieldDecorator('researchType', { rules: [ { required: false } ], initialValue: theData.researchType||theData.researchType=='0'?theData.researchType.toString():undefined })( )}
:'' }

您还可以说明

{this.setState({isUrgent:e.target.value})}}> 非加急 加急 {this.state.isUrgent?
{getFieldDecorator('urgentDays', { initialValue: theData.urgentDays })()} {getFieldDecorator('urgentMoney', { initialValue: theData.urgentMoney?theData.urgentMoney:undefined })()} 万元
:''}
{this.setState({isHot:e.target.value})}}> {this.setState({status:e.target.value})}}> 进行中 未解决 已解决
{this.setState({pictureUrlMin:e})}} pictureUrl={this.state.pictureUrlMin} visible={this.props.visible} />
{getFieldDecorator('publishPages', { rules: [ { required: false } ], initialValue: this.state.publishPagesArr })( 网站首页 网站需求主页 网站需求搜索页 APP首页 APP需求首页 APP需求搜索页 知识产权交易首页 app需求交易页面 )}
{theData.auditInfo&&
{theData.auditInfo}
}
) } })); export default DemandDetailForm;