import React from 'react';
import { Radio, Icon, Button, Cascader, Input, Select, Tabs, Spin, Popconfirm, Table, Switch, message, DatePicker, Modal, Upload, Form, Row, Col } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import './myClient.less';
import { citySelect, provinceList, areaSelect } from '../../../areaList';
import {getProvinceList} from '../../../addressList';
const { Column, ColumnGroup } = Table;
const TabPane = Tabs.TabPane;
const monthFormat = 'YYYY/MM';
import CustomerDetail from './myClientDesc.jsx';
import { socialAttribute, industry, auditStatusL, newFollow, lvl, currentMember, statuslist, customerStatus, intentionalService } from '../../../dataDic.js';
import { getSocialAttribute, splitUrl,getAuditStatus, getCompanyIntention, getStatuslist, getContactType, getIndustryType, getfllowSituation, beforeUploadFile, getWhether, getcustomerStatue, getfllowSituationOn, getCertification, getcustomerTyp, getLvl, getCurrentMember, getprovince } from '../../../tools.js';
//图片组件
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 QueryCustomer = Form.create()(React.createClass({
	loadData(pageNo, apiUrl) {
		this.state.data = [];
		this.setState({
			loading: true,
			ispage:pageNo,
		});
		$.ajax({
			method: "post",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/customer/listAllPersonalCustomer',
			data: {
				pageNo: pageNo || 1,
				pageSize: this.state.pagination.pageSize,
				expertAudit:2,
				type: this.state.typeSearch, //名称1   
				name: this.state.nameSearch,
				province: !(this.state.addressSearch).length ? this.state.provinceSearch : this.state.addressSearch[0],
				city: !(this.state.addressSearch).length ? '' : this.state.addressSearch[1],
				status: this.state.statusSearch,
				industry: this.state.industrySearch,
				businessAudit: this.state.serviceCertificationSearch,
				auditStatus: this.state.userCertificationSearch,
				currentMemberStatus: this.state.currentMemberStatusSearch,
				lvl: this.state.lvlSearch,
				listed: this.state.listedSearch, //是否上市
				highTechZone: this.state.highTechZoneSearch, //是否高新
				startDate: this.state.releaseDate[0],
				endDate: this.state.releaseDate[1],
				isMember: this.state.isMemberSearch,
				international: this.state.internationalSearch,
				celebrity: this.state.celebritySearch,
				expert: this.state.expertSearch,
				industry: this.state.industrySearch,
				shareType: this.state.shareTypeSearch,
			},
			success: function(data) {
				let theArr = [];
				if(data.error.length || data.data.list == "") {
					if(data.error && data.error.length) {
						message.warning(data.error[0].message);
					};
				} else {
					for(let i = 0; i < data.data.list.length; i++) {
						let thisdata = data.data.list[i];
						theArr.push({
							key: i,
							id: thisdata.uid,
							type: thisdata.type,
							name: thisdata.name,
							status: thisdata.status,
							contacts: thisdata.contacts,
							contactMobile: thisdata.contactMobile,
							industry: thisdata.industry,
							createTime: thisdata.createTime,
							businessAudit: thisdata.businessAudit,
							auditStatus: thisdata.auditStatus,
							lvl: thisdata.lvl,
							shareType: thisdata.shareType,
							isMember: thisdata.isMember,
							consultant: thisdata.consultant,
							societyTag: thisdata.societyTag,
							currentMemberStatus: thisdata.currentMemberStatus,
							international: thisdata.international,
							listed: thisdata.listed,
							international: thisdata.international,
							expert: thisdata.expert,
							celebrity: thisdata.celebrity,
							adminName: thisdata.adminName,
							releaseStatus: thisdata.releaseStatus,
							highTechZone: thisdata.highTechZone,
							locationProvince: thisdata.province ? thisdata.province + '-' + thisdata.city || '' + '-' + thisdata.area : '--'
						});
					};
					this.state.pagination.current = data.data.pageNo ;
					this.state.pagination.total = data.data.totalCount ;
				};
				if(!data.data.list.length){
					this.state.pagination.current=0
					this.state.pagination.total=0
				}
				this.setState({
					dataSource: theArr,
					pagination: this.state.pagination,
					selectedRowKeys:[]
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	//点击出现函数
	setModal2VisibleOk(e) {
		this.setState({
			modal2Visible: true
		});
	},
	//点击消失函数
	setModal2Visiblecancel(e) {
		this.setState({
			modal2Visible: false
		});
	},
	getPictureUrl(e) {
		this.setState({ pictureUrl: e });
	},
	handleOk(e) {
		this.setState({
			visible: false,
		});
	},
	handleCancel(e) {
		this.setState({
			visible: false,
		});
	},
	getInitialState() {
		return {
			addressSearch: [],
			positiveIdUrl: [],
			oppositeIdUrl: [],
			headPortraitUrl: [],
			visible: false,
			searchMore: true,
			releaseDate: [],
			releaseDate: [],
			selectedRowKeys: [],
			selectedRowKey: [],
			selectedRows: [],
			loading: false,
			pagination: {
				defaultCurrent: 1,
				defaultPageSize: 10,
				showQuickJumper: true,
				pageSize: 10,
				onChange: function(page) {
					this.loadData(page);
				}.bind(this),
				showTotal: function(total) {
					return '共' + total + '条数据';
				}
			},
			paginations: {
				defaultCurrent: 1,
				defaultPageSize: 10,
				showQuickJumper: true,
				pageSize: 10,
				onChange: function(page) {
					this.loadVisit(page);
				}.bind(this),
				showTotal: function(total) {
					return '共' + total + '条数据';
				}
			},
			paginationsy: {
				defaultCurrent: 1,
				defaultPageSize: 10,
				showQuickJumper: true,
				pageSize: 10,
				onChange: function(page) {
					this.loadBfVisit(page, false);
				}.bind(this),
				showTotal: function(total) {
					return '共' + total + '条数据';
				}
			},
			paginationt: {
				defaultCurrent: 1,
				defaultPageSize: 10,
				showQuickJumper: true,
				pageSize: 10,
				onChange: function(page) {
					this.BusinessList(page, false);
				}.bind(this),
				showTotal: function(total) {
					return '共' + total + '条数据';
				}
			},
			//业务意向列表
			intentionList: [{
					title: '业务名称',
					dataIndex: 'businessGlossoryId',
					key: 'businessGlossoryId',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  : {getCompanyIntention(text)}
					}
				},
				{
					title: '最新进度',
					dataIndex: 'followSituation',
					key: 'followSituation',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  : {getfllowSituation(text)}
					}
				}, {
					title: '最新状态',
					dataIndex: 'customerStatus',
					key: 'customerStatus',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  : {getcustomerStatue(text)}
					}
				}, {
					title: '跟进说明',
					dataIndex: 'remarks',
					key: 'remarks',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.remarks = e.target.value; this.setState({ data: this.state.data }); }}
	                             style={{width:'120px'}}/> : {text}
					}
				}
			],
			businessIntentionList: [{
				title: '意向时间',
				dataIndex: 'createTime',
				key: 'createTime'
			}, {
				title: '客户姓名',
				dataIndex: 'identifyName',
				key: 'identifyName'
			}, {
				title: '业务名',
				dataIndex: 'businessName',
				key: 'businessName'
			}, {
				title: '营销员',
				dataIndex: 'adminName',
				key: 'adminName'
			}, {
				title: '业务意向进度',
				dataIndex: 'followSituation',
				key: 'followSituation',
				render: text => { return getfllowSituation(text) }
			}, {
				title: '客户状态',
				dataIndex: 'customerStatus',
				key: 'customerStatus',
				render: text => { return getcustomerStatue(text) }
			}],
			businessFollowList: [{
					title: '跟进时间',
					dataIndex: 'followTime',
					key: 'followTime',
				}, {
					title: '营销员',
					dataIndex: 'adminName',
					key: 'adminName',
				}, {
					title: '业务意向进度',
					dataIndex: 'followSituation',
					key: 'followSituation',
					render: text => { return getfllowSituation(text) }
				}, {
					title: '客户状态',
					dataIndex: 'customerStatus',
					key: 'customerStatus',
					render: text => { return getcustomerStatue(text) }
				},
				{
					title: '拜访方式',
					dataIndex: 'contactType',
					key: 'contactType',
					render: text => { return getContactType(text) }
				}, {
					title: '联系人',
					dataIndex: 'contacts',
					key: 'contacts',
				},
				{
					title: '联系电话',
					dataIndex: 'contactMobile',
					key: 'contactMobile',
				}
			],
			visitsList: [{
				title: '拜访时间',
				dataIndex: 'followTime',
				key: 'followTime'
			}, {
				title: '客户姓名',
				dataIndex: 'identifyName',
				key: 'identifyName'
			}, {
				title: '拜访方式',
				dataIndex: 'contactType',
				key: 'contactType',
				render: text => { return getContactType(text) }
			}, {
				title: '联系人',
				dataIndex: 'contacts',
				key: 'contacts'
			}, {
				title: '联系电话',
				dataIndex: 'contactMobile',
				key: 'contactMobile'
			}, {
				title: '拜访人',
				dataIndex: 'adminName',
				key: 'adminName'
			}, {
				title: '拜访说明',
				dataIndex: 'result',
				key: 'result',
				render: text => {
					return {text}
				}
			}],
			ContactsLists: [{
					title: '姓名',
					dataIndex: 'name',
					key: 'name',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.name = e.target.value; 
	                           	this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '联系人部门',
					dataIndex: 'depatrment',
					key: 'depatrment',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.depatrment = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '联系人职务',
					dataIndex: 'position',
					key: 'position',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.position = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '手机号码',
					dataIndex: 'mobile',
					key: 'mobile',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.mobile = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '微信',
					dataIndex: 'wechat',
					key: 'wechat',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.wechat = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '联系人QQ',
					dataIndex: 'qq',
					key: 'qq',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.qq = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}, {
					title: '电子邮箱',
					dataIndex: 'email',
					key: 'email',
					render: (text, record, index) => {
						return adminData.isSuperAdmin ?  { record.email = e.target.value; this.setState({ contactList: this.state.contactList }); }} style={{width:'120px'}}/> : {text}
					}
				}
			],
			columnsman: [{
				title: '姓名',
				dataIndex: 'name',
				key: 'name'
			}, {
				title: '手机号码',
				dataIndex: 'mobile',
				key: 'mobile'
			}],
			columns: [{
					title: '客户姓名',
					dataIndex: 'name',
					key: 'name',
				}, {
					title: '地区',
					dataIndex: 'locationProvince',
					key: 'locationProvince',
				},
				{
					title: '公共客户',
					dataIndex: 'shareType',
					key: 'shareType',
					render: (text, record) => { return record.shareType == '1' ? 公共客户 : 个人客户 }
				},
				{
					title: '行业',
					dataIndex: 'industry',
					key: 'industry',
				},
				{
					title: '社会性质',
					dataIndex: 'societyTag',
					key: 'societyTag',
					render: text => { return getSocialAttribute(text) }
				},
				{
					title: '创建时间',
					dataIndex: 'createTime',
					key: 'createTime',
				},{
					title: '所属人',
					dataIndex: 'adminName',
					key: 'adminName',
				},
				{
					title: '业务认证',
					dataIndex: 'businessAudit',
					key: 'businessAudit',
					render: text => { return getCertification(text) }
				},
				{
					title: '实名认证',
					dataIndex: 'auditStatus',
					key: 'auditStatus',
					render: text => { return getAuditStatus(text) }
				},
				{
					title: '是否专家',
					dataIndex: 'expert',
					key: 'expert',
					render: text => { return getWhether(text) }
				},
				{
					title: '是否会员',
					dataIndex: 'isMember',
					key: 'isMember',
					render: text => { return getWhether(text) }
				},
				{
					title: '是否国际',
					dataIndex: 'international',
					key: 'international',
					render: text => { return getWhether(text) }
				},
				{
					title: '会员等级',
					dataIndex: 'lvl',
					key: 'lvl',
					render: text => { return getLvl(text) }
				},
				{
					title: '会员状态',
					dataIndex: 'currentMemberStatus',
					key: 'currentMemberStatus',
					render: text => { return getCurrentMember(text) }
				},
				{
					title: '状态',
					dataIndex: 'status',
					key: 'status',
					render: text => { return getStatuslist(text) }
				}, {
                    title: '发布操作',
                    dataIndex: 'ee',
                    key: 'ee',
                    render: (text, record, index) => {
                    	return 
							{(!record.releaseStatus)?
{this.examineOK(record)}} okText="确认" cancelText="取消">
							                     
							:
							
{this.examineCancel(record)}} okText="确认" cancelText="取消">
							                     
							}
                        
                                  
                    专家发布审核
                
                                                               
                 
                				    
					     
						    
						        {adminData.isSuperAdmin?:
								
								}
							
						    
						        
						             
						        
						       
						    
						    
						    		
						    			{adminData.isSuperAdmin?
	:
						    			
						    			}