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) {
		this.setState({
			loading: true,
		});
		$.ajax({
			method: "get",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + apiUrl,
			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 = {};
					return;
				};
				for(let i = 0; i < data.data.length; i++) {
					let thisdata = data.data[i];
					listArr.push({
						id: thisdata.id,
						businessProjectName: thisdata.businessProjectName,
						salesmanName: thisdata.salesmanName,
						lockTime: thisdata.lockTime && thisdata.lockTime.split(' ')[0],
					});
				};
				this.setState({
					dataSource: listArr,
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	getInitialState() {
		return {
			loading: false,
			dataSource: [],
			columns: [{
					title: '业务名称',
					dataIndex: 'businessProjectName',
					key: 'businessProjectName',
				}, {
					title: '签单时间',
					dataIndex: 'lockTime',
					key: 'lockTime',
				},
				{
					title: '营销员',
					dataIndex: 'salesmanName',
					key: 'salesmanName',
				}
			],
		}
	},
	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 size="middle" columns={this.state.columns}
                            dataSource={this.state.dataSource}    
                            pagination={false} 
                           />
                    </Spin>
			</Modal>
		)
	}
})
export default Detail;