import React from 'react';
import { Radio, Icon, Button, AutoComplete,Cascader,Input, Select, Spin, Popconfirm, Table, Switch, message,Calendar , DatePicker, Upload, Form ,Modal,Tabs,Card ,Col} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import Jquery from 'jquery/dist/jquery.js';
import moment from 'moment';
import {boutique } from '@/dataDic.js';
import { getLiquidationStatus,getApprovedState,getProcessStatus,splitUrl,getjiedian,getboutique,getNewOrderStatus,getProjectStatus,getTaskStatus} from '@/tools.js';
const TabPane = Tabs.TabPane;
const Dragger = Upload.Dragger;
//图片组件
const PicturesWall = React.createClass({
	getInitialState() {
		return {
			previewVisible: false,
			previewImage: '',
			fileList: [],
		}
	},
	handleCancel() {
		this.setState({
			previewVisible: false
		})
	},
	handlePreview(file) {
		this.setState({
			previewImage: file.url || file.thumbUrl,
			previewVisible: true,
		});
	},
	handleChange(info) {
		let fileList = info.fileList;
		this.setState({
			fileList
		});
		this.props.fileList(fileList);
	},
	componentWillReceiveProps(nextProps) {
		this.state.fileList = nextProps.pictureUrl;
		this.state.pojectApplicationUrl = undefined;
	},
	render() {
		const {
			previewVisible,
			previewImage,
			fileList
		} = this.state;
		const uploadButton = (
			<div>
                <Icon type="plus" />
                <div className="ant-upload-text">点击上传</div>
            </div>
		);
		return(
			<div style={{display:"inline-block"}}>
                <Upload
                    action={globalConfig.context + "/api/admin/customer/uploadCustomerImg"}
                    data={{ 'sign': '' }}
                    listType="picture-card"
                    fileList={fileList}
                    onPreview={this.handlePreview}
                    onChange={this.handleChange} >
                    {fileList.length >= 1 ? null : uploadButton}
                </Upload>
                <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
                    <img alt="example" style={{ width: '100%' }} src={previewImage} />
                </Modal>
            </div>
		);
	}
});


const IntentionCustomer = Form.create()(React.createClass({
	loadData(pageNo, apiUrl) {
		this.setState({
			visitModul:false,
			loading: true,
			ispage:pageNo,
			modalVisible:false
		});
		$.ajax({
			method: "get",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context +"/api/admin/orderProject/taskHoursList",
			data: {
				pageNo: pageNo || 1,
				pageSize: this.state.pagination.pageSize,
				name: this.state.customerName,//名称
				taskId: this.state.orderNo,//订单编号
				starTime: this.state.releaseDate[0],//开始时间
				endTime: this.state.releaseDate[1],//结束时间
			},
			success: function(data) {
				let theArr = [];
				if(data.error.length || 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,//ID
							 orderNo: thisdata.orderNo,//订单编号
	                         taskName:thisdata.taskName,//任务名称
	                         userName:thisdata.userName,//客户名称
	                         cname:thisdata.cname,//项目品类
	                         taskStatus:thisdata.taskStatus,//任务状态
	                         receiverName:thisdata.receiverName,//负责人
	                         hours:thisdata.hours,//任务工时
	                         depName:thisdata.depName,//派单公司
							 contractNo:thisdata.contractNo,
							 signTime:thisdata.signTime,
							 creteTime:thisdata.creteTime
						});
					};
				    this.state.pagination.total = data.data.totalCount;
				};
				if(data.data&&data.data.list&&!data.data.list.length){
					this.state.pagination.total=0
				}
				this.setState({
					dataSource: theArr,
					pageNo: pageNo,
					pagination: this.state.pagination,
					selectedRowKeys:[]
				});
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	
	getInitialState() {
		return {
			page:1,
			releaseDate: [],
			selectedRowKeys: [],
			orgCodeUrl:[],
			paginations: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: 'id',
                    key: 'id'
                },{
                    title: '任务名称',
                    dataIndex: 'taskName',
                    key: 'taskName'
                },{
                    title: '订单编号',
                    dataIndex: 'orderNo',
                    key: 'orderNo'
                }, {
                    title: '业务类别',
                    dataIndex: 'cname',
                    key: 'cname'
                },{
                    title: '客户名称',
                    dataIndex: 'userName',
                    key: 'userName',
                    render:(text)=>{
                    	return (text&&text.length>9?text.substr(0,9)+'...':text)
                    }
                },{
                    title: '任务负责人',
                    dataIndex: 'receiverName',
                    key: 'receiverName'
                },{
                    title: '派单公司',
                    dataIndex: 'depName',
                    key: 'depName'
                },{
                    title: '任务状态',
                    dataIndex: 'taskStatus',
                    key: 'taskStatus',
                    render:text=>{return getTaskStatus(text)}
                }, {
                    title: '工时',
                    dataIndex: 'hours',
                    key: 'hours'
                }, {
					title: '合同编号',
					dataIndex: 'contractNo',
					key: 'contractNo'
				}, {
					title: '签单日期',
					dataIndex: 'signTime',
					key: 'signTime'
				}, {
					title: '派单日期',
					dataIndex: 'creteTime',
					key: 'creteTime'
				},  
			],
			data: [],
			dataSource: [],
			columnsX: [
				{
                    title: '催款人',
                    dataIndex: 'dumBy',
                    key: 'dumBy'
                }, {
                    title: '催款时间',
                    dataIndex: 'dumTime',
                    key: 'dumTime',
                    
                },{
                    title: '催款情况',
                    dataIndex: 'remarks',
                    key: 'remarks'
                }
			],
			dataSources: [],
			
		}
	},
	
	//页面加载函数
	componentWillMount() {
		this.loadData();
	},
//	//整行点击
	tableRowClick(record, index) {
		this.setState({
			visibles:true,
		});
		this.loadDatas(record.id);
	},	
	
    
	
	
	
	
	//关闭输入理由框
	noCancel(){
		this.setState({
			noVisible:false
		})
	},
	//搜索
	search() {
    	this.setState({
    		//signBillVisible:false
    	})
        this.loadData();
    },
    //重置
    reset() {
    	this.setState({
    		signBillVisible:false
    	})
    	this.state.orderNo='';
    	this.state.customerName='';
    	this.state.releaseDate[0] = undefined;
		this.state.releaseDate[1] = undefined;
        this.loadData(this.state.page);       
    },
    resets(){
    	this.state.orderNo='';
    	this.state.customerName='';
    	this.state.releaseDate[0] = undefined;
		this.state.releaseDate[1] = undefined;
    },
	getOrgCodeUrl(e) {
        this.setState({ orgCodeUrl: e });
    },
	//关闭详情
	visitCancel(e){
		this.setState({
			visible:false
		})
		this.resets();
	},
	visitOk(e){
		this.setState({
			visible:false
		})
		this.resets();
	},
	//关闭详情
	visitCancels(e){
		this.setState({
			visibles:false
		})
		this.resets();
	},
	//导出
    exportExec(){
        var data = {
            name: this.state.customerName?this.state.customerName:undefined,//订单负责人
            taskId: this.state.orderNo?this.state.orderNo:undefined,//订单编号
            starTime: this.state.releaseDate[0]?this.state.releaseDate[0]:undefined,
            endTime: this.state.releaseDate[1]?this.state.releaseDate[1]:undefined,
        }
        window.location.href=(globalConfig.context+'/api/admin/orderProject/exportTaskHoursListData?'+$.param(data));
    },
	visitOks(e){
		this.setState({
			visibles:false
		})
		this.resets();
	},
	render() {
		const formItemLayout = {
			labelCol: { span: 8 },
			wrapperCol: { span: 14 },
		};
		const FormItem = Form.Item;
		const { RangePicker } = DatePicker;
		const rowSelection = {
			selectedRowKeys: this.state.selectedRowKeys,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({
					modalVisible:false,
					selectedRows: selectedRows.slice(-1),
					selectedRowKeys: selectedRowKeys.slice(-1)
				});
			},
			onSelect: (recordt, selected, selectedRows) => {
				this.setState({
					modalVisible:false,
					recordt: recordt.id
				})
			},
		};
		const hasSelected = this.state.selectedRowKeys.length > 0;
		return(
			<div className="user-content">
				<div className="content-title">                  
                    <span>工时数据统计</span>
                </div>
               	<div className="user-search">             
               		<Button type="primary" onClick={this.exportExec} style={{float:'right'}}>导出工时数据</Button>
                   <Input placeholder="客户名称" style={{width:'150px',marginBottom:'10px'}}
	                        value={this.state.customerName}
	                        onChange={(e) => { this.setState({ customerName: e.target.value }); }} />
                    <Input placeholder="任务编号" style={{width:'150px'}}
                        value={this.state.orderNo}
                        onChange={(e) => { this.setState({ orderNo: e.target.value }); }} />
                    <span style={{marginRight:"10px"}}>合同签订时间 :</span>
                    <RangePicker
                        value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
                        this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
                        onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
                    <Button type="primary" onClick={this.search} style={{marginLeft:'10px'}}>搜索</Button>
                    <Button onClick={this.reset}>重置</Button> 
                   	<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>  
            </div>
			);
	}
}));
export default IntentionCustomer;






