/* * Author: 黎永顺 * name: 统计数据范围及规则设置 * Description: * Date: 2023/4/21 */ import React, { Component } from "react"; import { WeaButtonIcon, WeaDatePicker, WeaError, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaSearchGroup, WeaSelect, WeaSlideModal, WeaTable, WeaTools } from "ecCom"; import CustomStatisticsItemsModal from "./customStatisticsItemsModal"; import moment from "moment"; import { Button, message, Modal } from "antd"; import { getSearchs } from "../../../util"; import { deleteRangeSetting, reportStatisticsGetSearchCondition, reportStatisticsItemDelete, reportStatisticsSaveSearchCondition, statisticsItemList } from "../../../apis/statistics"; import { commonEnumList } from "../../../apis/ruleconfig"; import { getTaxAgentSelectList } from "../../../apis/taxAgent"; import { getPayrollTemplateLedgerList } from "../../../apis/payroll"; import { condition } from "./condition"; import cs from "classnames"; import "../index.less"; const getKey = WeaTools.getKey; const { getLabel } = WeaLocaleProvider; class StatisticalMicroSettingsSlide extends Component { constructor(props) { super(props); this.state = { loading: false, selectedRowKeys: [], conditions: [], dataSource: [], unitTypeList: [], salaryMonth: [], timeType: 10, statisticalItemPayload: { visible: false, id: "", dimension: "", statisticsItemId: "", isShare: false } }; } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && nextProps.visible) this.getTaxAgentSelectList(nextProps); if (nextProps.id !== this.props.id && !_.isEmpty(nextProps.id)) { this.statisticsItemList(nextProps.id).then(r => { }); } if (nextProps.visible !== this.props.visible && !nextProps.visible) { nextProps.form.resetForm(); this.setState({ selectedRowKeys: [] }); } } getTaxAgentSelectList = async (props) => { const { data: salarySobList } = await getPayrollTemplateLedgerList(); getTaxAgentSelectList(true).then(({ status, data }) => { if (status) { const conditions = _.map(condition, item => { return { ...item, items: _.map(item.items, child => { if (getKey(child) === "taxAgent") { return { ...child, viewAttr: props.isShare ? 1 : child.viewAttr, options: _.map(data, o => ({ key: o.id, showname: o.content })) }; } else if (getKey(child) === "salarySob") { return { ...child, viewAttr: props.isShare ? 1 : child.viewAttr, options: _.map(salarySobList, o => ({ key: o.id, showname: o.content })) }; } return { ...child, viewAttr: props.isShare ? 1 : child.viewAttr }; }) }; }); this.setState({ conditions }, () => { props.form.initFormFields(this.state.conditions); props.id && this.reportStatisticsGetSearchCondition(props.id); }); } }); }; reportStatisticsGetSearchCondition = (id) => { const { conditions } = this.state; const { form } = this.props; reportStatisticsGetSearchCondition({ id }).then(({ status, data }) => { if (status && !_.isEmpty(data)) { const { salaryEndMonth, salaryStartMonth, timeType, ...formData } = data.data; this.setState({ timeType, 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, timeType, dataSource } = this.state; const { form, id, dimension, onClose } = this.props; const [salaryStartMonth, salaryEndMonth] = salaryMonth; const { department, employee, position, subCompany, taxAgent, salarySob, ...extra } = form.getFormDatas(); const { value, valueSpan } = taxAgent; const { value: sobValue, valueSpan: sobValueSpan } = salarySob; if (!salaryEndMonth || !salaryStartMonth) { this.refs.weaError.showError(); return; } const payload = { dimension, id, timeType, 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] })) : [], salarySob: sobValue ? _.map(sobValue.split(","), (it, idx) => ({ id: it, name: sobValueSpan.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 => { deleteRangeSetting({ reportId: this.props.id }); }); }); } 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