import React from 'react';
import { Icon, Table, Modal, message, Spin, Input, Select, Button, Form ,Upload,Popconfirm,DatePicker} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import '../userMangagement.less';
import {lvl} from '../../../dataDic.js';


const MyBillDetaile = Form.create()(React.createClass({
	getInitialState() {
		return {
			loading: false,
			visible: false,
		};
	},
	//查看基本详情基本信息
    loaduser(record){
    	if(record){
    	$.ajax({
            method: "post",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/role/rolePermission',
            data: {
              id: record.id
            },
            success: function (data) {
                let thisData = data.data;                
                if (!thisData) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                    thisData = {};
                };
                
                this.setState({
                	orderList:thisData[0],
					ids:record.id,
                });                  
            }.bind(this),
       }).always(function () {
            this.setState({            	
                loading: false
            });
        }.bind(this));  
       }
    },
    //保存确认流水
    handleSubmit(e){
    	e.preventDefault();
    	console.log(this.state.selTime)
        if(this.state.selTime==undefined){
        	message.warning('请选择财务流水时间');
        	return false;
        };
		this.props.form.validateFields((err, values) => {
			if(!err) {
				this.setState({
					loading: true
				});
				$.ajax({
					method: "POST",
					dataType: "json",
					crossDomain: false,
					url: globalConfig.context + 'api/baocun',
					data: {
						time:this.state.selTime
					}
				}).done(function(data) {
					this.setState({
						loading: false
					});
					if(!data.error.length) {
						message.success('已确认！');
						this.handleOk()
					} else {
						message.warning(data.error[0].message);
					}
				}.bind(this));
			}
		});
    },
    //时间选择
    selTime(e,index){
    	this.setState({
    		selectTime:e,
    		selTime:index
    	})
    },
    //作废流水
    toVoid(){
    	if(!this.props.datauser.id){
    		return false;
    	}
    	this.setState({
			loading: true
		});
		$.ajax({
			method: "POST",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + 'api/zuofei',
			data: {
				id:this.props.datauser.id
			}
		}).done(function(data) {
			this.setState({
				loading: false
			});
			if(!data.error.length) {
				message.success('已作废！');
				this.handleOk()
			} else {
				message.warning(data.error[0].message);
			}
		}.bind(this));
    },
	handleOk(e) {
		this.setState({
			visible: false,
		});
		this.props.closeDesc(false, true);
	},
	handleCancel(e) {
		this.setState({
			visible: false,
		});
		this.props.closeDesc(false);
	},
	componentWillMount() {
		
	},
	nextCancel() {
		this.setState({
			addnextVisible: false
		})
	},
	componentWillReceiveProps(nextProps) { //props改变时触发
		this.state.visible = nextProps.showDesc;
		if(nextProps.userDetaile && nextProps.showDesc ) {
			if(nextProps.datauser && nextProps.datauser.id ) {
				this.loaduser(nextProps.datauser);
			}
		}
	},
	render() {
		const FormItem = Form.Item
		const formItemLayout = {
			labelCol: { span: 8 },
			wrapperCol: { span: 14 },
		};
		const orderDetaiel=this.state.orderList || [];
		return(
			<div>
            <Modal maskClosable={false} visible={this.state.visible}
                    onOk={this.handleOk} onCancel={this.handleCancel}
                    width='1000px'
                    title='编辑订单'                     
                    footer=''
                    className="admin-desc-content">
		            <Form layout="horizontal" id="demand-form" style={{paddingBottom:'40px'}} onSubmit={this.handleSubmit}>
		                <Spin spinning={this.state.loading}>
	                        <div className="clearfix">
	                            <div className="clearfix">
		                       		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="平台流水号" >
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="平台流水时间" >  
			                            <span>{orderDetaiel.createTimez}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="流水金额" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="流水科目" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="流水状态" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="付款人名称" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="收款人名称" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="交易方式" >  
			                            <span>{orderDetaiel.rname}</span>
		                    		</FormItem>
		                    		<FormItem className="half-item"
			                            {...formItemLayout}
			                            label="交易渠道" >    
		                            	<span>{orderDetaiel.roleName}</span>
				                    </FormItem>
				                    <div className='clearfix'>
							        	<FormItem
								            labelCol={{ span: 4 }}
								            wrapperCol={{ span: 16 }}
								            label="附言" >
							        		<span>{orderDetaiel.roleName}</span>
								        </FormItem>
							        </div>
				                    <div className='clearfix'>
					                    <FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单编号" >   
				                            <span>{orderDetaiel.roleName}</span>
					                    </FormItem>
					               	</div>    
				                    <div className='clearfix'>
							        	<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="订单负责人" >   
				                            <span>{orderDetaiel.roleName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="下单时间" >   
				                            <span>{orderDetaiel.roleName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="财务负责人" >   
				                            <span>{orderDetaiel.roleName}</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="流水确认时间" >   
				                            <span>{orderDetaiel.roleName}</span>
			                    		</FormItem>
		                    		</div>
		                    		<div className='clearfix'>
				                        <FormItem className="half-item"
				                            {...formItemLayout}
				                            label="财务流水号" >   
				                            <Input value={this.state.timet}  style={{width:'240px'}} placeholder="请输入财务流水号"
				                                 onChange={(e)=>{this.setState({timet:e.target.value})}} required="required" />
									        <span className="mandatory">*</span>
			                    		</FormItem>
			                    		<FormItem className="half-item"
				                            {...formItemLayout}
				                            label="财务流水时间" >   
				                            <DatePicker
				                              style={{marginTop:'0',width:'200px',height:'32px'}}
										      showTime
										      format="YYYY-MM-DD HH:mm:ss"
										      placeholder="选择时间"
										      value={this.state.selectTime}
										      onChange={(e,time)=>{this.selTime(e,time)}}
										    />
									        <span className="mandatory">*</span>
			                    		</FormItem>
			                    	</div>
			                    	<div className='clearfix'>
			                    		<FormItem
								            labelCol={{ span: 4 }}
								            wrapperCol={{ span: 16 }}
								            label="财务备注" >
								                <Input type="textarea" placeholder="请输入财务备注" rows={4}  value={this.state.introduction} 
									    			onChange={(e)=>{this.setState({introduction:e.target.value})}}/>			                      
								        </FormItem>
								    </div> 
								    <div className='btnSave'>
							            <Button className="setSave" type="primary" htmlType="submit">确认流水</Button> 
							            <Button className="toVoid" type="danger" onClick={this.toVoid}>作废流水</Button> 
							        	<Button className="cancel" type="ghost" onClick={this.handleCancel}>返回</Button>
							        </div>
		                        </div>
		                    </div>
		                </Spin>
		            </Form >
		        </Modal>
    	    </div>
		)
	}
}));

export default MyBillDetaile;