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 { 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 QueryCustomer = Form.create()(React.createClass({
	loadData(pageNo) {
		this.state.data = [];
		this.setState({
			loading: true
		});
		$.ajax({
			method: "post",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/customer/findEnteringAudit',
			data: {
				pageNo: pageNo || 1,
				pageSize: this.state.pagination.pageSize,
				name: this.state.nameSearch,//客户名称
				adminName:this.state.adminName,//营销员名称
			},
			success: function(data) {
				let theArr = [];
				let thisdata;
				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++) {
						thisdata = data.data.list[i];
						theArr.push({
							key: i,
							id: thisdata.uid,
							name: thisdata.name,
							createTime: thisdata.createTime,
							adminName: thisdata.adminName,
							contactMobile: thisdata.contactMobile,
						});
					};
					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: [],
			orgCodeUrl: [],
			companyLogoUrl: [],
			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 + '条数据';
				}
			},
			columns: [{
					title: '客户名称',
					dataIndex: 'name',
					key: 'name',
				}, {
					title: '联系电话',
					dataIndex: 'contactMobile',
					key: 'contactMobile',
				},
				{
					title: '营销员',
					dataIndex: 'adminName',
					key: 'adminName',
				},
				{
					title: '创建时间',
					dataIndex: 'createTime',
					key: 'createTime',
				}, {
                    title: '审核操作',
                    dataIndex: 'ee',
                    key: 'ee',
                    render: (text, record, index) => {
                    	return 
							{this.examineOK(record)}} okText="确认" cancelText="取消">
							                     
							
                         
					}
                }
			],
			dataSource: [],
		};
	},
	 //审核不通过
    examineCancel(record){
    	let api=2;
    	this.examine(api,record);
    },
	 //审核通过
    examineOK(record){
    	let api=1;
    	this.examine(api,record);
    },
    examine(api,record) {
        this.setState({
            selectedRowKeys: [],
        });
        $.ajax({
            method: "POST",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + '/api/admin/customer/updateEnteringAudit',
            data: {
                id:record.id,
                auditStatus:api,
                auditOpinion:this.state.auditOpinion,
             }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('操作成功');
                this.setState({
                    loading: false,
                });
            } else {
                message.warning(data.error[0].message);
            };
            this.loadData();
        }.bind(this));
    },
	componentWillMount() {
		this.loadData();
	},
	//审核实名认证不通过功能
	auditRows(e) {
		e.preventDefault();	
		$.ajax({
			url: globalConfig.context + '/api/admin/customer/updateEnteringAudit',
			method: 'post',
			data: {
				id:this.state.id,
                auditOpinion:this.state.auditOpinion,
                auditStatus:2,
			}
		}).done(function(data) {
			this.setState({
				loading: false
			});
			if(!data.error.length) {
				message.success('操作成功!');
				this.detailsModal()
				this.loadData();
			} else {
				message.warning(data.error[0].message);
			}
		}.bind(this));
	},
	//审核实名认证通过功能
	auditRowse(e) {
		e.preventDefault();	
		$.ajax({
			url: globalConfig.context + '/api/admin/customer/updateEnteringAudit',
			method: 'post',
			data: {
				id:this.state.id,
                auditOpinion:this.state.auditOpinion,
                auditStatus:1,
			}
		}).done(function(data) {
			this.setState({
				loading: false
			});
			if(!data.error.length) {
				message.success('操作成功!');
				this.detailsModal()
				this.loadData();
			} else {
				message.warning(data.error[0].message);
			}
		}.bind(this));
	},
	search() {
		this.loadData();
	},
	reset() {
		this.state.nameSearch = '';
		this.state.adminName=''
		this.loadData();
	},
	searchSwitch() {
		this.setState({
			searchMore: !this.state.searchMore
		});
	},
	//整行点击
	tableRowClick(record, index) {
		this.state.RowData = record;
		this.detailsModalOk(record);
		this.setState({
			name:record.name,
			id:record.id,
		})
	},
	detailsModalOk(e) {
		this.setState({ 
			modal5Visible: true 
		}); //需要一个请求数据
	},
	detailsModal(e){
		this.setState({ 
			modal5Visible: false 
		});
	},
	componentWillReceiveProps(nextProps) {
		if(!this.props.visible && nextProps.visible) {
			if(nextProps.data && nextProps.data.id) {
				this.loadData(nextProps.data.id, nextProps.detailApiUrl);
			};
			this.state.data = {};
			this.state.companyLogoUrl = [];
			this.state.orgCodeUrl = [];
			this.loadData(null);
		};
	},
	render() {
		const FormItem = Form.Item
		const rowSelection = {
			selectedRowKeys: this.state.selectedRowKeys,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({
					selectedRows: selectedRows.slice(-1),
					selectedRowKeys: selectedRowKeys.slice(-1)
				});
			},
			onSelect: (recordt, selected, selectedRows) => {
				this.setState({
					recordt: recordt.id
				})
			},
		};
		const rowSelections = {
			selectedRowKeys: this.state.selectedRowKey,
			onChange: (selectedRowKey, selectedRow) => {
				this.setState({
					selectedRow: selectedRow.slice(-1),
					selectedRowKey: selectedRowKey.slice(-1)
				});
			},
			onSelect: (records, selected, selectedRow) => {
				this.setState({
					selectedRow: selectedRow.slice(-1),
					records: records.id,
				})
			},
		};
		const hasSelected = this.state.selectedRowKeys.length > 0;
		const { RangePicker } = DatePicker;
		const { getFieldDecorator } = this.props.form;
		const formItemLayout = {
			labelCol: { span: 8 },
			wrapperCol: { span: 14 },
		};
		//const theDatak = this.state.datak || {};
		const theInformation = this.state.dataInformation || {}
		const contactsOption = "";
		const formItemLayput = {
			labelCol: { span: 10 },
			wrapperCol: { span: 14 },
		};
		const contacts = this.state.contacts || '';
		return(
			
		);
	}
}));
export default QueryCustomer;