import React, { Component } from 'react';

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

import { Modal, Select } from 'amos-framework';
/**
 * 中心级2侧模块
 */
export default class Statistical extends Component {
  constructor(props) {
    
    super(props);
    this.state = {
      visible: true

    };
  }
  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 'week_safety_index':
        console.log('一周安全指数趋势刷新~~~~~~~~~~~~~~~~~~~~');
        this.AllSafety.AllSafetyData();
        break;
      case 'today_check_status':
        console.log('今日巡检情况刷新~~~~~~~~~~~~~~~~~~~~');
        this.FireSafety.FireSafetyData();
        break;
      case 'today_duty':
        this.FireStrength.FireStrengthData();
        console.log('今日值班刷新~~~~~~~~~~~~~~~~~~~~');
        break;
      case 'all':
        console.log('首页刷新~~~~~~~~~~~~~~~~~~~~');
        this.RiskControl.getRiskControl();
        this.safetyExecute.DangerControl();
        this.equipStatus.AlarmControl();
        this.AllSafety.AllSafetyData();
        this.FireSafety.FireSafetyData();
        this.FireStrength.FireStrengthData();
        break;
      default:
        console.log(refreshType,'：类型不支持');
    }
  }

  cancel = () => {

    this.setState({

      visible: false

    });

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