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 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: [],
		}
	},
	loadInformation(record) {
		$.ajax({
			method: "get",
			dataType: "json",
			url: globalConfig.context + '/api/admin/customer/findOrganizationCustomerDetail',
			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.locationProvince; //getprovince
				let citys = thisData.locationCity;
				let Areas = thisData.locationArea;
				ProvinceCityArr.push(ProvinceS, citys, Areas);
				this.setState({
					InformationId: thisData.id,
					InformationUid: thisData.uid,
					identifyName: thisData.identifyName,
					listed: thisData.listed,
					highTechZone: thisData.highTechZone,
					orgCodeUrl: thisData.orgCodeUrl ? splitUrl(thisData.orgCodeUrl, ',', globalConfig.avatarHost + '/upload') : [],
					companyLogoUrl: thisData.companyLogoUrl ? splitUrl(thisData.companyLogoUrl, ',', globalConfig.avatarHost + '/upload') : [],
					dataInformation: thisData,
					ProvinceCity: ProvinceCityArr[0]!=null?ProvinceCityArr:undefined,
					contacts: thisData.contacts,
					contactMobile: thisData.contactMobile,
					industry: String(thisData.industry) == 'null' ? undefined : String(thisData.industry),
					international: thisData.international,
					societyTag: thisData.societyTag||undefined,
					introduction: thisData.introduction,
					postalAddress: thisData.postalAddress,
					contactsFixedTel: thisData.contactsFixedTel,
					contactsFax: thisData.contactsFax,
					registeredCapital: thisData.registeredCapital,
					enterpriseScale: thisData.enterpriseScale,
					legalPerson: thisData.legalPerson,
					legalPersonIdCard: thisData.legalPersonIdCard,
					legalPersonTel: thisData.legalPersonTel,
					legalPersonEmail: thisData.legalPersonEmail,
					businessScope: thisData.businessScope,
					orgCode: thisData.orgCode,
					investment: thisData.investment,
					auditStatus: thisData.auditStatus ? String(thisData.auditStatus) : undefined,
					businessAudit: thisData.businessAudit
				});
			}.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;
		};
		if(isNaN(this.state.registeredCapital)) {
			message.warning('注册资本只能输入数字')
			return false;
		};
		if(isNaN(this.state.enterpriseScale)) {
			message.warning('单位规模只能输入数字')
			return false;
		}
		this.setState({
			selectedRowKeys: [],
		});
		let theorgCodeUrl = [];
		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);
				}
			});
			theorgCodeUrl = picArr.join(",");
		};
		let thecompanyLogoUrl = [];
		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);
				}
			});
			thecompanyLogoUrl = picArr.join(",");
		};
		this.setState({
			loading: true
		});
		$.ajax({
			method: "post",
			dataType: "json",
			url: globalConfig.context + '/api/admin/customer/updateOrganizationCustomer',
			data: {
				id: this.state.InformationId,
				uid: this.state.InformationUid,
				societyTag: this.state.societyTag,
				introduction: this.state.introduction,
				unitName: this.state.unitName,
				industry: this.state.industry,
				locationProvince: (this.state.ProvinceCity)[0], //省-
				locationCity: (this.state.ProvinceCity)[1], //市
				locationArea: (this.state.ProvinceCity)[2], //区
				postalAddress: this.state.postalAddress,
				contactsFixedTel: this.state.contactsFixedTel,
				contactsFax: this.state.contactsFax,
				registeredCapital: this.state.registeredCapital ? this.state.registeredCapital : 0,
				enterpriseScale: this.state.enterpriseScale ? this.state.enterpriseScale : 0,
				legalPerson: this.state.legalPerson,
				legalPersonIdCard: this.state.legalPersonIdCard,
				legalPersonTel: this.state.legalPersonTel,
				legalPersonEmail: this.state.legalPersonEmail,
				highTechZone: this.state.highTechZone,
				listed: this.state.listed,
				contacts: this.state.contacts,
				contactMobile: this.state.contactMobile,
				international: this.state.international,
				orgCode: this.state.orgCode,
				businessScope: this.state.businessScope,
				introduction: this.state.introduction,
				companyLogoUrl: thecompanyLogoUrl != 0 ? thecompanyLogoUrl : '',
				orgCodeUrl: theorgCodeUrl != 0 ? theorgCodeUrl : '',
				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)
	},
	componentWillMount(){
		this.loadInformation(this.props.data.id)
	},
	componentWillReceiveProps(nextProps) {
		if(nextProps.data&&nextProps.basicState){
			this.loadInformation(nextProps.data.id)
		}
	},
	render() {
		return(
			
		)
	}
})
export default Basic;