/*
  *  方案信息确认
  * 保存并自动修改基数，仅保存方案设置
  * @Author:    黎永顺
  * @Date:      2024/8/19
  * @Wechat:
  * @Email:     971387674@qq.com
  * @description:
*/
import React, { Component } from "react";
import { WeaDialog, WeaLocaleProvider, WeaTransfer } from "ecCom";
import { Alert, Button } from "antd";

const getLabel = WeaLocaleProvider.getLabel;
const WeaTransferList = WeaTransfer.list;

class BaseValidateDialog extends Component {
  constructor(props) {
    super(props);
    this.state = { dataSource: [] };
  }

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextProps.visible !== this.props.visible && nextProps.visible) {
      this.setState({
        dataSource: _.filter(_.map(nextProps.baseChangeInfo.split("\n"), (g, gi) => ({
          id: gi + 1, name: g
        })), k => !!k.name)
      });
    }
    if (nextProps.visible !== this.props.visible && !nextProps.visible) this.setState({
      dataSource: []
    });
  }

  render() {
    const { dataSource } = this.state, { onCancel } = this.props;
    const scrollHeight = this.baseChangeRef ? this.baseChangeRef.state.height - 118 : 606.6;
    const buttons = [
      <Button type="primary" onClick={() => onCancel({
        validate: false, changeData: true
      })}>{getLabel(111, "保存并自动修改基数")}</Button>,
      <Button type="ghost" onClick={() => onCancel({
        validate: false, changeData: false
      })}>{getLabel(111, "仅保存方案设置")}</Button>
    ];
    return (
      <WeaDialog
        {...this.props} hasScroll className="baseChangeDialog" initLoadCss ref={dom => this.baseChangeRef = dom}
        title={getLabel(131329, "信息确认")} buttons={buttons}
        style={{
          width: 750, height: 606.6, minHeight: 200, minWidth: 380,
          maxHeight: "90%", maxWidth: "90%", overflow: "hidden", transform: "translate(0px, 0px)"
        }}
      >
        <div className="baseChangeContent">
          <Alert
            message={getLabel(111, "是否需要将社保档案中不满足上下限的基数值，自动设置为对应的上限或下限值？")}
            description={getLabel(111, "以下员工的社保福利档案基数大于上限值，或小于下限值：")}
            type="warning"/>
          {
            !_.isEmpty(dataSource) ? <WeaTransferList
              data={dataSource} renderItem={(it) => (<div className="detailBox">
              <div className="order">{it.id}</div>
              <div className="content" title={it.name}>{it.name}</div>
            </div>)}
              height={scrollHeight} checkedCb={() => ({})} checkedKeys={[]}
            /> : <div className="empty">{getLabel(111, "无数据变更记录")}</div>
          }
        </div>
      </WeaDialog>
    );
  }
}

export default BaseValidateDialog;
