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 { getTechField } from '@/DicTechFieldList.js';
import {areaSelect } from '@/NewDicProvinceList';
import { IndustryObject, getIndustryCategory } from '@/DicIndustryList.js';
import { splitUrl, companySearch, getDemandType, getAchievementCategory } from '@/tools.js';
const FormItem =Form.Item
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: '',
fileList: []
};
},
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: [],
};
},
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 ProvinceCityArr = [];
// let ProvinceS = thisData.locationProvince; //getprovince
// let citys = thisData.locationCity;
// let Areas = thisData.locationArea;
// ProvinceCityArr.push(ProvinceS, citys, Areas);
this.setState({
//ProvinceCity:ProvinceCityArr,
id:thisData.id,
data: thisData,
isHot:thisData.isHot,
isUrgent:thisData.isUrgent,
status:thisData.status,
isHot:thisData.isHot,
pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', 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) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
console.log(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(",");
};
if (!err) {
this.setState({
loading: true
});
$.ajax({
method: "post",
dataType: "json",
// crossDomain: false,
url: this.props.data.id ? globalConfig.context + '/api/user/demand/update' : 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,
crowdCost:values.crowdCost,
budgetCost:values.budgetCost,
urgentDays:values.urgentDays?values.urgentDays.format('YYYY-MM-DD'):undefined,
urgentMoney:values.urgentMoney,
auditStatus:values.auditStatus,
status: this.state.status,
isUrgent: this.state.isUrgent,
isHot:this.state.isHot,
publishPages:JSON.stringify(values.publishPages),
researchType:values.researchType
}
}).done(function (data) {
this.setState({
loading: false
});
if (!data.error.length) {
message.success('保存成功!');
this.setState({
visible: false
});
this.props.handleOk();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
}
});
},
submission(record){
this.handleSubmit();
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/user/demand/deletet",
data: {
ids: deletedIds
}
}).done(function (data) {
if (!data.error.length) {
message.success('成功提交审核.');
this.setState({
loading: false,
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
cancelFun(){
this.props.closeDesc();
},
componentWillMount() {
if (this.props.data.id) {
this.loadData(this.props.data.id);
} else {
this.state.data = {};
};
},
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.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 (
)
}
}));
export default DemandDetailForm;