import React, { Component } from 'react';

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

/**
 * 全景监控统计
 */
export default class StatisticalRight extends Component {

  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 '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.AllSafety.AllSafetyData();
        this.FireSafety.FireSafetyData();
        this.FireStrength.FireStrengthData();
        break;
      default:
        console.log(refreshType,'：类型不支持');
    }
  }


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