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}
);
}
});
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 (
)
}
}));
export default DemandDetailForm;