/*
 * Author: 黎永顺
 * name:薪酬统计报薪资明细-高级查询
 * Description:
 * Date: 2024/3/26
 */
import React, { Component } from "react";
import { WeaLocaleProvider, WeaTools } from "ecCom";
import { Button } from "antd";
import { inject, observer } from "mobx-react";
import { getSearchs } from "../../../../util";
import { salaryDetailSearchConditions } from "../conditions";
import { getTaxAgentSelectList } from "../../../../apis/taxAgent";

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

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

  async componentDidMount() {
    const [{ data: taxAgentList }] = await Promise.all([getTaxAgentSelectList()]);
    this.setState({
      searchConditions: _.map(salaryDetailSearchConditions, item => {
        return {
          ...item,
          items: _.map(item.items, child => {
            if (getKey(child) === "taxAgentIds") {
              return {
                ...child, options: _.map(taxAgentList, o => ({ key: o.id, showname: o.content }))
              };
            }
            return { ...child };
          })
        };
      })
    }, () => {
      const { attendanceStore: { salaryDetailSearchForm } } = this.props;
      salaryDetailSearchForm.initFormFields(this.state.searchConditions);
    });
  }

  render() {
    const { searchConditions } = this.state;
    const { attendanceStore: { salaryDetailSearchForm } } = this.props;
    return (
      <React.Fragment>
        <div className="wea-advanced-searchsAd">
          {getSearchs(salaryDetailSearchForm, 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={() => salaryDetailSearchForm.resetForm()}>{getLabel(2022, "重置")}</Button>
            </span>
            <span style={{ marginLeft: 15 }}>
              <Button type="ghost" onClick={this.props.onCancel}>{getLabel(31129, "取消")}</Button>
            </span>
          </div>
        </div>
      </React.Fragment>
    );
  }
}

export default SalaryDetailAdvanceSearchPannel;

