/*
 * Author: 黎永顺
 * name: 工资单发放重构-工资单模板查询
 * Description:
 * Date: 2023/10/12
 */
import React, { Component } from "react";
import { WeaInputSearch, WeaLocaleProvider, WeaSelect } from "ecCom";
import { getPayrollTemplateLedgerList } from "../../../../apis/payroll";

const getLabel = WeaLocaleProvider.getLabel;

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

  componentDidMount() {
    this.getPayrollTemplateLedgerList();
  }

  getPayrollTemplateLedgerList = () => {
    getPayrollTemplateLedgerList().then(({ status, data }) => {
      if (status) {
        this.setState({
          salarySobOptions: _.map(data, o => ({ key: o.id, showname: o.content }))
        });
      }
    });
  };

  render() {
    const { salarySobOptions } = this.state;
    const { queryParams } = this.props;
    const { salarySobId, name } = queryParams;
    return (
      <div className="payroll-btn-flex">
        <WeaSelect value={salarySobId} options={salarySobOptions} style={{ width: 200 }}
                   onChange={v => this.props.onChange({ salarySobId: v })}/>
        <WeaInputSearch value={name} style={{ marginLeft: 10 }}
                        placeholder={getLabel(111, "请输入工资单模板名称")}
                        onChange={v => this.props.onChange({ name: v })}
                        onSearch={this.props.onSearch}
        />
      </div>
    );
  }
}

export default TemplateQuery;
