import React from 'react';
import { Radio, Icon, Button, AutoComplete, Cascader, layout, Input, Select, Tabs, Spin, Popconfirm, Popover, Table, Switch, message, DatePicker, Modal, Upload, Form, Row, Col, TimePicker } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import { citySelect, provinceList, areaSelect } from '@/NewDicProvinceList';
import { socialAttribute, industry, newFollow, auditStatusL, lvl, currentMember, cityArr, statuslist, customerStatus, intentionalService, sex } from '@/dataDic.js';
import { getCompanyIntention, splitUrl, getIndustry, getStatuslist, getAuditStatus, getContactType, getSocialAttribute, getfllowSituation, beforeUploadFile, getWhether, getcityArr, getcustomerStatue, getfllowSituationOn, getCertification, getcustomerTyp, getLvl, getCurrentMember, getprovince } from '@/tools.js';
const FormItem = Form.Item;
const monthFormat = 'YYYY/MM';
//图片组件
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 Basic = React.createClass({
	getInitialState() {
		return {
			loading: false,
			orgCodeUrl: [],
			companyLogoUrl: [],
			headPortraitUrl: [],
			positiveIdUrl: [],
			oppositeIdUrl: []
		}
	},
	loadInformation(record) {
		this.setState({
			loading: true
		});
		$.ajax({
			method: "get",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/customer/findPersonalCustomerDetail',
			data: {
				uid: record
			},
			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.province; //getprovince
				let citys = thisData.city;
				let Areas = thisData.area;
				ProvinceCityArr.push(ProvinceS, citys, Areas);
				let month = thisData.dateOfBirthYear ? thisData.dateOfBirthYear + '/' + thisData.dateOfBirthMonth : undefined;
				this.setState({
					InformationId: thisData.id,
					InformationUid: thisData.uid,
					identifyName: thisData.identifyName,
					listed: thisData.listed,
					highTechZone: thisData.highTechZone,
					headPortraitUrl: thisData.headPortraitUrl ? splitUrl(thisData.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
					positiveIdUrl: thisData.positiveIdUrl ? splitUrl(thisData.positiveIdUrl, ',', globalConfig.avatarHost + '/upload') : [],
					oppositeIdUrl: thisData.oppositeIdUrl ? splitUrl(thisData.oppositeIdUrl, ',', globalConfig.avatarHost + '/upload') : [],
					dataInformation: thisData,
					idNumber: thisData.idNumber,
					contacts: thisData.contacts,
					contactMobile: thisData.contactMobile,
					ProvinceCity: ProvinceCityArr[0]!=null?ProvinceCityArr:undefined,
					industry: thisData.industry ? String(thisData.industry) : undefined,
					societyTag: thisData.societyTag||undefined,
					sex: thisData.sex,
					yearMonth: month,
					postalAddress: thisData.postalAddress,
					fixedTel: thisData.fixedTel,
					consultationPrice: thisData.consultationPrice,
					email: thisData.email,
					qq: thisData.qq,
					introduction: thisData.introduction,
					expert: thisData.expert,
					celebrity: thisData.celebrity,
					consultant: thisData.consultant,
					international: thisData.international,
					investment: thisData.investment,
					professionalTitle: thisData.professionalTitle,
					workUnit: thisData.workUnit,
					education: thisData.education,
					graduateSchool: thisData.graduateSchool,
					majorCategory: thisData.majorCategory,
					qualification: thisData.qualification,
					businessAudit: thisData.businessAudit,
					auditStatus: thisData.auditStatus ? String(thisData.auditStatus) : undefined,
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	//图片
	getOrgCodeUrl(e) {
		this.setState({
			orgCodeUrl: e
		});
	},
	getCompanyLogoUrl(e) {
		this.setState({
			companyLogoUrl: e
		});
	},
	//基本信息提交
	newSubmit(e) {
		e.preventDefault();
		if(!this.state.industry) {
			message.warning('请选择行业');
			return false;
		};
		if(!this.state.societyTag) {
			message.warning('请选择社会性质');
			return false;
		};
		if(!this.state.ProvinceCity[1]) {
			message.warning('请选择地区');
			return false;
		};
		var reg = /^[1-9]\d*$|^0$/;
		if(this.state.consultationPrice) {
			if(this.state.consultationPrice.length > 6) {
				message.warning('咨询费用不超过6位数');
				this.refs.consul.focus();
				return false;
			};
			if(!reg.test(this.state.consultationPrice)) {
				message.warning('咨询费用只能输入数字');
				this.refs.consul.focus();
				return false;
			}
		}
		this.state.data = [];
		this.setState({
			selectedRowKeys: [],
		});
		let theorgCodeUrl = [];
		if(this.state.headPortraitUrl.length) {
			let picArr = [];
			this.state.headPortraitUrl.map(function(item) {
				if(item.response && item.response.data && item.response.data.length) {
					picArr.push(item.response.data);
				}
			});
			theorgCodeUrl = picArr.join(",");
		};
		let thecompanyLogoUrl = [];
		if(this.state.positiveIdUrl.length) {
			let picArr = [];
			this.state.positiveIdUrl.map(function(item) {
				if(item.response && item.response.data && item.response.data.length) {
					picArr.push(item.response.data);
				}
			});
			thecompanyLogoUrl = picArr.join(",");
		};
		let thecompanyLogoUrls = [];
		if(this.state.oppositeIdUrl.length) {
			let picArr = [];
			this.state.oppositeIdUrl.map(function(item) {
				if(item.response && item.response.data && item.response.data.length) {
					picArr.push(item.response.data);
				}
			});
			thecompanyLogoUrls = picArr.join(",");
		};
		let years = [];
		let yearMonth = this.state.yearMonth != undefined ? new Date(this.state.yearMonth).toLocaleDateString() : '';
		years = yearMonth.split('/');
		this.setState({
			loading: true
		});
		$.ajax({
			method: "post",
			dataType: "json",
			url: globalConfig.context + '/api/admin/customer/updatePersonalCustomer',
			data: {
				id: this.state.InformationId,
				uid: this.state.InformationUid,
				societyTag: this.state.societyTag,
				identifyName: this.state.identifyName,
				industry: this.state.industry,
				dateOfBirthYear: years[0], //出生年
				dateOfBirthMonth: years[1], //出生月
				province: (this.state.ProvinceCity)[0], //省-
				city: (this.state.ProvinceCity)[1], //市
				area: (this.state.ProvinceCity)[2], //区
				sex: this.state.sex,
				expert: this.state.expert,
				celebrity: this.state.celebrity,
				consultant: this.state.consultant,
				international: this.state.international,
				fixedTel: this.state.fixedTel,
				consultationPrice: this.state.consultationPrice ? this.state.consultationPrice : '',
				qq: this.state.qq,
				contacts: this.state.contacts,
				contactMobile: this.state.contactMobile,
				idNumber: this.state.idNumber,
				email: this.state.email,
				isMember: this.state.isMember,
				postalAddress: this.state.postalAddress,
				introduction: this.state.introduction,
				positiveIdUrl: thecompanyLogoUrl.length != 0 ? thecompanyLogoUrl : '',
				oppositeIdUrl: thecompanyLogoUrls.length != 0 ? thecompanyLogoUrls : '',
				headPortraitUrl: theorgCodeUrl.length != 0 ? theorgCodeUrl : '',
				investment: this.state.investment,
				professionalTitle: this.state.professionalTitle,
				workUnit: this.state.workUnit,
				education: this.state.education,
				graduateSchool: this.state.graduateSchool,
				majorCategory: this.state.majorCategory,
				qualification: this.state.qualification,
				businessAudit: this.state.businessAudit,
				auditStatus: this.state.auditStatus,
			}
		}).done(function(data) {
			this.setState({
				loading: false
			});
			if(!data.error.length) {
				message.success('保存成功!');
				this.props.closeDetail(false, true)
			} else {
				message.warning(data.error[0].message);
			}
		}.bind(this));
	},
	//取消
	detailsModal() {
		this.props.closeDetail(false, false)
	},
	getHeadPortraitUrl(e) {
		this.setState({ headPortraitUrl: e });
	},
	getPositiveIdUrl(e) {
		this.setState({ positiveIdUrl: e });
	},
	getOppositeIdUrl(e) {
		this.setState({ oppositeIdUrl: e });
	},
	componentWillMount() {
		this.loadInformation(this.props.data.id)
	},
	componentWillReceiveProps(nextProps) {
		if(nextProps.data && nextProps.basicState) {
			this.loadInformation(nextProps.data.id)
		}
	},
	render() {
		const {
			RangePicker,
			MonthPicker
		} = DatePicker;
		const formItemLayout = {
			labelCol: {
				span: 8
			},
			wrapperCol: {
				span: 14
			},
		};
		return(
			
		)
	}
})
export default Basic;