import React from 'react'; import $ from 'jquery/src/ajax'; import { Icon, Tooltip, Modal, message, Spin, Upload, Input, Select, Button, Radio, Form, Cascader, Tag, Checkbox, Row, Col } from 'antd'; import {industry} from '@/industryList'; import {achievementType,achievementCategoryList,maturityList,innovationList,transaction} from '@/dataDic'; import { splitUrl} from '@/tools.js'; import SpinContainer from "../../SpinContainer"; 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: [], pictureUrl: [], pictureUrlMin:[], tags:[] }; }, loadData(id) { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/user/achievement/achievementDetail' , 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 = {}; }; this.setState({ id:thisData.id, tags: thisData.keywords, data: thisData, publishPages:thisData.publishPages.length?thisData.publishPages:['app_achievement_list','web_achievement_list'], auditStatus:thisData.auditStatus, pictureUrl: thisData.technicalPictureUrl ? splitUrl(thisData.technicalPictureUrl, ',', 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/achievement/update' : globalConfig.context + '/api/user/achievement/apply', data: { id: this.props.data.id, name: values.name, fieldA: values.industryCategory ? values.industryCategory[0] : undefined, fieldB: values.industryCategory ? values.industryCategory[1] : undefined, dataCategory: values.dataCategory, category: values.category, technicalPictureUrl: thePictureUrl.length?thePictureUrl:'', pictureUrlMin: thepictureUrlMin.length?thepictureUrlMin:'', introduction:values.introduction, keyword: this.state.tags ? this.state.tags.join(",") : [], keywords: this.state.tags, maturity:values.maturity, innovation:values.innovation, transferMode:values.transferMode, auditStatus:index, patentCase: values.patentCase, teamDes: values.teamDes, parameter: values.parameter, boutique: values.boutique, isHot:values.isHot, publishPages:values.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)); } }); }, submission(e,index){ this.handleSubmit(e,index); $.ajax({ method: "POST", dataType: "json", crossDomain: false, async:true, url: globalConfig.context + "/api/user/achievement/commit", data: { id: this.state.id, } }).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.setState({ publishPages:['app_achievement_list','web_achievement_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.pictureUrl = []; this.state.pictureUrlMin=[]; this.state.tags = []; this.setState({ publishPages:['app_achievement_list','web_achievement_list'] }) }; 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 }, }; return (
{this.handleSubmit(e,0)}} id="demand-form">
{getFieldDecorator('name', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.name })()}
{getFieldDecorator('introduction', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue: theData.introduction })()} {getFieldDecorator('patentCase', { initialValue: theData.patentCase })()} {getFieldDecorator('parameter', { initialValue: theData.parameter })()} {getFieldDecorator('teamDes', { initialValue: theData.teamDes })()}
* 关键词} > {this.setState({tags:e})}} />
{getFieldDecorator('industryCategory', { rules: [ { type: 'array', required: true, message: '此项为必填项!' } ], initialValue: [ theData.fieldA, theData.fieldB ] })()}
{getFieldDecorator('dataCategory', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue:(theData.dataCategory||theData.dataCategory=='0'?theData.dataCategory.toString():undefined) })( )} {getFieldDecorator('category', { rules: [ { required: true, message: '此项为必填项!' } ], initialValue:(theData.category||theData.category=='0'?theData.category.toString():undefined) })( )} {getFieldDecorator('innovation', { initialValue:(theData.innovation||theData.innovation=='0'?theData.innovation.toString():undefined) })( )} {getFieldDecorator('maturity', { initialValue:(theData.maturity||theData.maturity=='0'?theData.maturity.toString():undefined) })( )} {getFieldDecorator('transferMode', { initialValue:(theData.transferMode||theData.transferMode=='0'?theData.transferMode.toString():undefined) })( )}
{this.setState({pictureUrlMin:e})}} pictureUrl={this.state.pictureUrlMin} visible={this.props.visible} />
{getFieldDecorator('boutique', { initialValue: theData.boutique })( 非精品 精品 ) } {getFieldDecorator('isHot', { initialValue: theData.isHot })( 非热点 热点 ) }
{getFieldDecorator('publishPages', { rules: [ { required: false } ], initialValue: this.state.publishPages })( 网站首页 网站成果主页 网站成果搜索页 APP首页 APP成果首页 APP成果搜索页 知识产权交易首页 app成果知识产权交易页面 )}
{theData.auditInfo&&
{theData.auditInfo}
}
) } })); export default DemandDetailForm;