import React from 'react';
import {
	Icon,
	Button,
	Input,
	Select,
	Spin,
	Checkbox,
	Cascader,
	Table,
	Form,
	Switch,
	message,
	DatePicker,
	Modal,
	Row,
	Col,
	InputNumber,
	notification
} from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
//import axios from 'axios';
import 'antd/dist/antd.css';
const FormItem = Form.Item;
import './sichuan.css';
const { TextArea } = Input;

class Achievement extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			loading:false,
			publishPages: [],
			visible: 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: 'serialNumber',
					key: 'serialNumber'
				},
				{
					title: '成果名称',
					dataIndex: 'name',
					key: 'name'
				},
				{
					title: '关键字',
					dataIndex: 'keyword',
					key: 'keyword'
				},
				{
					title: '行业领域',
					dataIndex: 'auditStatus',
					key: 'auditStatus'
				},
				{
					title: '企业名称',
					dataIndex: 'createTime',
					key: 'createTime'
				},
				{
					title: '拟对接单位',
					dataIndex: 'releaseDate',
					key: 'releaseDate'
				},
				{
					title: '成果状态',
					dataIndex: 'releaseDate1',
					key: 'releaseDate1'
				},
				{
					title: '操作',
					dataIndex: 'caozuo',
					key: 'caozuo',
					render: (text, recard) => {
						return (
							<div className="btnRight">
								<Button
									style={{ marginRight: 10 }}
									type="primary"
									onClick={this.tableRowClick.bind(this)}
								>
									修改
								</Button>
								<Button
									type="danger"
									onClick={(e) => {
										this.delectRow(recard);
									}}
								>
									删除
								</Button>
							</div>
						);
					}
				}
			]
		};
	}
	loadData(pageNo) {
		this.setState({
			page: pageNo,
			// loading: true
		});
//		axios.get('api/list',{
//			params:{
//				page:pageNo||1,
//				pageSize:10
//			}
//		})
//		.then(function(res) {
//			let theArr = [];
//              if (!data.data || !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,
//                          serialNumber: thisdata.serialNumber,
//                          name: thisdata.name,
//                          category:thisdata.category,
//                          fieldA:thisdata.thisdata,
//                          fieldB:thisdata.fieldB,
//                      });
//                  };
//              }
//              this.state.pagination.current = data.data.pageNo;
//              this.state.pagination.total = data.data.totalCount;
//              if(data.data&&data.data.list&&!data.data.list.length){
//					this.state.pagination.current=0
//					this.state.pagination.total=0
//				}
//              this.setState({
//					loading:false,
//                  dataSource: theArr,
//                  pagination: this.state.pagination
//              });
//		})
//		.catch(function(error) {
//			console.log(error);
//		});
	}
	//消息提示
	message(mess) {
		notification.open({
			message: '提示',
			description: mess,
			placement: 'bottomRight'
		});
	}
	//删除
	delectRow(recard) {
		this.setState({
			loading: true
		});
//		axios({
//			method:'get',
//			url:'api/sdas',
//			}).then(function(res) {
//				this.success('success');
//				this.setState({
//					loading: false
//				});
//			})
//			.catch(function(error) {
//				console.log(error);
//			});
	}
	details(recard){
		this.state({
			loading:true
		})
	}
	add() {
		this.setState({
			uid: '',
			visible: true,
			addState: true,
			name: '',
			introduce: '',
			industry: '',
			summary: '',
			ownerName: '',
			reserveButtMode: '',
			patentNumber: '',
			transferPrice: '',
			telephone: '',
			cname: ''
		});
	}
	search() {
		this.loadData(1);
	}
	reset() {
		this.state.nameSearch = '';
		this.state.keyword = '';
		this.loadData(1);
	}
	tableRowClick(record, index) {
		this.state.RowData = record;
		this.setState({
			visible: true,
			addState: false,
			uid: record.id
		});
		this.details(record)
	}
	handleOk() {
		this.handleSubmit();
	}
	handleCancel() {
		this.setState({
			visible: false
		});
	}
	handleSubmit() {
		if (!this.state.name || !this.state.introduce) {
			this.message('请填写带*项');
			return false;
		}
		this.setState({
			loading: true
		});
		let api = this.state.addState ? '/api/achievements' : '/api/update';
//		axios
//			.post(api, {
//				id: this.state.uid,
//				achievementDTO: {
//					name: this.state.name,
//					type: this.state.type,
//					industry: this.state.industry,
//					summary: this.state.summary,
//					introduce: this.state.introduce,
//					ownerName: this.state.ownerName,
//					reserveButtMode: this.state.reserveButtMode,
//					patentNumber: this.state.patentNumber,
//					transferPrice: this.state.transferPrice
//				},
//				publisherDTO: {
//					name: this.state.name,
//					telephone: this.state.telephone
//				}
//			})
//			.then(function(res) {
//				console.log(res);
//				this.message('success');
//				this.setState({
//					loading: false,
//					visible: false
//				});
//				this.loadData(1);
//			})
//			.catch(function(error) {
//				console.log(error);
//			});
	}
	componentWillMount() {
		this.loadData(1);
	}
	render() {
		const rowSelection = {
			selectedRowKeys: this.state.selectedRowKeys,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({
					selectedRows: selectedRows.slice(-1),
					selectedRowKeys: selectedRowKeys.slice(-1)
				});
			}
		};
		const formItemLayout = {
			labelCol: { span: 6 },
			wrapperCol: { span: 12 }
		};
		this.state.dataSource = [ { id: 212, key: 1, name: 'liting' }, { key: 2, name: 'YouXi' } ];
		return (
			<div className="user-content">
				<div className="content-title">
					<span className="title">我的科技成果</span>
					<div className="patent-addNew">
						<Button type="primary" onClick={this.add.bind(this)}>
							发布成果<Icon type="plus" />
						</Button>
					</div>
				</div>
				<div className="user-search">
					<Input
						placeholder="成果名称"
						value={this.state.name}
						className="searchInp"
						onChange={(e) => {
							this.setState({ name: e.target.value });
						}}
						style={{ width: 120 }}
					/>
					<Input
						placeholder="关键字"
						value={this.state.keyword}
						onChange={(e) => {
							this.setState({ keyword: e.target.value });
						}}
						style={{ width: 120 }}
					/>
					<Button type="primary" onClick={this.search.bind(this)} className="interval">
						搜索
					</Button>
					<Button onClick={this.reset.bind(this)} className="interval">
						重置
					</Button>
				</div>
				<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>
				<Modal
					title={this.state.addState ? '新建成果' : '查看成果'}
					visible={this.state.visible}
					width="900px"
					onOk={this.handleOk.bind(this)}
					onCancel={this.handleCancel.bind(this)}
					okText="保存"
					cancelText="取消"
				>
					<Form layout="horizontal" id="demand-form">
						<Spin spinning={this.state.loading}>
							<div className="clearfix">
								{!this.state.addState ? (
									<FormItem className="half-item" {...formItemLayout} label="成果编号">
										<span />
									</FormItem>
								) : (
									''
								)}
								<FormItem className="half-item" {...formItemLayout} label="专利编号">
									<Input
										placeholder="专利编号"
										value={this.state.patentNumber}
										onChange={(e) => {
											this.setState({ patentNumber: e.target.value });
										}}
									/>
								</FormItem>
								<FormItem
									className="half-item"
									{...formItemLayout}
									label={
										<span>
											<strong style={{ color: '#f00' }}>*</strong>成果名称
										</span>
									}
								>
									<Input
										placeholder="成果名称."
										value={this.state.name}
										onChange={(e) => {
											this.setState({ name: e.target.value });
										}}
									/>
								</FormItem>
								<FormItem className="half-item" {...formItemLayout} label="行业领域">
									<Select
										defaultValue={this.state.industry}
										onChange={(e) => {
											this.setState({ industry: e });
										}}
										placeholder="请选择"
									>
										<Select.Option value="0">先进制造与自动化</Select.Option>
										<Select.Option value="1">电子信息技术</Select.Option>
										<Select.Option value="2">新材料技术</Select.Option>
										<Select.Option value="3">生物与新药</Select.Option>
										<Select.Option value="4">资源与新环境</Select.Option>
										<Select.Option value="5">新能源</Select.Option>
									</Select>
								</FormItem>

								<FormItem className="half-item" {...formItemLayout} label="所有权人">
									<Input
										placeholder="所有权人"
										value={this.state.ownerName}
										onChange={(e) => {
											this.setState({ ownerName: e.target.value });
										}}
									/>
								</FormItem>
								<FormItem className="half-item" {...formItemLayout} label="项目负责人">
									<Input
										placeholder="项目负责人"
										value={this.state.cname}
										onChange={(e) => {
											this.setState({ cname: e.target.value });
										}}
									/>
								</FormItem>
								<FormItem className="half-item" {...formItemLayout} label="联系电话">
									<Input
										placeholder="联系电话"
										value={this.state.telephone}
										onChange={(e) => {
											this.setState({ telephone: e.target.value });
										}}
									/>
								</FormItem>
								<div className="clearfix">
									<FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="技术简称">
										<TextArea
											autosize={{ minRows: 4, maxRows: 10 }}
											placeholder="输入技术简称"
											value={this.state.summary}
											onChange={(e) => {
												this.setState({ summary: e.target.value });
											}}
										/>
									</FormItem>
									<FormItem
										labelCol={{ span: 3 }}
										wrapperCol={{ span: 18 }}
										label={
											<span>
												<strong style={{ color: '#f00' }}>*</strong>技术成果内容
											</span>
										}
										style={{ margin: '10px 0px' }}
									>
										<TextArea
											autosize={{ minRows: 4, maxRows: 10 }}
											placeholder="输入技术成果内容"
											value={this.state.introduce}
											onChange={(e) => {
												this.setState({ introduce: e.target.value });
											}}
										/>
									</FormItem>
								</div>
								<Row>
									<Col span={8} style={{ fontSize: 18 }}>
										技术成果企业情况
									</Col>
								</Row>
								<div className="clearfix">
									<FormItem
										className="half-item"
										{...formItemLayout}
										label={
											<span>
												<strong style={{ color: '#f00' }}>*</strong>企业名称
											</span>
										}
									>
										<Input
											placeholder="企业名称."
											value={this.state.cname}
											onChange={(e) => {
												this.setState({ cname: e.target.value });
											}}
										/>
									</FormItem>
									<FormItem className="half-item" {...formItemLayout} label="科技主管部门">
										<Input
											placeholder="科技主管部门."
											value={this.state.name}
											onChange={(e) => {
												this.setState({ name: e.target.value });
											}}
										/>
									</FormItem>
									<FormItem className="half-item" {...formItemLayout} label="单位性质">
										<Select
											defaultValue={this.state.name}
											onChange={(e) => {
												this.setState({ name: e });
											}}
											placeholder="请选择"
										>
											<Select.Option value="0">国家行政企业</Select.Option>
											<Select.Option value="1">公私合作企业</Select.Option>
											<Select.Option value="2">中外合资企业</Select.Option>
											<Select.Option value="3">社会组织机构</Select.Option>
											<Select.Option value="4">国际组织机构</Select.Option>
											<Select.Option value="5">外资企业</Select.Option>
											<Select.Option value="6">私营企业</Select.Option>
											<Select.Option value="7">集体企业</Select.Option>
											<Select.Option value="8">国防军事企业</Select.Option>
										</Select>
									</FormItem>
									<FormItem className="half-item" {...formItemLayout} label="企业特征">
										<Input
											placeholder="企业特征"
											value={this.state.name}
											onChange={(e) => {
												this.setState({ name: e.target.value });
											}}
										/>
									</FormItem>
									<FormItem className="half-item" {...formItemLayout} label="邮政编码">
										<Input
											placeholder="邮政编码"
											value={this.state.name}
											onChange={(e) => {
												this.setState({ name: e.target.value });
											}}
										/>
									</FormItem>
									<div className="clearfix">
										<FormItem className="half-item" {...formItemLayout} label="法定代表人">
											<Input
												placeholder="法定代表人"
												value={this.state.name}
												onChange={(e) => {
													this.setState({ name: e.target.value });
												}}
											/>
										</FormItem>
										<FormItem className="half-item" {...formItemLayout} label="电话">
											<Input
												placeholder="电话"
												value={this.state.name}
												onChange={(e) => {
													this.setState({ name: e.target.value });
												}}
											/>
										</FormItem>
										<FormItem className="half-item" {...formItemLayout} label="企业网址">
											<Input
												placeholder="企业网址"
												value={this.state.name}
												onChange={(e) => {
													this.setState({ name: e.target.value });
												}}
											/>
										</FormItem>
										<FormItem className="half-item" {...formItemLayout} label="E-Mail">
											<Input
												placeholder="E-Mail"
												value={this.state.name}
												onChange={(e) => {
													this.setState({ name: e.target.value });
												}}
											/>
										</FormItem>
									</div>
									<div className="clearfix">
										<FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="企业简介">
											<TextArea autosize={{ minRows: 4, maxRows: 10 }} placeholder="输入企业简介" />
										</FormItem>
									</div>
								</div>
							</div>
						</Spin>
					</Form>
				</Modal>
			</div>
		);
	}
}

export default Achievement;
