/* * Author: 黎永顺 * name: 统计数据范围及规则设置 * Description: * Date: 2023/4/21 */ import React, { Component } from "react"; import { toJS } from "mobx"; import { WeaButtonIcon, WeaError, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaRangePicker, WeaSearchGroup, WeaSelect, WeaSlideModal, WeaTable } from "ecCom"; import CustomStatisticsItemsModal from "./customStatisticsItemsModal"; import moment from "moment"; import { Button, message, Modal } from "antd"; import { condition } from "./condition"; import { getSearchs } from "../../../util"; import { reportStatisticsGetSearchCondition, reportStatisticsItemDelete, reportStatisticsSaveSearchCondition, statisticsItemList } from "../../../apis/statistics"; import { commonEnumList } from "../../../apis/ruleconfig"; import "../index.less"; const { getLabel } = WeaLocaleProvider; class StatisticalMicroSettingsSlide extends Component { constructor(props) { super(props); this.state = { loading: false, selectedRowKeys: [], conditions: [], dataSource: [], unitTypeList: [], salaryMonth: [], statisticalItemPayload: { visible: false, id: "", dimension: "", statisticsItemId: "" } }; } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.taxAgentAdminOption !== this.props.taxAgentAdminOption && !_.isEmpty(nextProps.taxAgentAdminOption)) { const conditions = _.map(condition, item => { return { ...item, items: _.map(item.items, child => { if (child.domkey[0] === "taxAgent") { return { ...child, options: toJS(nextProps.taxAgentAdminOption) }; } return { ...child }; }) }; }); this.setState({ conditions }); nextProps.form.initFormFields(condition); } if (nextProps.id !== this.props.id && !_.isEmpty(nextProps.id)) { this.reportStatisticsGetSearchCondition(nextProps.id); this.statisticsItemList(nextProps.id).then(r => { }); } if (nextProps.visible !== this.props.visible && !nextProps.visible) { nextProps.form.resetForm(); this.setState({ selectedRowKeys: [] }); } } reportStatisticsGetSearchCondition = (id) => { const { conditions } = this.state; const { form } = this.props; reportStatisticsGetSearchCondition({ id }).then(({ status, data }) => { if (status && !_.isEmpty(data)) { const { salaryEndMonth, salaryStartMonth, ...formData } = data.data; this.setState({ salaryMonth: [salaryStartMonth || moment().startOf("year").format("YYYY-MM"), salaryEndMonth || moment().format("YYYY-MM")] }); const fields = _.map(conditions[0].items, it => it.domkey[0]); fields.map(item => { const value = item.indexOf("hiredate") !== -1 ? { value: formData["hiredate"] || [] } : { value: !_.isNil(formData[item]) ? _.map(formData[item], val => val.id).join(",") : "", valueSpan: !_.isNil(formData[item]) ? _.map(formData[item], val => val.name).join(",") : "", valueObj: !_.isNil(formData[item]) ? formData[item] : [] }; const key = item.indexOf("hiredate") !== -1 ? "hiredate1__hiredate2" : item; form.updateFields({ [key]: value }); }); } }); }; reportStatisticsSaveSearchCondition = () => { const { salaryMonth, dataSource } = this.state; const { form, id, dimension, onClose } = this.props; const [salaryStartMonth, salaryEndMonth] = salaryMonth; const { department, employee, position, subCompany, taxAgent, ...extra } = form.getFormDatas(); const { value, valueSpan } = taxAgent; if (!salaryEndMonth && !salaryStartMonth) { this.refs.weaError.showError(); return; } const payload = { dimension, id, hiredate: extra["hiredate1__hiredate2"].value || [], department: _.map(department.valueObj, it => ({ id: it.id, name: it.name })), employee: _.map(employee.valueObj, it => ({ id: it.id, name: it.name })), position: _.map(position.valueObj, it => ({ id: it.id, name: it.name })), subCompany: _.map(subCompany.valueObj, it => ({ id: it.id, name: it.name })), taxAgent: value ? _.map(value.split(","), (it, idx) => ({ id: it, name: valueSpan.split(",")[idx] })) : [], items: dataSource, salaryEndMonth: salaryEndMonth + "-01", salaryStartMonth: salaryStartMonth + "-01" }; this.setState({ loading: true }); reportStatisticsSaveSearchCondition(payload).then(({ status, errormsg }) => { this.setState({ loading: false }); if (status) { onClose(true); message.success(getLabel(111, "保存成功")); } else { message.error(errormsg); } }).catch(() => this.setState({ loading: false })); }; reportStatisticsItemDelete = () => { Modal.confirm({ title: getLabel(111, "信息确认"), content: getLabel(111, "确认要删除吗?"), onOk: () => { const { selectedRowKeys } = this.state; reportStatisticsItemDelete(selectedRowKeys).then(({ status, errormsg }) => { if (status) { message.success(getLabel(111, "删除成功")); this.setState({ selectedRowKeys: [] }, () => { this.statisticsItemList(this.props.id).then(r => { }); }); } else { message.error(errormsg || getLabel(111, "删除失败")); } }); } }); }; statisticsItemList = async (statisticsReportId = "") => { const { data: unitTypeList } = await this.commonEnumList(); statisticsItemList({ statisticsReportId }).then(({ status, data }) => { if (status) { this.setState({ dataSource: data, unitTypeList: _.map(unitTypeList, it => ({ key: it.value.toString(), showname: it.defaultLabel })) }); } }); }; commonEnumList = () => { const payload = { enumClass: "com.engine.salary.report.enums.UnitTypeEnum" }; return commonEnumList(payload); }; renderGroupTitle = () => { return
{getLabel(111, "统计数据范围")} {getLabel(111, "统计满足以下所有条件的人员薪资核算数据,不选则默认为选择全部")}
; }; renderProjectTitle = () => { const { selectedRowKeys } = this.state; const { id, dimension } = this.props; return
{getLabel(111, "统计项目")}
this.setState({ statisticalItemPayload: { visible: true, id, dimension, statisticsItemId: "" } })} />
; }; render() { const { salaryMonth, conditions, selectedRowKeys, loading, statisticalItemPayload, dataSource, unitTypeList } = this.state; const { id, dimension } = this.props; const columns = [ { title: "统计项名称", dataIndex: "itemName", render: (txt, record) => { return ( this.setState({ statisticalItemPayload: { visible: true, id, dimension, statisticsItemId: record.id } })}>{txt} ); } }, { title: "统计单位", dataIndex: "unitType", render: (txt, record) => { return this.customStatisticsItemsRef.reportStatisticsItemSave({ id: record.id, unitType })} />; } } ]; const rowSelection = { selectedRowKeys, onChange: (selectedRowKeys) => { this.setState({ selectedRowKeys }); } }; return ( this.props.onClose()} top={0} measureT="%" width={800} measureX="px" height={100} measureY="%" direction={"right"} title={} content={ this.setState({ salaryMonth: v })} /> { getSearchs(this.props.form, conditions, 2, false, () => { }, this.renderGroupTitle()) } this.setState({ dataSource })} pagination={false} rowSelection={rowSelection} /> this.customStatisticsItemsRef = dom} {...statisticalItemPayload} onCancel={(isRefresh) => this.setState({ statisticalItemPayload: { visible: false, id: "", dimension: "", statisticsItemId: "" } }, () => isRefresh && this.statisticsItemList(this.props.id))} /> } /> ); } } export default StatisticalMicroSettingsSlide; const TitleDialog = (props) => { return
{getLabel(111, "统计数据范围及规则设置")}
; };