import React from 'react';
import $ from 'jquery/src/ajax';
import {
Icon,
Tooltip,
Modal,
message,
Spin,
Upload,
Input,
Select,
Button,
Radio,
Form,
Cascader,
Checkbox,
Tag,
Row,Col,
InputNumber
} from 'antd';
import { citySelect } from '@/NewDicProvinceListAll';
import { splitUrl ,getReleaseStateList} from '@/tools.js';
import Editors from '@/richTextEditors';
import './business.less';
//图片组件
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 >= 1 ? null : uploadButton}
);
}
});
const DemandDetailForm = Form.create()(
React.createClass({
getInitialState() {
return {
tagArr:[],
visible: false,
loading: false,
auditStatus: 0,
textFileList: [],
videoFileList: [],
pictureUrl: [],
orgCodeUrl: [],
companyLogoUrl: [],
tags: [],
introduce:{},
};
},
//左侧图片地址
getOrgCodeUrl(e) {
this.setState({ orgCodeUrl: e });
},
//右侧图片地址
getCompanyLogoUrl(e) {
this.setState({ companyLogoUrl: e });
},
//编辑部门,保存
handleSubmit(e,index) {
e.preventDefault();
if (!this.state.name) {
message.warning('请输入项目名称');
return;
}
if ((this.state.name).length>50) {
message.warning('项目名称在50个字以内');
return false;
};
if (!this.state.categoryId||!this.state.categoryId[1]) {
message.warning('请选择项目二级业务品类');
return;
}
if (!this.state.ProvinceCity.length) {
message.warning('请选择省份');
return;
}
if (!this.state.price) {
message.warning('请输入正确的市场价');
return;
}
if(this.state.summary&&(this.state.summary).length>40){
message.warning('项目简介字数不得超过40个字。');
return;
}
if(this.state.advertisement&&(this.state.advertisement).length>100){
message.warning('项目营销说明字数不得超过100个字。');
return;
}
if(this.state.introduce&&(this.state.introduce.length)>10000){
message.warning('业务项目服务内容不大于10000字')
return;
}
this.setState({
loading: true
});
let minPictureUrl = [];
if (this.state.orgCodeUrl.length) {
let picArr = [];
this.state.orgCodeUrl.map(function(item) {
if (item.response && item.response.data && item.response.data.length) {
picArr.push(item.response.data);
}
});
minPictureUrl = picArr.join(',');
}
let maxPictureUrl = [];
if (this.state.companyLogoUrl.length) {
let picArr = [];
this.state.companyLogoUrl.map(function(item) {
if (item.response && item.response.data && item.response.data.length) {
picArr.push(item.response.data);
}
});
maxPictureUrl = picArr.join(',');
}
$.ajax({
method: 'post',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/jtBusiness/project/update',
data: {
auditStatus:index,
id: this.state.id, //业务名称
name: this.state.name, //业务名称
keyword:this.state.keyword, //关键字
categoryId: this.state.categoryId[1], //业务品类
price: this.state.price, //市场价
advertisement:this.state.advertisement,//项目营销说明
summary:this.state.summary,//项目简介
activityPrice: this.state.activityPrice ? this.state.activityPrice : '0', //最低折扣
memberPrice: this.state.memberPrice ? this.state.memberPrice : '0', //会员价
offset: this.state.offset ? this.state.offset : '0',
activityFlag: this.state.activityFlag, //活动生效标识
province: this.state.ProvinceCity ? this.state.ProvinceCity[0] : '', //是否全国
city: this.state.ProvinceCity ? this.state.ProvinceCity[1] : '',
introduce: this.state.introduce,
value: this.state.value,
isHot: this.state.isHot,
minImgUrl: minPictureUrl.length ? minPictureUrl : '',
maxImgUrl: maxPictureUrl.length ? maxPictureUrl : '',
applyConditions: this.state.applyConditions,
tag:this.state.tagArr.join(',')
}
}).done(
function(data) {
if (!data.error.length) {
this.setState({
loading: false,
editvisible: false
});
if(index){
this.submission();
}else{
message.success('保存成功!');
}
} else {
message.warning(data.error[0].message);
}
this.props.handOk();
}.bind(this)
);
},
loadData(ids) {
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/jtBusiness/project/detail',
data: {
id: ids
},
success: function(data) {
if (!data.data) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
} else {
let categoryIdArr=[];
let thisdata = data.data;
let ProvinceCityArr = [];
ProvinceCityArr.push(thisdata.province, thisdata.city);
(this.props.categoryList).map(item=>{
if(item.children.length){
(item.children).map(atem=>{
if(atem.value==thisdata.categoryId){
categoryIdArr.push(item.value,atem.value)
}
})
}
})
let tagFirst =thisdata.tags,tagTxt=[],tagArr=[];
tagFirst.map(item=>{
tagTxt.push(item.name);
tagArr.push(item.id)
})
this.setState({
id: thisdata.id, //业务名称
name: thisdata.name, //业务名称
keyword:thisdata.keyword, //关键字
tagTxt:tagTxt.join(' - '),
tagArr:tagArr,
categoryId: categoryIdArr, //业务品类
number: thisdata.number,
auditInfo:thisdata.auditInfo,
price: thisdata.price, //市场价
advertisement:thisdata.advertisement,//项目营销说明
summary:thisdata.summary,//项目简介
activityPrice: thisdata.activityPrice ? thisdata.activityPrice : '', //最低折扣
memberPrice: thisdata.memberPrice ? thisdata.memberPrice : '', //会员价
offset: thisdata.offset ? thisdata.offset : '',
activityFlag: thisdata.activityFlag ? thisdata.activityFlag.toString() : '', //活动生效标识
ProvinceCity: ProvinceCityArr,
introduce: thisdata.introduce,
createTime: thisdata.createTime ? new Date(thisdata.createTime).toLocaleString() : '',
value: thisdata.value,
isHot:thisdata.isHot,
auditStatus:thisdata.auditStatus,
applyConditions: thisdata.applyConditions,
orgCodeUrl: thisdata.minImgUrl
? splitUrl(thisdata.minImgUrl, ',', globalConfig.avatarHost + '/upload')
: [],
companyLogoUrl: thisdata.maxImgUrl
? splitUrl(thisdata.maxImgUrl, ',', globalConfig.avatarHost + '/upload')
: []
});
}
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
submission(e) {
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
async: true,
url: globalConfig.context + '/api/user/jtBusiness/project/publish',
data: {
id: this.state.id,
auditStatus:1
}
}).done(
function(data) {
if (!data.error.length) {
message.success('提交成功,请耐心等待审核结果.')
this.setState({
loading: false
});
} else {
message.warning(data.error[0].message);
}
}.bind(this)
);
},
cancelFun() {
this.props.closeDesc();
},
componentWillMount() {
if (this.props.data.id) {
this.state.introduce='
';
this.loadData(this.props.data.id);
}
},
//标签
tagOk(){
this.setState({
visibleTag:false
})
},
tagCancel(){
this.setState({
visibleTag:false
})
},
selTag(){
this.setState({
visibleTag:true
})
this.state.tagArr=this.state.tagArr;
},
onChange(e){
this.setState({
tagArr:e
})
},
tagSubmit(e){
e.preventDefault();
let tags =[];
(this.props.tagList).map(item=>{
for(let i=0;i<(this.state.tagArr).length;i++){
if(item.id==(this.state.tagArr[i])){
tags.push(item.name)
}
}
})
this.tagCancel();
this.setState({
tagTxt:tags.join(' - ')
})
},
//发布后查看效果
lookSee(e){
e.preventDefault();
if (!this.state.name) {
message.warning('请输入项目名称');
return;
}
if ((this.state.name).length>16) {
message.warning('项目名称在16个字以内');
return false;
};
if (!this.state.categoryId||!this.state.categoryId[1]) {
message.warning('请选择项目二级业务品类');
return;
}
if (!this.state.ProvinceCity.length) {
message.warning('请选择省份');
return;
}
if (!this.state.price) {
message.warning('请输入正确的市场价');
return;
}
if(this.state.summary&&(this.state.summary).length>40){
message.warning('项目简介字数不得超过40个字。');
return;
}
if(this.state.advertisement&&(this.state.advertisement).length>100){
message.warning('项目营销说明字数不得超过30个字.');
return;
}
this.setState({
loading: true
});
let minPictureUrl = [];
if (this.state.orgCodeUrl.length) {
let picArr = [];
this.state.orgCodeUrl.map(function(item) {
if (item.response && item.response.data && item.response.data.length) {
picArr.push(item.response.data);
}
});
minPictureUrl = picArr.join(',');
}
let maxPictureUrl = [];
if (this.state.companyLogoUrl.length) {
let picArr = [];
this.state.companyLogoUrl.map(function(item) {
if (item.response && item.response.data && item.response.data.length) {
picArr.push(item.response.data);
}
});
maxPictureUrl = picArr.join(',');
}
$.ajax({
method: 'post',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/jtBusiness/project/update',
data: {
id: this.state.id, //业务名称
name: this.state.name, //业务名称
keyword:this.state.keyword, //关键字
categoryId: this.state.categoryId[1], //业务品类
price: this.state.price, //市场价
advertisement:this.state.advertisement,//项目营销说明
summary:this.state.summary,//项目简介
activityPrice: this.state.activityPrice ? this.state.activityPrice : '0', //最低折扣
memberPrice: this.state.memberPrice ? this.state.memberPrice : '0', //会员价
offset: this.state.offset ? this.state.offset : '0',
activityFlag: this.state.activityFlag, //活动生效标识
province: this.state.ProvinceCity ? this.state.ProvinceCity[0] : '', //是否全国
city: this.state.ProvinceCity ? this.state.ProvinceCity[1] : '',
introduce: this.state.introduce,
value: this.state.value,
isHot: this.state.isHot,
minImgUrl: minPictureUrl.length ? minPictureUrl : '',
maxImgUrl: maxPictureUrl.length ? maxPictureUrl : '',
applyConditions: this.state.applyConditions,
tag:(this.state.tagArr).length?this.state.tagArr.join(','):''
}
}).done(
function(data) {
if (!data.error.length) {
this.setState({
loading: false,
});
message.success('提交预览请求成功,即将跳转预览页面');
setTimeout(()=>{
window.open(globalConfig.context+'/portal/service/patentDetail?id='+this.state.id)
},1000)
} else {
message.warning(data.error[0].message);
}
}.bind(this)
);
},
componentWillReceiveProps(nextProps) {
if (!this.props.visible && nextProps.visible) {
this.state.textFileList = [];
this.state.videoFileList = [];
if (nextProps.data.id) {
this.state.introduce='
';
this.loadData(nextProps.data.id);
}
}
},
render() {
const FormItem = Form.Item;
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 16 },
};
let categoryList = this.props.categoryList||[];
let plainOptions= this.props.tagList||[];
return (
* 标签}>
{plainOptions.map((item)=>{
return {item.name}
})}
);
}
})
);
export default DemandDetailForm;