import React, { Component, useState, useEffect } from 'react';
import echarts from 'echarts/lib/echarts';
import EChart from '@/components/EchartsTest/EChart';
import request from '@/utils/request';
import apis from '@/services/apis';
import moment from 'moment';
import router from 'umi/router';
import { Table, Select, Row, Col, Menu, Dropdown, Button, Icon, message } from 'antd';

// import styles from '../styles.less'
const formatDate = (start, end) => {
  const startDate = moment(start).format('YYYY-MM-DDT00:00:00.000') + 'Z'
  const endDate = moment(end).format('YYYY-MM-DDT23:59:59.999') + 'Z'
  return { startDate, endDate }
}
const NewUsers = (props) => {
  const [data, setData] = useState({ records: [] })


  useEffect(() => {
    NewsUserCount(formatDate(props.startDate, props.endDate))
  }, [props.startDate, props.endDate])


  function NewsUserCount (params) {
    request({
      ...apis.indexEcharts.changeNewUser,
      params,
    }).then((data) => {
      setData(data)
    })
  }

  const dataZoom=props.dataZoom?[
    {
      type: 'inside',
      start: 0,
      end: 100
    },
    {
      type: 'slider',
      start: 0,
      end: 100
    },
  ] : undefined 
  const dataset = data || []
  const options = {

   
      color: ["#FF814C", "#F02B3E"],
      tooltip: {
        trigger: "axis"
      },
      icon: "rect",
      legend: {
        data: ["新用户数", "授权注册"]
      },
      toolbox: {},
      xAxis: {
        type: "category",
      },
      yAxis: {},
      dataZoom,
      series: [
        {
          name: "新用户数",
          type: "line",
          smooth:true, 
        },
        {
          name: "授权注册",
          type: "line",
          smooth:true, 
        }
      ],
      dataset: {
        dimensions: ['createTime', 'fromNum', 'registeredNum'],
        source: dataset
      }
 
    
    
  }


  const piestyles = {
    width: '100%',
    height: '400px',
  }

  return (
    <>
      <div>
        <div >
          <p onClick={()=>router.push('/statistical/newUsers')}><span style={{borderBottom:'1px solid #f02d40',cursor: 'pointer',fontSize:'0.12rem',fontWeight:'600'}}>新增用户</span> {!props.BuildSelectHide && <span style={{ fontSize: '0.09rem', color: '#888', marginLeft: '0.06rem' }}>最近七天</span>}</p>
       </div>
        <EChart options={options} style={piestyles}  />
      </div>
    </>
  )
}

export default NewUsers;