import React, { Component } from 'react';
import { RiskControlDetailAction } from './../../../services/centerLevelService';
import moment from 'moment';
const format = 'YYYY-MM-dd';


export default class ModelContent extends Component {

  constructor(props) {
    super(props);
    this.state = {
      alarmData: []
    };
  }

  componentDidMount(){
    let { type } = this.props;
    this.RiskControlDetail(type);
  }

  RiskControlDetail = (type) => {
    RiskControlDetailAction(type).then(data => {
      this.setState({
        alarmData: data
      });
    });
  }

  /**
   * 获取标题
   *
   * @memberof ModelContent
   */
  getTitle = (v) => {
    const titleParams = {
      1: '一级风险点', //一级风险点
      2: '二级风险点', //二级风险点
      3: '三级风险点', //三级风险点
      4: '四级风险点' //四级风险点
    };
    return titleParams[v];
  }

  formatData = (str) => {
    let date = str.split(' ')[0];
    return date;
  }

  renderContent = (content) =>{
    return (
      <div className='rows'>
        {(content || []).map(itemA => {
          return (
            <div className='row'>
              <span>{itemA.name}</span>
              <span className='date'>{this.formatData(itemA.changeDate)}</span>
            </div>
          );
        })}
      </div>
    );
  }

  render() {
    let { alarmData } = this.state;
    let { type } = this.props;
    return (
      <div className='model-content'>
        {(alarmData || []).map(item => {
          return (
            <div className='content-div'>
              <div className='title'>
                <span>|</span>
                <span className='next-title'>{ type === 'risk' ? this.getTitle(item.typeCode) : item.typeName }</span>
              </div>
              {this.renderContent(item.content)}
            </div>
          );
        })}
      </div>
    );
  }
}
