import React from 'react';
import { AutoComplete, Icon, Button, Input, InputNumber, Select, Spin, Table, message, Modal, Row, Col, DatePicker,Switch,Upload} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import './myClient.less';
import { orderStatusList,cityArr,customerStatus,intentionalService,newFollow} from '../../dataDic.js';
import { beforeUploadFile,getOrderStatus, getSearchUrl,getcustomerTyp,getcityArr,getcustomerStatue,getCompanyIntention,getfllowSituation,getsex} from '../../tools.js';



//查询功能和初始列表
const Teamcustomer = React.createClass({
     loadData(pageNo, detailApiUrl) {    	
        this.state.data = [];
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,          
            url:globalConfig.context +'/api/admin/customer/listTeamCustomer',
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,               
                companyName: this.state.companyNamet, //名称1                
				customerType: this.state.customerTypet, //客户类型1
              	locationProvince:this.state.locationProvincet,//地区
				customerStatus:this.state.customerStatust,//客户状态1
				contactName:this.state.contactNamet,//联系人姓名1							
				contactTel:this.state.contactTelt,//联系人手机
				companyIntention:this.state.companyIntentiont,//意向服务
                followSituation:this.state.followSituationt,//最新跟进进度
				//releaseDateStartDate: this.state.releaseDate[0],
                //releaseDateEndDate: this.state.releaseDate[1],			
            },
            success: function (data) {            	
                let theArr = [];
                if (!data.data || !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.id,                                                  
                            companyName:thisdata.companyName,//公司名称
                            customerType:thisdata.customerType,
                            _customerType:thisdata._customerType,//客户类型
                            locationProvince:thisdata.locationProvince,//地区                        
                            contactName:thisdata.contactName, //联系人姓名
                            telNum:thisdata.telNum,//手机号
                            _customerStatus:thisdata._customerStatus,//客户状态
                            _companyIntention:thisdata._companyIntention,//意向服务
                            _followSituation:thisdata._followSituation,//最新跟进
                            customerStatus:thisdata.customerStatus,//客户状态
                            companyIntention:thisdata.companyIntention,//意向服务
                            followSituation:thisdata.followSituation,//最新跟进
                            adminName:thisdata.adminName,     //跟进人          
                            followDate:thisdata.followDate,
                            customerStatus:thisdata.customerStatus,//客户状态
                            companyIntention:thisdata.companyIntention,//意向服务                                                      
                        });
                    };
                   
                    this.state.pagination.current = data.data.pageNo;
                    this.state.pagination.total = data.data.totalCount;
                };               
                this.setState({
                    dataSource: theArr,
                    pagination: this.state.pagination
                });             
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },    
    getInitialState() {
        return {
            searchMore: true,
            searchType: 0,
            validityPeriodDate: [],
            releaseDate: [],
            selectedRowKeys: [],
            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: 'companyName',
                    key: 'companyName',
                }, {
                    title: '客户类型',
                    dataIndex: '_customerType',
                    key: '_customerType',
                    //render: text => { return getcustomerTyp(text); }
                }, {
                    title: '地区',
                    dataIndex: 'locationProvince',
                    key: 'locationProvince',
                    render: text => { return getcityArr(text); }
                }, {
                    title: '联系人姓名',
                    dataIndex: 'contactName',
                    key: 'contactName',                    
                }, 
                {
                    title: '手机号',
                    dataIndex: 'telNum',
                    key:'telNum',                   
                },
                 {
                    title: '客户状态',
                    dataIndex: '_customerStatus',
                    key: '_customerStatus',
                  //render: text => { return getcustomerStatue(text) }
                },
                {
                    title: '意向服务',
                    dataIndex: '_companyIntention',
                    key: '_companyIntention',
                    //render: text => { return getCompanyIntention(text) }
                },
                 {
                    title: '最新跟进',
                    dataIndex: '_followSituation',
                    key: '_followSituation',
                    //render: text => { return getfllowSituation(text) }
                },
                 {
                    title: '跟单人',
                    dataIndex: 'adminName',
                    key: 'adminName',
                },
                {
                    title: '时间',
                    dataIndex: 'followDate',
                    key: 'followDate',
                }
            ],
            dataSource: [],
            searchTime: [],
        };
    },
    componentWillMount() {
        let theArr = [];
        customerStatus.map(function (item) {
            theArr.push(
                <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
            )
        });            
               
        let intentionalArr = [];
        intentionalService.map(function (item) {
            intentionalArr.push(
                <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
            )
        });   
        let newArr = [];
        newFollow.map(function (item) {
            newArr.push(
                <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
            )
        });   
				let auditArr = [];
        cityArr.map(function (item) {
            auditArr.push(
                <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
            )
        }); 
        this.state.customerStatuarr = theArr;               
        this.state.intentionalOption = intentionalArr;
        this.state.newOption = newArr;
        this.state.auditStatusOption = auditArr;
        
        if (window.location.search) {
            let theObj = getSearchUrl(window.location.search);
            if (theObj.rid) {
                theObj.id = theObj.rid;
                if (theObj.rid != 'null') {
                    this.tableRowClick(theObj);
                };
            };
        };       
        this.loadData();        
    },    
    closeDesc(e, s) {
        this.state.showDesc = e;
        if (s) {
            this.loadData();
        };
    },
    search() {
        this.loadData();
    },
    reset() {
      	this.state.customerTypet=undefined;
      	this.state.companyNamet='';   
        this.state.id = undefined;
        this.state.shareTypet = undefined;
        this.state.companyIntentiont  = undefined;
        this.state.followSituationt  = undefined;
        this.state.locationProvincet  = undefined;
        this.state.customerStatust = undefined;
        this.state.contactNamet   = undefined;
        this.state.contactTelt = undefined;
        this.state.contactNamet = undefined;  
        this.state.releaseDatet = [];
        this.loadData(); 
    },
    searchSwitch() {
        this.setState({
            searchMore: !this.state.searchMore
        });
    },
    render() {
    	  const theData = this.state.data || {}; 
        const rowSelection = {
            selectedRowKeys: this.state.selectedRowKeys,
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState({
                    selectedRows: selectedRows.slice(-1),
                    selectedRowKeys: selectedRowKeys.slice(-1)
                });
            }
        };
        const hasSelected = this.state.selectedRowKeys.length > 0;
        const { RangePicker } = DatePicker;
        return (
            <div className="user-content" >
                <div className="content-title">                  
                    <span>公共客户管理</span>                  
                </div>
                <div className="user-search">                    
                    <Input placeholder="公司名称"
                        value={this.state.companyNamet}
                        onChange={(e) => { this.setState({ companyNamet: e.target.value }); }} /> 
                    <Select placeholder="客户类型" style={{ width: 120 }}
                            value={this.state.customerTypet }
                            onChange={(e) => { this.setState({ customerTypet : e }) }}>
                            <Select.Option value="0" >个人客户</Select.Option>
                            <Select.Option value="1" >公司客户</Select.Option>
                            <Select.Option value="2" >团体单位</Select.Option>
                    </Select>                        
                    <Select placeholder="地区"
                            style={{ width: 160 }}
                            value={this.state.locationProvincet}
                            onChange={(e) => { this.setState({ locationProvincet: e }) }}>
                            {this.state.auditStatusOption}
                    </Select>                   
                    <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}
                           />
                    </Spin>
                </div>                           
            </div >
        );
    }
});
export default Teamcustomer;
