import { Button,InputNumber,message } from 'antd'
import React, { Component } from 'react'
import axios from 'axios'
import HistoryRecord from '../../components/HistoryRecord'
import { connect } from 'react-redux';
import { historyRecordSync } from '../../redux/historyRecord_reducer';
class SyncContext extends Component {
    state={size:1}
    eidtSyncContextSize=(event)=>{
        this.setState({size:event})
    }
    historySync=(data)=>{
        console.info("historySync(data)",data)
		this.props.historyRecordSync(data)
	}
    syncContext = () => {
        const key = 'SYNC_CONTEXT';
        message.loading({content:'Loading...',key,duration:0});
        axios.get(`/ticai/sync/context/${this.state.size}`)
            .then(response => {
                const result = response.data;
                if (result.status.code === 200) {
                    console.log(result.data.length)
                    message.destroy(key)
                    message.success({
                        content: "成功同步"+result.data.length+"条",
                        duration: 2,
                      })
                      this.historySync(result.data)
                } else {
                    message.destroy(key)
                    message.error(result.status.message)
                }
            })
            .catch(function (error) {
                message.destroy(key)
                message.error(error)
            })
    }
    render() {
        return (
            <div>
                <span>同步最近</span><InputNumber min={1} max={10000} defaultValue={this.state.size} onChange={this.eidtSyncContextSize}/>条数据,
                <Button onClick={this.syncContext}>确认</Button>.
                <hr/>
                <HistoryRecord/>
            </div>
        )
    }
}

export default connect(
    null,
	// state => ({
	// }),//映射状态
	{historyRecordSync}//映射操作状态的方法
)(SyncContext)
