/*
 * Author: 黎永顺
 * name: 调薪记录-查看面板
 * Description:
 * Date: 2023/10/16
 */
import React, { Component } from "react";
import { WeaLocaleProvider, WeaTools } from "ecCom";
import { Button } from "antd";
import { inject, observer } from "mobx-react";
import { adjustSearchConditions } from "../conditions";
import { getSearchs } from "../../../../util";
import { commonEnumList } from "../../../../apis/ruleconfig";

const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;

@inject("payrollFilesStore")
@observer
class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      searchConditions: []
    };
  }

  componentDidMount() {
    commonEnumList({ enumClass: "com.engine.salary.enums.salaryarchive.SalaryArchiveItemAdjustReasonEnum" })
      .then(({ status, data }) => {
        if (status) {
          this.setState({
            searchConditions: _.map(adjustSearchConditions, item => {
              return {
                ...item,
                items: _.map(item.items, o => {
                  if (getKey(o) === "userStatus") {
                    return {
                      ...o,
                      options: [
                        { key: "0", showname: getLabel(18883, "试用") }, {
                          key: "1",
                          showname: getLabel(15711, "正式")
                        },
                        { key: "2", showname: getLabel(480, "临时") }, {
                          key: "3",
                          showname: getLabel(15844, "试用延期")
                        },
                        { key: "4", showname: getLabel(542707, "解雇") }, {
                          key: "5",
                          showname: getLabel(6091, "离职")
                        },
                        { key: "6", showname: getLabel(6092, "退休") }
                      ]
                    };
                  } else if (getKey(o) === "adjustReason") {
                    return {
                      ...o,
                      options: _.map(data, item => ({
                        key: item.value,
                        showname: item.defaultLabel
                      }))
                    };
                  }
                  return { ...o };
                }),
                title: getLabel(32905, "常用条件")
              };
            })
          }, () => {
            const { payrollFilesStore: { adjustForm } } = this.props;
            adjustForm.initFormFields(this.state.searchConditions);
          });
        }
      });
  }

  render() {
    const { searchConditions } = this.state;
    const { payrollFilesStore: { adjustForm } } = this.props;
    return (
      <React.Fragment>
        <div className="wea-advanced-searchsAd">
          {getSearchs(adjustForm, searchConditions, 2, false)}
        </div>
        <div className="wea-search-buttons">
          <div style={{ textAlign: "center" }}>
            <span style={{ marginLeft: 15 }}><Button type="primary"
                                                     onClick={this.props.onAdSearch}>{getLabel(388113, "搜索")}</Button></span>
            <span style={{ marginLeft: 15 }}><Button type="ghost"
                                                     onClick={() => adjustForm.resetForm()}>{getLabel(2022, "重置")}</Button></span>
            <span style={{ marginLeft: 15 }}><Button type="ghost"
                                                     onClick={this.props.onToggleSwitch}>{getLabel(31129, "取消")}</Button></span>
          </div>
        </div>
      </React.Fragment>
    );
  }
}

export default Index;
