import React from 'react';
import { Table,Spin, message,Modal } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';

const Detail =React.createClass({
	loadData(data,apiUrl) {
		console.log(data)
		this.setState({
			loading: true,
		});
		$.ajax({
			method: "get",
			dataType: "json",
			crossDomain: false,
			//url: globalConfig.context + apiUrl,
			url: globalConfig.context + '/api/admin/customer/toAddFollow',
			data: {
				uid: data.id,
			},
			success: function(data) {
				let listArr = [];
				let thedata = data.data;
				if(!thedata) {
					if(data.error && data.error.length) {
						message.warning(data.error[0].message);
					};
					thedata = {};
				};
				for(let i = 0; i < data.data.userBusinessList.length; i++) {
					let thisdata = data.data.userBusinessList[i];
					listArr.push({
						id: thisdata.id,
						businessName:thisdata.businessName,
						businessGlossoryId: String(thisdata.businessGlossoryId),
						followSituation: String(thisdata.followSituation),
						customerStatus: String(thisdata.customerStatus),
						remarks: thisdata.remarks,
					});
				};
				this.setState({
					dataSource: listArr,
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	getInitialState(){
		return{
			loading:false,
			dataSource:[],
			columns: [{
					title: '业务名称',
					dataIndex: 'businessName',
					key: 'businessName',
				}, {
					title: '项目名称',
					dataIndex: 'locationProvince',
					key: 'locationProvince',
				},{
					title: '签单时间',
					dataIndex: 'createTime',
					key: 'createTime',
				}, 
				{
					title: '客户名称',
					dataIndex: 'contacts',
					key: 'contacts',
				},
				{
					title: '营销员',
					dataIndex: 'contactst',
					key: 'contactst',
				}
			],
		}
	},
	visitCancel(){
		this.setState({
			visitModul:false
		})
		this.props.closeDesc(false)
	},
	componentWillReceiveProps(nextProps) {
		if(nextProps.visitModul){
			this.setState({
				visitModul:true
			})
			this.loadData(nextProps.data,nextProps.detailApi)
		}
	},
	render(){
		return(
			<Modal	
			      className="customeDetails"
			      footer=''
		          title="已签业务"
		          width='800px'
		          visible={this.state.visitModul}
		          onOk={this.visitCancel}
				  onCancel={this.visitCancel}							          							          
			        >		
                    <Spin spinning={this.state.loading}>
                        <Table columns={this.state.columns}
                            dataSource={this.state.dataSource}    
                            pagination={false} 
                           />
                    </Spin>
			</Modal>
		)
	}
})
export default Detail;
