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 QueryCustomer from './myRejectOne.jsx';
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 PublicCustomer = 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/findEnteringAuditIsNo',
			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,
							auditOpinion:thisdata.auditOpinion,
						});
					};
					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: 'auditOpinion',
					key: 'auditOpinion',
				}
			],
			dataSource: [],
		};
	},
	 //审核通过
    examineCancel(record){
    	let api=0;
    	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(
			<div className="user-content" >
                <div className="content-title">                  
                    <span>我的被拒绝客户</span>
                </div>
                <div className="user-search">                    
                    <Input placeholder="客户名称"
                        value={this.state.nameSearch}
                        onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />    
                    <Input placeholder="营销员"
                        value={this.state.adminName}
                        onChange={(e) => { this.setState({ adminName: e.target.value }); }} /> 
                    <Button type="primary" onClick={this.search}>搜索</Button>
                    <Button onClick={this.reset}>重置</Button>                                         				
				</div>                                               
                <div className="patent-table">
                    <Spin spinning={this.state.loading}>
                        <Table columns={this.state.columns}
                            dataSource={this.state.dataSource}    
                            rowSelection={rowSelection}
                            pagination={this.state.pagination} 
                            onRowClick={this.tableRowClick}
                           />
                    </Spin>
                </div> 
                <Modal	
				      className="customeDetails"				      
			          title="单位客户资料审核"
			          width='500px'
			          visible={this.state.modal5Visible}
			          onOk={this.detailsModal}
			          onCancel={this.detailsModal}
			          footer=''
			        >				    
					<Form horizontal onSubmit={this.auditRows} id="add-form">
		                <Spin spinning={this.state.loading}>
		                    <div className="clearfix">
		                    	<FormItem 
			                            labelCol={{ span: 6 }}
			                        	wrapperCol={{ span: 15 }}
			                            label="客户名称" >
		                                <span>{this.state.name}</span>
			                    </FormItem>
		                    </div>
		                    <div className="clearfix">
	                   		    <FormItem
			                        labelCol={{ span: 6 }}
			                        wrapperCol={{ span: 15 }}
			                        label="审核意见" >					                        
			                        <Input type="textarea" rows={4} placeholder="审核意见" value={this.state.auditOpinion}
                       				 	onChange={(e) => { this.setState({ auditOpinion: e.target.value }) }} style={{width:'95%'}}/>					                           
			                    </FormItem>
			                </div>    
		                    <FormItem wrapperCol={{ span: 25, offset: 4 }}>
		                        <Button className="set-submit" type="primary" onClick={this.auditRowse}>审核通过</Button> 
		                        <Button className="set-submit" type="primary" htmlType="submit" style={{marginLeft:'30px'}}>审核不通过</Button>  
		                        <Button className="set-submit" type="ghost" onClick={this.detailsModal} style={{marginLeft:'30px'}}>取消</Button>
		                    </FormItem> 
		                </Spin>
		            </Form >                          
				</Modal>
          </div >
		);
	}
}));

//const Tablees=Form.create()(React.createClass({
//	//详情tab切换数据处理
//	callbacks(e) {
//		this.setState({
//			callnubs: e,
//		})
//		if(e == '1') {
//			
//		}
//		if(e == '2') {
//			
//		}
//		
//	},
//	getInitialState() {
//		return {
//			callnubs: "1",
//		}
//	},
//	render() {
//		return(
//			<div className="clearfix" style={{marginTop:'0px',marginLeft:'20px'}}>
//			    <Tabs onChange={this.callbacks} type="card" activeKey={this.state.callnubs} style={{paddingLeft:'15px',paddingRight:'15px',marginRight:'20px'}}>
//			         <TabPane tab="个人客户" key="1" >
//			         	<QueryCustomer />
//			         </TabPane>
//					 <TabPane tab="单位客户" key="2">
//					 	<PublicCustomer />
//					 </TabPane>
//			    </Tabs>
//			</div>
//		);
//	}
//}));
export default PublicCustomer;




