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 ,getProvince} 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 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 ProvinceS = thisData.locationProvince, //getprovince
				    citys = thisData.locationCity,
				    Areas = thisData.locationArea,
				    ProvinceCity = getProvince(ProvinceS, citys, Areas);
				this.setState({
					orgCodeUrl: thisData.orgCodeUrl ? splitUrl(thisData.orgCodeUrl, ',', globalConfig.avatarHost + '/upload') : [],
					companyLogoUrl: thisData.companyLogoUrl ? splitUrl(thisData.companyLogoUrl, ',', globalConfig.avatarHost + '/upload') : [],
					ProvinceCity: ProvinceCity,
					basicData:thisData
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	//图片
	getOrgCodeUrl(e) {
		this.setState({
			orgCodeUrl: e
		});
	},
	getCompanyLogoUrl(e) {
		this.setState({
			companyLogoUrl: e
		});
	},
	//取消
	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() {
		const basicData = this.state.basicData || [];
		return(
			<div>
				 <Form layout="horizontal" onSubmit={this.newSubmit} id="demand-form">
	                <Spin spinning={this.state.loading}>
		               	<div className="clearfix" style={{paddingLeft:'60px'}}>
	                    	<FormItem className="half-item"
			                    labelCol={{ span: 4 }}
			                    wrapperCol={{ span: 18 }}
			                    label="客户名称"
		                        >
		                        <span>{basicData.identifyName}</span>
		                    </FormItem>
	                    </div>
	                    <div className="clearfix" style={{paddingLeft:'60px'}}>
	                    	<FormItem className="half-item" 
	                         labelCol={{ span: 4 }}
	                         wrapperCol={{ span: 18 }}
	                         label="行业">
                                <span>{getIndustry(basicData.industry)}</span>
	                   		 </FormItem>
	                   		 <FormItem className="half-item" 
	                           labelCol={{ span: 4 }}
	                            wrapperCol={{ span: 18 }}
	                           label="社会属性"
	                         > 
                                <span>{getSocialAttribute(basicData.societyTag)}</span>
	                   		 </FormItem>
	                         <FormItem className="half-item" 
	                           labelCol={{ span: 4 }}
	                           wrapperCol={{ span: 18 }}
	                           label="省-市-区"
	                          > 
								<span>{this.state.ProvinceCity}</span>
		                   </FormItem>
		                   <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                         label="通信地址"
		                            >
		                   		<span>{basicData.postalAddress}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                         label="固定电话"
		                            >
		                   			<span>{basicData.contactsFixedTel}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="客户传真"
		                            >
		                   		<span>{basicData.contactsFax}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="注册资本"
		                            >	
		                   		   <span>{basicData.registeredCapital}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="单位规模"
		                            >
		                   		   <span>{basicData.enterpriseScale}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="法人名称"
		                            >
		                   		    <span>{basicData.legalPerson}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="身份证号码"
		                            >
		                   		    <span>{basicData.legalPersonIdCard}</span>
		                    </FormItem>
		                    <FormItem className="half-item" 
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="主要联系人"
	                           	 >
		                   		    <span>{basicData.contacts}</span>
		                     </FormItem>
		                     <FormItem className="half-item" 
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="主要联系人号码"
	                           	 >	
		                   		    <span>{basicData.contactMobile}</span>
		                     </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="法人电话"
		                            > 
		                   		    <span>{basicData.legalPersonTel}</span>
		                    </FormItem>
		                    <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="电子邮箱"
		                            >
		                   		    <span>{basicData.legalPersonEmail}</span>
		                    </FormItem>
				            <FormItem className="half-item"
			                    	labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="机构代码"
		                            >
		                   		    <span>{basicData.orgCode}</span>
		                    </FormItem>
		                    <div className="clearfix pictures">
		                        <FormItem
			                        labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="机构证(PIC)" >
			                        <div className="clearfix">
			                            <Upload className="demandDetailShow-upload"
			                                listType="picture-card"
			                                fileList={this.state.orgCodeUrl}                               
			                                onPreview={(file) => {
			                                    this.setState({
			                                        previewImage: file.url || file.thumbUrl,
			                                        previewVisible: true,
			                                    });
			                                }} >
			                            </Upload>
			                            <Modal maskClosable={false} footer={null}
			                                visible={this.state.previewVisible}
			                                onCancel={() => { this.setState({ previewVisible: false }) }}>
			                                <img alt="" style={{ width: '100%' }} src={this.state.previewImage || ''} />
			                            </Modal>
			                        </div>    
		                        </FormItem>
		                        <FormItem
			                        labelCol={{ span: 4 }}
			                        wrapperCol={{ span: 18 }}
			                        label="单位logo" > 
			                        <div className="clearfix">
			                            <Upload className="demandDetailShow-upload"
			                                listType="picture-card"
			                                fileList={this.state.companyLogoUrl}                               
			                                onPreview={(file) => {
			                                    this.setState({
			                                        previewImage: file.url || file.thumbUrl,
			                                        previewVisible: true,
			                                    });
			                                }} >
			                            </Upload>
			                            <Modal maskClosable={false} footer={null}
			                                visible={this.state.previewVisible}
			                                onCancel={() => { this.setState({ previewVisible: false }) }}>
			                                <img alt="" style={{ width: '100%' }} src={this.state.previewImage || ''} />
			                            </Modal>
			                        </div>       
			                    </FormItem>
			                </div> 
			                <div className="clearfix">
			                    <FormItem
		                        labelCol={{ span: 2 }}
		                        wrapperCol={{ span: 18 }}
		                        label="业务范围" >
		                   			<span>{basicData.businessScope}</span>
			                    </FormItem>
			                    <FormItem
			                        labelCol={{ span: 2 }}
			                        wrapperCol={{ span: 18 }}
			                        label="单位简介" >
		                   			<span>{basicData.introduction}</span>
			                    </FormItem>
		                    </div>
	                    </div>		                	
				    </Spin>
				</Form>		
			</div>
		)
	}
})
export default Basic;