import React from 'react'; import {Modal, message, Spin, Input, Select, Button, Form, Col, Cascader, Tag, Tooltip,AutoComplete} from 'antd'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import { citySelect, provinceList ,areaSelect} from '@/NewDicProvinceList'; import {socialAttribute,customerSource} from '@/dataDic.js'; import TextArea from "antd/es/input/TextArea"; const Option = Select.Option; const AchievementDetailForm = Form.create()(React.createClass({ getInitialState() { return { loading: false, data: {}, detailApi:'', businessScope:[], inputVisible:false, cooperationProjects:[], selectCooperationProjects:[] }; }, handleSubmit(e) { // if (/.*[\u4e00-\u9fa5]+.*$/.test(this.state.content)) { // } else { // message.error("请填写正确的姓名,且至少包含一个汉字"); // return; // } e.preventDefault(); this.props.form.validateFields((err, values) => { if(values.name.length>64){ message.warning('公司名称字数不超过64个') return false; }; let regu = /[`~!#$%^&*'_[\]+=<>?:"{}|~!#¥%……&*=-@-!{}|/《》?:“”【】、;;‘’,,.。、\s+]/g; if(regu.test(values.name)){ message.warning('公司名称不能存在特殊符号!') return false; } if (/.*[\u4e00-\u9fa5]+.*$/.test(values.content)) { } else { message.error("请填写正确的联系人,且至少包含一个汉字"); return false; }; if (/.*[\u4e00-\u9fa5]+.*$/.test(values.position)) { } else { message.error("请填写正确的职位,且至少包含一个汉字"); return false; }; if(!values.ProvinceCity[1]) { message.warning('请选择地区'); return false; }; if(values.content.length>32){ message.warning('联系人字数不超过32个') return false; }; if(values.length>13){ message.warning('电话号码字数不超过13个') return false; }; if(this.state.businessScope.length === 0){ message.warning('请选择主营产品') return false; } if(this.state.selectCooperationProjects.length === 0){ message.warning('请选择意向合作项目') return false; } let arr = []; for(let i of this.state.selectCooperationProjects){ arr.push(i.label) } if (!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/customer/addCustomer', data: { name: values.name, contacts:values.content, contactMobile:values.telnum, // societyTag:values.societyTagt, //source:values.customerSource, province:(values.ProvinceCity)[0],//省 city:(values.ProvinceCity)[1],//市 area:(values.ProvinceCity)[2],//区 type:'1', intendedProject:arr.join(','), businessScope:this.state.businessScope.join(','), position:values.position, } }).done(function (data) { this.setState({ loading: false }); if (!data.error.length) { message.success('保存成功!'); this.props.handleOk(); } else { message.warning(data.error[0].message); } }.bind(this)); } }); }, componentWillMount() { this.state.name=''; this.state.content=''; this.state.position=''; this.state.telnum=''; // this.state.societyTagt='0'; this.state.customerSource='0'; this.state.inputValue=''; this.state.businessScope = []; this.state.inputVisible = false; this.state.cooperationProjects = []; this.state.selectCooperationProjects = []; }, componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { this.state.name=''; this.state.content=''; this.state.position = ''; this.state.telnum=''; this.state.inputValue=''; this.state.businessScope = []; this.state.inputVisible = false; this.state.cooperationProjects = []; this.state.selectCooperationProjects = []; // this.state.societyTagt='0'; this.props.form.resetFields(); }; }, handleClose(removedTag){ let businessScope = this.state.businessScope.filter(tag => {return tag !== removedTag}); this.setState({ businessScope }); }, handleCloseCooperation(removedTag){ let selectCooperationProjects = this.state.selectCooperationProjects.filter(tag => {return tag.value !== removedTag.value}); this.setState({ selectCooperationProjects }); }, showInput(){ let str = this.state.businessScope.join('/') this.setState({ inputVisible: true, inputValue: str }); }, handleInputConfirm(){ let inputValue = this.state.inputValue; let arr = inputValue.split('/'); let lv = true; for(let i of arr){ if(i.length > 16){ message.warning('单个标签字数不能超过16个字符') lv = false; return; } } if(lv){ arr = Array.from(new Set(arr)); arr = arr.filter(v=>v); this.setState({ businessScope:arr, inputVisible: false, inputValue: '', }); } }, //加载(自动补全) supervisor(value) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/order/getBusinessProjectByName', data: { businessName: value }, success: function (data) { let thedata = data.data; if (data.error.length === 0) { this.setState({ cooperationProjects: thedata, }); }else{ message.warning(data.error[0].message); } }.bind(this), }).always( function () { }.bind(this) ); }, onSelect(value){ let arr = this.state.cooperationProjects.filter(v=>v.id === value); let arr1 = this.state.selectCooperationProjects.filter(v=>v.value === value); if(arr.length > 0){ if(arr1.length > 0){ message.warning('选项已存在'); }else{ this.state.selectCooperationProjects.push({ label: arr[0].bname, value: arr[0].id, }) this.setState({ selectCooperationProjects:this.state.selectCooperationProjects }) } } }, render() { const theData = this.state.data || {}; const { getFieldDecorator } = this.props.form; const FormItem = Form.Item const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 }, }; return (