/* 
	@author:李霆
	@update:2018/05/29
	@descript:复制粘贴,拿起来就是干!!
*/
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,
	InputNumber
} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import './unit.less';
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 Unit = React.createClass({
	getInitialState() {
		return {
			loading: false,
			orgCodeUrl: [],
			companyLogoUrl: [],
			ProvinceCity:[]
		};
	},
	loadInformation(record) {
		this.setState({
			loading:true
		})
		$.ajax({
			method: 'get',
			dataType: 'json',
			url: globalConfig.context + '/api/user/getOrganizationDetail',
			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,
					industry: String(thisData.industry) == 'null' ? undefined : String(thisData.industry),
					societyTag: thisData.societyTag || undefined,
					introduction: thisData.introduction,
					postalAddress: thisData.postalAddress,
					fixedTel: thisData.fixedTel,
					registeredCapital: thisData.registeredCapital,
					enterpriseScale: thisData.enterpriseScale,
					legalPerson: thisData.legalPerson,
					legalPersonIdCard: thisData.legalPersonIdCard,
					legalPersonTel: thisData.legalPersonTel,
					legalPersonEmail: thisData.legalPersonEmail,
					businessScope: thisData.businessScope,
					orgCode: thisData.orgCode,
					type:thisData.type,
					authentication:thisData.authentication
				});
			}.bind(this)
		}).always(
			function() {
				this.setState({
					loading: false
				});
			}.bind(this)
		);
	},
	//图片
	getOrgCodeUrl(e) {
		this.setState({
			orgCodeUrl: e
		});
	},
	getCompanyLogoUrl(e) {
		this.setState({
			companyLogoUrl: e
		});
	},
	//基本信息提交
	newSubmit(e) {
		if(!this.state.identifyName){
			message.warning('请填写单位名称!');
			return;
		}
		if (!this.state.industry) {
			message.warning('请选择行业!');
			return false;
		}
		if (!this.state.societyTag) {
			message.warning('请选择社会性质!');
			return false;
		}
		
		if (isNaN(this.state.registeredCapital)) {
			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/user/updateOrganizationDetail',
			data: {
				id: this.state.InformationId,
				uid: this.state.InformationUid,
				societyTag: this.state.societyTag,
				identifyName: this.state.identifyName, //单位名称
				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,
				fixedTel: this.state.fixedTel,
				contactsFax: this.state.contactsFax,
				registeredCapital: this.state.registeredCapital ? this.state.registeredCapital : 0,
				enterpriseScale: this.state.enterpriseScale,
				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,
				orgCode: this.state.orgCode,
				businessScope: this.state.businessScope,
				introduction: this.state.introduction,
				companyLogoUrl: thecompanyLogoUrl != 0 ? thecompanyLogoUrl : '',
				orgCodeUrl: theorgCodeUrl != 0 ? theorgCodeUrl : '',
				auditStatus: this.state.auditStatus,
				authentication:this.state.authentication,
				type:this.state.type
			}
		}).done(
			function(data) {
				this.setState({
					loading: false
				});
				if (!data.error.length) {
					if(this.state.type!='1'){
						message.success('企业认证成功,1s后回到首页.')
						setTimeout(()=>{
							window.location.href = globalConfig.context + "/user/account/index.html";
						},1000)  
					}else{
						message.success('保存成功');
						this.loadInformation();
					}
				} else {
					message.warning(data.error[0].message);
				}
			}.bind(this)
		);
	},
	subFun(){
		if(this.state.type=='0'||this.state.type=='1'){
			this.newSubmit()
		}else{
			this.setState({
				visible:true
			})
		}
	},
	handleOk(){
		this.newSubmit();
		this.setState({
			visible:false
		})
	},
	handleCancel(){
		this.setState({
			visible:false
		})
	},
	componentWillMount() {
		this.loadInformation();
	},
	componentWillReceiveProps(nextProps) {
		
	},
	render() {
		return (
			
		);
	}
});
export default Unit;