import React, { Component, useState, useEffect, useRef } from 'react';
import { Card, Row, Col, Statistic, Icon, Tabs, Form, Select, Button, Modal } from 'antd';
// import IndexEcharts from './components/indexEcharts';
// import Swiper from './swiper/index';
import moment from 'moment';
import router from 'umi/router';
import request from '@/utils/request';
import apis from '@/services/apis';
import TimeSelect from '../compents/TimeSelect';
import BuildingSelect from '@/components/SelectButton/BuildSelect';
import Navigate from '@/components/Navigate';
import NewUsers from './compents/NewUsers';
import OverviewDeatil from './compents/OverviewDeatil';

const activityOverView = props => {
  const timeRef = useRef();

  const [data, setData] = useState({});
  const [serachData, setSearchData] = useState({
    startDate:
      moment()
        .subtract(7, 'day')
        .format('YYYY-MM-DDT00:00:00.000') + 'Z',
    endDate: moment().format('YYYY-MM-DDT23:59:59.999') + 'Z',
    ...props.location.query,
  });
  const [timeValue, setTimeValue] = useState();

  const [time, setTime] = useState();

  //重置搜索
  const handleReset = e => {
    props.form.resetFields();
    timeRef.current.reset();
    setSearchData({
      startDate:
        moment()
          .subtract(7, 'day')
          .format('YYYY-MM-DDT00:00:00.000') + 'Z',
      endDate: moment().format('YYYY-MM-DDT23:59:59.999') + 'Z',
    });
  };

  const onTimeChange = e => {
    setTime(e);
  };
  const handleSubmit = e => {
    props.form.validateFieldsAndScroll((err, values) => {
      setTimeValue();
      setSearchData({
        ...values,
        startDate: moment(time[0]).format('YYYY-MM-DDT00:00:00.000') + 'Z',
        endDate: moment(time[1]).format('YYYY-MM-DDT23:59:59.999') + 'Z',
      });
    });
  };

  const { getFieldDecorator } = props.form;

  return (
    <div>
      <Form layout="inline" onSubmit={handleSubmit}>
        <Form.Item>
          <TimeSelect onChange={onTimeChange} ref={timeRef}></TimeSelect>
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType="submit" style={{ marginLeft: '30px' }}>
            搜索
          </Button>
          <Button onClick={e => handleReset()} style={{ marginLeft: '30px' }}>
            重置
          </Button>
        </Form.Item>
      </Form>

      <div style={{ marginTop: '20px' }}>
        <NewUsers params={serachData} dataZoom={false}></NewUsers>
      </div>
      <div style={{ marginTop: '20px' }}>
        <OverviewDeatil params={serachData}></OverviewDeatil>
      </div>
    </div>
  );
};

const WrappedTypeForm = Form.create()(activityOverView);
export default WrappedTypeForm;
