/* * Author: 黎永顺 * name: 薪酬统计分析 * Description: * Date: 2023/4/10 */ import React, { Component } from "react"; import { inject, observer } from "mobx-react"; import { WeaDatePicker, WeaInputSearch, WeaLocaleProvider, WeaReqTop } from "ecCom"; import { Button } from "antd"; import { condition, reportCondition } from "./components/conditions"; import { commonEnumList, reportGetForm } from "../../apis/ruleconfig"; import { dimensionGetForm } from "../../apis/statistics"; import EmployeeDetails from "./components/employeeDetails"; import StatisticsModal from "./components/statisticsModal"; import DimensionSlide from "./components/dimensionSlide"; import DimensionTable from "./components/dimensionTable"; import ReportList from "./components/reportList"; import ReportForm from "./components/reportForm"; import moment from "moment"; import "./index.less"; const { getLabel } = WeaLocaleProvider; @inject("taxAgentStore", "attendanceStore") @observer class Index extends Component { constructor(props) { super(props); this.state = { conditions: [], convertConditions: [], reportConditions: [], selectedKey: "statistics", reportName: "", keyword: "", year: moment().format("YYYY"), slideReq: { visible: false, formId: "" }, modalReq: { title: "", visible: false, typeKey: "", id: "" } }; } componentDidMount() { this.initReportFormCondition(); } initReportFormCondition = (payload = {}) => { const { attendanceStore: { reportForm } } = this.props; reportGetForm(payload).then(({ status, data }) => { if (status) { const { statsDimOptions, data: detailData } = data; if (_.isEmpty(payload)) { this.setState({ reportConditions: _.map(reportCondition, item => { return { ...item, items: _.map(item.items, child => { if (child.domkey[0] === "dimensionIds") { return { ...child, options: _.map(statsDimOptions, dimTypeItem => ({ key: dimTypeItem.id, showname: dimTypeItem.content })) }; } return { ...child }; }) }; }) }, () => { reportForm.initFormFields(this.state.reportConditions); }); } else { reportForm.updateFields({ reportName: detailData.reportName, dimensionIds: detailData.dimension.join(",") }); } } }); }; initCondition = async () => { const { attendanceStore: { statisticsForm } } = this.props; const [dimTypeEnum, dimCodeList] = await Promise.all([this.commonEnumList(), this.dimensionGetForm()]); const { data: dimTypeData } = dimTypeEnum, { data: dimCodeData } = dimCodeList; const { baseForm: { statsDimOptions, groupDimOptions, data: dimTypeValue } } = dimCodeData; this.setState({ conditions: _.map(condition, item => { return { ...item, items: _.map(item.items, child => { if (child.domkey[0] === "dimType") { return { ...child, value: dimTypeValue.dimType, options: _.map(dimTypeData, dimTypeItem => ({ key: dimTypeItem.value, showname: dimTypeItem.defaultLabel })) }; } if (child.domkey[0] === "setting4Qualitative") { return { ...child, options: _.map(statsDimOptions, dimCodeItem => ({ key: dimCodeItem.id, showname: dimCodeItem.content })) }; } if (child.domkey[0] === "dimCode") { return { ...child, options: _.map(groupDimOptions, dimCodeItem => ({ key: dimCodeItem.id, showname: dimCodeItem.content })) }; } return { ...child }; }) }; }) }, () => { this.setState({ convertConditions: this.state.conditions }); statisticsForm.initFormFields(this.state.conditions); }); }; commonEnumList = () => { const payload = { enumClass: "com.engine.salary.report.enums.SalaryStatisticsDimensionTypeEnum" }; return commonEnumList(payload); }; dimensionGetForm = () => { return dimensionGetForm(); }; handleChangeCondition = (val, viewAttr) => { const { attendanceStore: { statisticsForm } } = this.props; const helpfulTitle = val === "RATION_GROUP_SPACING" ? "例:\n" + " 若:所属字段为【工龄】,分组设置为【0-5】,【5-10】;统计项为【税前薪资】,对应的统计规则为【求和】; 则统计结果为:【工龄】为【0-5】的所有人的【税前薪资】求和,【工龄】为【5-10】的所有人的【税前薪资】求和;\n" + "若:未选择所属字段,分组设置为【0-10,000.00】,【10,000.00-20,000.00】;若统计项为【税前薪资】,对应的统计规则为【计数】; 则统计结果为:【税前薪资】为【0-10,000.00】有多少人,【税前薪资】为【10,000.00-20,000.00】有多少人;" : val === "RATION_GROUP_INDIVIDUAL" ? "例:\n" + " 若:所属字段为【职级】,分组设置为【1】,【2】,【3】;统计项为【税前薪资】,对应的统计规则为【平均值】; 则统计结果为:【职级】为【1】的所有人的【税前薪资】的平均值,【职级】为【2】的所有人的【税前薪资】的平均值;【职级】为【3】的所有人的【税前薪资】的平均值;\n" + "若:未选择所属字段,分组设置为【1】,【2】,【3】;若统计项为【绩效】,对应的统计规则为【计数】; 则统计结果为:【绩效】为【1】有多少人,绩效为【2】有多少人,绩效为【3】有多少人;" : ""; if (val === "QUALITATIVE") { this.setState({ conditions: _.map(this.state.convertConditions, item => { return { ...item, items: _.map(_.filter(item.items, child => child.domkey[0] !== "dimCode"), it => { if (it.domkey[0] === "dimType") { return { ...it, value: val, viewAttr: viewAttr ? viewAttr : it.viewAttr }; } return { ...it }; }) }; }) }, () => { statisticsForm.setCondition(this.state.conditions); }); } else { this.setState({ conditions: _.map(this.state.convertConditions, item => { return { ...item, items: _.map(_.filter(item.items, child => child.domkey[0] !== "setting4Qualitative"), it => { if (it.domkey[0] === "dimType") { return { ...it, value: val, viewAttr: viewAttr ? viewAttr : it.viewAttr }; } else if (it.domkey[0] === "dimCode") { return { ...it, helpfulTitle }; } return { ...it }; }) }; }) }, () => { statisticsForm.setCondition(this.state.conditions); }); } }; handleReqBtnsClick = (key, id = "") => { if (key === "search") { const { reportName } = this.state; this.reportListRef.reportStatisticsReportList({ reportName }); } else { const { modalReq } = this.state; const title = key === "dimension" ?
{getLabel(111, "统计维度管理")}
: getLabel(111, id ? "编辑报表" : "新建报表"); this.setState({ modalReq: { ...modalReq, id, title, visible: true, typeKey: key } }, () => id && this.initReportFormCondition({ id })); } }; handleCancel = (refresh = false) => { const { attendanceStore: { reportForm } } = this.props; const { modalReq } = this.state; this.setState({ modalReq: { ...modalReq, visible: false, id: "" } }, () => { const { selectedKey, reportName, modalReq: { typeKey } } = this.state; selectedKey === "statistics" && reportForm.resetForm(); typeKey === "dimension" && this.initReportFormCondition(); refresh && selectedKey === "statistics" && this.reportListRef.reportStatisticsReportList({ reportName }); }); }; handleAddDimension = (formId = "") => { const { slideReq } = this.state; this.setState({ slideReq: { ...slideReq, visible: true, formId } }); }; handleClose = (initTable = false) => { const { attendanceStore: { statisticsForm } } = this.props; const { slideReq } = this.state; this.setState({ slideReq: { ...slideReq, visible: false, formId: "" } }, () => { statisticsForm.resetForm(); initTable && this.dimensionTableRef.dimensionList(); }); }; render() { const { taxAgentStore: { statisticsReportBtn }, attendanceStore: { statisticsForm, reportForm } } = this.props; const { selectedKey, modalReq, slideReq, conditions, reportConditions, reportName, keyword, year } = this.state; const buttons = selectedKey === "statistics" ? [ , , this.setState({ reportName })} onSearch={() => this.handleReqBtnsClick("search")}/> ] : [ {getLabel(111, "年薪资核算人员明细:")} this.setState({ year })}/> , this.setState({ keyword })} onSearch={() => this.employeeListRef.statisticsEmployeeList()}/> ]; const tabs = [ { key: "statistics", title: getLabel(111, "统计表") }, { key: "detail", title: getLabel(111, "员工明细") } ]; return ( } selectedKey={selectedKey} iconBgcolor="#F14A2D" tabDatas={tabs} className="xc_tj_fx_wrapper" showDropIcon={false} buttons={(!statisticsReportBtn && selectedKey === "statistics") ? buttons.slice(-1) : buttons} buttonSpace={10} onChange={selectedKey => this.setState({ selectedKey }, () => this.state.selectedKey === "statistics" && this.initReportFormCondition())} > { selectedKey === "statistics" ? this.reportListRef = dom} reportName={reportName} onEdit={this.handleReqBtnsClick} /> : this.employeeListRef = dom} keyword={keyword} year={year} /> } { modalReq.typeKey === "dimension" && this.dimensionTableRef = dom} onEdit={id => this.handleAddDimension(id)} /> } { modalReq.typeKey === "addReport" && } ); } } export default Index;