/* * 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 { 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 = (props) => { getTaxAgentSelectList(props.isShare).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 })) }; } 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, ...extra } = form.getFormDatas(); const { value, valueSpan } = taxAgent; 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] })) : [], 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
{getLabel(111, "统计数据范围")} {getLabel(111, "统计满足以下所有条件的人员薪资核算数据,不选则默认为选择全部")}
; }; renderProjectTitle = () => { const { selectedRowKeys } = this.state; const { id, dimension, isShare } = this.props; return
{getLabel(111, "统计项目")}
{ !isShare && } { !isShare && this.setState({ statisticalItemPayload: { visible: true, id, dimension, statisticsItemId: "", isShare } })} /> }
; }; render() { const { salaryMonth, conditions, selectedRowKeys, loading, statisticalItemPayload, dataSource, unitTypeList, timeType } = this.state; const { id, dimension, isShare } = this.props; const columns = [ { title: "统计项名称", dataIndex: "itemName", render: (txt, record) => { return ( { this.setState({ statisticalItemPayload: { visible: true, id, dimension, statisticsItemId: record.id, isShare } }); }}>{txt} ); } }, { title: "统计单位", dataIndex: "unitType", render: (txt, record) => { return this.customStatisticsItemsRef.reportStatisticsItemSave({ id: record.id, unitType })} />; } } ]; const rowSelection = { selectedRowKeys, onChange: (selectedRowKeys) => { this.setState({ selectedRowKeys }); }, getCheckboxProps: record => ({ disabled: isShare }) }; return ( this.props.onClose()} top={0} measureT="%" width={800} measureX="px" height={100} measureY="%" direction={"right"} title={} content={ this.setState({ salaryMonth: v, timeType })}/> { getSearchs(this.props.form, conditions, 2, false, () => { }, this.renderGroupTitle()) } this.setState({ dataSource: _.map(datas, (it, idx) => ({ ...it, indexValue: idx.toString() })) })} pagination={false} rowSelection={rowSelection} /> this.customStatisticsItemsRef = dom} {...statisticalItemPayload} onCancel={(isRefresh) => this.setState({ statisticalItemPayload: { visible: false, id: "", dimension: "", statisticsItemId: "", isShare: false } }, () => isRefresh && this.statisticsItemList(this.props.id))} /> } /> ); } } export default StatisticalMicroSettingsSlide; const TitleDialog = (props) => { return
{getLabel(111, "统计数据范围及规则设置")}
{ !props.isShare && }
; }; const StatisticalScopePicker = (props) => { const scopeBtns = [ { key: 1, label: getLabel(111, "上月") }, { key: 2, label: getLabel(111, "本月") }, { key: 3, label: getLabel(111, "一季度") }, { key: 4, label: getLabel(111, "二季度") }, { key: 5, label: getLabel(111, "三季度") }, { key: 6, label: getLabel(111, "四季度") }, { key: 7, label: getLabel(111, "上半年") }, { key: 8, label: getLabel(111, "下半年") }, { key: 9, label: getLabel(111, "本年") } ]; const { timeType, dateRange, onChange, viewAttr, disabled = false } = props; const [startDate, endDate] = dateRange || []; return
{ _.map(scopeBtns.slice(0, 2), o => ( )) }
{ _.map(scopeBtns.slice(2, 6), o => ( )) }
{ _.map(scopeBtns.slice(6), o => ( )) }
onChange([], 10)}>{getLabel(111, "指定月份")}
{ return current && endDate && current.getTime() > new Date(endDate).getTime(); }} format="YYYY-MM" onChange={(val) => onChange([val, endDate], timeType)} viewAttr={viewAttr} /> { return current && startDate && current.getTime() < new Date(startDate).getTime(); }} format="YYYY-MM" viewAttr={viewAttr} onChange={(val) => onChange([startDate, val], timeType)} />
; }; export const MonthRangePicker = (props) => { const { dateRange, onChange, viewAttr, disabled = false } = props; const [startDate, endDate] = dateRange || []; return
{ return current && endDate && current.getTime() > new Date(endDate).getTime(); }} format="YYYY-MM" onChange={(val) => onChange([val, endDate])} viewAttr={viewAttr} /> { return current && startDate && current.getTime() < new Date(startDate).getTime(); }} format="YYYY-MM" viewAttr={viewAttr} onChange={(val) => onChange([startDate, val])} />
; }; // 获取所属月份值 const getSalaryMonthValue = (dateType) => { let start = "", end = ""; switch (dateType) { case 1: start = moment().add(-1, "month").startOf("month").format("YYYY-MM"); end = moment().add(-1, "month").endOf("month").format("YYYY-MM"); break; case 2: start = moment().startOf("month").format("YYYY-MM"); end = moment().endOf("month").format("YYYY-MM"); break; case 3: start = moment().year() + "-01"; end = moment().year() + "-03"; break; case 4: start = moment().year() + "-04"; end = moment().year() + "-06"; break; case 5: start = moment().year() + "-07"; end = moment().year() + "-09"; break; case 6: start = moment().year() + "-10"; end = moment().year() + "-12"; break; case 7: start = moment().startOf("year").format("YYYY-MM"); end = moment().endOf("year").subtract(6, "month").format("YYYY-MM"); break; case 8: start = moment().startOf("year").add(6, "month").format("YYYY-MM"); end = moment().endOf("year").format("YYYY-MM"); break; case 9: start = moment().startOf("year").format("YYYY-MM"); end = moment().endOf("year").format("YYYY-MM"); break; default: break; } return [start, end]; };