import React from 'react';
import { Icon, Table, Modal, message, Spin, Input, Select, Button, Form ,Upload,Popconfirm,AutoComplete} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import '../userMangagement.less';
import {orderType} from '../../../../dataDic.js';
import {getOrderType,getProjectState,getTaskStatus,getOrderChannel,getOrderState,getPaymentState,getApprovedState} from '../../../../tools.js';

const MySettlementDetaile = Form.create()(React.createClass({
	getInitialState() {
		return {
			loading: false,
			visible: false,
            //派单
		};
	},
	//查看基本详情基本信息
    loaduser(record){
    	if(record){
	    	$.ajax({
	            method: "get",
				dataType: "json",
				crossDomain: false,
				url: globalConfig.context + '/api/admin/techproject/getProjectTaskDetail',
	            data: {
	              taskId: record.taskId
	            },
	            success: function (data) {
	                let thisData = data.data;                
	                if (!thisData) {
	                    if (data.error && data.error.length) {
	                        message.warning(data.error[0].message);
	                    };
	                    thisData = {};
	                };
	                this.setState({
	                	orderNo:thisData.orderNo,
						orderList:thisData
	                });                  
	            }.bind(this),
	       }).always(function () {
	            this.setState({            	
	                loading: false
	            });
	        }.bind(this));  
	    }
    },
    //查看订单
	seeOrder(){
		this.setState({
			seeOrderVisible:true
		})
		this.seeOrderList();
	},
	seeOrderCancel(){
		this.setState({
			seeOrderVisible:false
		})	
	},
	seeOrderList(){
		this.state.lookOrderList=[];
    	$.ajax({
            method: "get",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/order/getServiceOrderDetail',
            data: {
              orderNo: this.state.orderNo
            },
            success: function (data) {
                let thisData = data.data;                
                if (!thisData) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                    thisData = {};
                };
                this.setState({
					id:thisData.id,
					lookOrderList:thisData,
                });
            }.bind(this),
       }).always(function () {
            this.setState({            	
                loading: false
            });
        }.bind(this));  
	},
	componentWillMount() {
		
	},
	componentWillReceiveProps(nextProps) { //props改变时触发
		this.state.visible = nextProps.showDesc;
		if(nextProps.showDesc) {
				this.loaduser(nextProps.datauser);
		}
	},
	handleCancel(){
		this.setState({
			visible:false
		})
	},
	render() {
		const FormItem = Form.Item
		const formItemLayout = {
			labelCol: { span: 8 },
			wrapperCol: { span: 14 },
		};
		const seeOrderDetaiel=this.state.lookOrderList || [];
		const orderDetaiel=this.state.orderList || [];
		return(
			<div>
            <Modal maskClosable={false} visible={this.state.visible}
                    onOk={this.handleCancel} onCancel={this.handleCancel}
                    width='1000px'
                    title='查看任务'                   
                    footer=''
                    className="admin-desc-content">
		            <Form layout="horizontal" id="demand-form" style={{paddingBottom:'40px'}} >
		                <Spin spinning={this.state.loading}>
		                    <div className="clearfix">
		                   			 <FormItem className="half-item"
				                            {...formItemLayout}
				                            label="客户名称" >
			                    			<span>{orderDetaiel.buyerName}</span>
			                    	</FormItem>
			                    	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单编号" >
			                    			<span>{orderDetaiel.orderNo}</span>
				                        {/*<Button style={{float:'right'}} onClick={this.seeOrder}>查看订单</Button>*/}
			                    	</FormItem>
		                        	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="项目编号" >
			                    			<span>{orderDetaiel.projectNo}</span>
			                    	</FormItem>
			                    	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="任务编号" >
			                    			<span>{orderDetaiel.taskNo}</span>
			                    	</FormItem>
			                    	
			                    	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="服务项目名称" >
			                    			<span>{orderDetaiel.commodityName}</span>
			                    	</FormItem>
			                    	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="任务状态" >
					                    	<span>{getTaskStatus(orderDetaiel.taskStatus)}</span>
			                    	</FormItem>
			                    	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="是否锁定" >
					                    	<span>{orderDetaiel.deletedSign==2?'锁定':'未锁定'}</span>
			                    	</FormItem>
			                    	<div className='clearfix'>
								        <FormItem className="half-item"
				                            {...formItemLayout}
				                            label="任务说明" >
					                    	<span>{orderDetaiel.taskComment}</span>
				                    	</FormItem>
							        </div>
							        <div className='clearfix'>
							        	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="派单人" >
					                    	<span>{orderDetaiel.taskAllocatorName}</span>
				                    	</FormItem>
				                    	<FormItem className="half-item"
					                            {...formItemLayout}
					                            label="派单时间" >
						                    	<span>{orderDetaiel.taskDistributionTime}</span>
				                    	</FormItem>
				                    	<FormItem className="half-item"
					                            {...formItemLayout}
					                            label="资料负责人" >
						                    	<span>{orderDetaiel.taskReceiverName}</span>
				                    	</FormItem>
							        </div>
		                        </div>
		                </Spin>
		            </Form >
		        </Modal>
		        <Modal maskClosable={false} visible={this.state.seeOrderVisible}
                        onOk={this.seeOrderCancel} onCancel={this.seeOrderCancel}
                        width='1000px'
                        title= '查看订单'                 
                        footer=''
                        className="admin-desc-content">
			            <Form layout="horizontal" id="demand-form">
			                <Spin spinning={this.state.loading}>
		                        <div className="clearfix">
	                        	  	<div className="clearfix">
			                       		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单编号" >
				                            <span>{seeOrderDetaiel.orderNo}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="下单时间" >  
				                            <span>{seeOrderDetaiel.createTime}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="客户名称" >  
				                            <span>{seeOrderDetaiel.buyerName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单类型" >  
				                            <span>{getOrderType(seeOrderDetaiel.orderType)}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单渠道" >  
				                            <span>{getOrderChannel(seeOrderDetaiel.orderChannel)}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单状态" >  
				                            <span>{getOrderState(seeOrderDetaiel.orderStatus)}</span>
			                    		</FormItem>
					                    <div className='clearfix'>
				                    		<FormItem className="half-item"
					                            {...formItemLayout}
					                            label="特批立项" >   
					                            <span>{getApprovedState(seeOrderDetaiel.approval)}</span>
				                    		</FormItem>
					                        <div className='clearfix'>
									        	<FormItem
										            labelCol={{ span: 4 }}
										            wrapperCol={{ span: 16 }}
										            label="订单留言" >
									        		<span>{seeOrderDetaiel.orderRemarks}</span>
										        </FormItem>
									        </div>
								        </div>
			                        </div>
			                        <div className='clearfix'>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单负责人" >  
				                            <span>{seeOrderDetaiel.salesmanName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="意向时间" >  
				                            <span>{seeOrderDetaiel.createTime}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="签单时间" >  
				                            <span>{seeOrderDetaiel.signTime}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="财务负责人" >  
				                            <span>{seeOrderDetaiel.financeName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="项目负责人" >  
				                            <span>{seeOrderDetaiel.technicianName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="立项时间" >  
				                            <span>{seeOrderDetaiel.setUpTime}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="项目状态" >  
				                            <span>{getProjectState(seeOrderDetaiel.projectStage)}</span>
						                </FormItem>
		                    		</div>
		                        </div>
			                </Spin>
			            </Form >
			        </Modal>
    	    </div>
		)
	}
}));

export default MySettlementDetaile;