/*
 * Author: 黎永顺
 * name: 按补缴人员的历史月份核算基数和当前档案方案核算
 * Description:
 * Date: 2023/1/3
 */
import React, { Component } from "react";
import { WeaInputNumber, WeaSearchGroup } from "ecCom";
import "./index.less";

class BusinessAccounting extends Component {
  renderBaseItem = (dataSource = [], type) => {
    return <ul className="baseFieldItemWrapper">
      {
        _.map(dataSource, it => {
          const { insuranceName, insuranceBase } = it;
          return <li>
            <div>{insuranceName}</div>
            <div>
              <WeaInputNumber
                value={insuranceBase} min={0}
                precision={2} onChange={(val) => this.handleChangeBaseItem(it, val, type)}
              />
            </div>
          </li>;
        })
      }
    </ul>;
  };
  handleChangeBaseItem = (item, value, type) => {
    const { onChangeBaseItem, socialSecurityBase, fundBase, otherBase } = this.props;
    _.map(this.props[type], it => {
      if (item.insuranceId === it.insuranceId) {
        it.insuranceBase = value;
      }
    });
    onChangeBaseItem(socialSecurityBase, fundBase, otherBase);
  };

  render() {
    const { socialSecurityBase, fundBase, otherBase } = this.props;
    return (
      <div>
        {
          !_.isEmpty(socialSecurityBase) &&
          <WeaSearchGroup title="社保补缴基数" showGroup
                          col={1}>{this.renderBaseItem(socialSecurityBase, "socialSecurityBase")}</WeaSearchGroup>
        }
        {
          !_.isEmpty(fundBase) &&
          <WeaSearchGroup title="公积金补缴基数" showGroup
                          col={1}>{this.renderBaseItem(fundBase, "fundBase")}</WeaSearchGroup>
        }
        {
          !_.isEmpty(otherBase) &&
          <WeaSearchGroup title="其他福利补缴基数" showGroup
                          col={1}>{this.renderBaseItem(otherBase, "otherBase")}</WeaSearchGroup>
        }
      </div>
    );
  }
}

export default BusinessAccounting;
