import { useEffect, useState, useCallback } from 'react';
import Echart from '@/components/echart/echart'
import { Card } from 'antd'
import { getAllOrgLine } from '@/services/statis'
import { useModel } from 'umi'
import moment from 'moment';

const lineOption = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    },
    // formatter: (params) => `截止：${params[0].data.name} <br />正常： ${params[0].data.value}`
    // formatter: (params) => `人次: ${params[0].data.value || 0}`
  },

  grid: {
    containLabel: true,
    left: 0,
    top: 8,
    right: 60,
    bottom: 0,
  },
  yAxis: {
    type: 'value',
  },

  xAxis: {
    type: 'category',

  },


  dataset: [
    {
      dimensions: ['name', 'value'],
      source: [],
    },
    {
      dimensions: ['name', 'value'],
      source: [],
    }
  ],
  series: [
    {
      name: '正常',
      type: 'line',
      datasetIndex: 0,
      itemStyle: {
        normal: {
          color: "#08507b",
          lineStyle: {
            color: "#08507b"
          }
        }
      }



    },
    {
      name: '异常',
      type: 'line',
      datasetIndex: 1,
      itemStyle: {
        normal: {
          color: "red",
          lineStyle: {
            color: "red"
          }
        }
      }

      // lineStyle: {
      //   color: 'red',
      // },
    }
  ]
}


export default (props) => {
  const [loading, setLoading] = useState(false)
  const [list, setList] = useState({})
  const { initialState } = useModel('@@initialState');

  const dataset = [
    {
      dimensions: ['name', 'value'],
      source: list.normal || [],
    },
    {
      dimensions: ['name', 'value'],
      source: list.abnormal || [],
    }
  ]

  const option = {
    ...lineOption,
    dataset,
  }
  console.log('dataset', dataset);


  useEffect(() => {
    // queryList()
    setLoading(true)

    getAllOrgLine({
      days: 7,
      startDate: moment().subtract(7, 'day').format('YYYY-MM-DD'),
      orgId: initialState.currentUser.orgId,
    }).then((res) => {
      setLoading(false)
      setList(res)

    }).catch(err => {
      setLoading(false)

    })

  }, [])

  return (
    <Card title='企业数据总览' loading={loading} bodyStyle={{ height: 600 }}>
      <Echart option={option} />
    </Card>
  )
}
