import React, { Component } from 'react';

import AlarmControl from './AlarmControl';
import DangerControl from './DangerControl';
import RiskControl from './RiskControl';
import AmosWebSocket from 'amos-websocket';
import SysWsURL, { completeToken } from './../../../consts/wsUrlConsts';

/**
 * 全景监控统计
 */
export default class StatisticalLeft extends Component {
  constructor(props) {
    super(props);
   
    this.state = {
     
    };
  }

  ondetails = (type) => {
    this.props.ondetails(type);
  };


  componentWillMount = () => {
    
   
  };






  componentWillReceiveProps = (nextProps) => {
   
}





  handleData = (data = {}) => {
    console.log('ws data:', data);
    data = JSON.parse(JSON.stringify(data));
    console.log(data);
    let refreshType = data.refreshType;
    let content = data.content;
    switch (refreshType){
      case 'today_safety_index':
        console.log('今日安全指数刷新~~~~~~~~~~~~~~~~~~~~');
        this.RiskControl.getRiskControl();
        break;
      case 'fire_safety':
        console.log('消防安全执行刷新~~~~~~~~~~~~~~~~~~~~');
        this.safetyExecute.DangerControl();
        break;
      case 'monitor_data':
        console.log('设备状态检测数据刷新~~~~~~~~~~~~~~~~~~~~');
        this.equipStatus.AlarmControl();
        break;
      case 'error_status':
        console.log('异常区域刷新~~~~~~~~~~~~~~~~~~~~');
        break;
      case 'all':
        console.log('首页左侧刷新~~~~~~~~~~~~~~~~~~~~');
        this.RiskControl.getRiskControl();
        this.safetyExecute.DangerControl();
        this.equipStatus.AlarmControl();
        break;
      default:
        console.log(refreshType,'：类型不支持');
    }
  }


  render() {
    const wsURL = completeToken(SysWsURL.viewIndexws);
    const { flag  } = this.state;
    return (
      <div className="statistical-left">
        <AmosWebSocket ref={node => this.aws = node} url={wsURL} onMessage={this.handleData} reconnect debug />
        <RiskControl   ondetails={this.ondetails}   />
        <DangerControl ondetails={this.ondetails}   />
        <AlarmControl  ondetails={this.ondetails}   />
      </div>
    );
  }
}
