salary-management-front/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerBaseSetting.js

313 lines
11 KiB
JavaScript
Raw Normal View History

2022-12-09 14:16:11 +08:00
/*
* Author: 黎永顺
* name: 薪资账套基本设置
* Description:
* Date: 2022/12/9
*/
import React, { Component } from "react";
import { WeaCheckbox, WeaFormItem, WeaHelpfulTip, WeaInput, WeaSelect, WeaTextarea } from "ecCom";
import { Col, Row } from "antd";
import { inject, observer } from "mobx-react";
import { baseSettingFormItem } from "../config";
2022-12-12 10:24:07 +08:00
import { getLedgerBasicForm } from "../../../apis/ledger";
2022-12-09 15:26:21 +08:00
import { getAddMonthYearMonth, getCurrentYearMonth, getSubtractMonthYearMonth } from "../../../util/date";
import moment from "moment";
2022-12-09 14:16:11 +08:00
import "./index.less";
@inject("taxAgentStore")
@observer
class LedgerBaseSetting extends Component {
constructor(props) {
super(props);
this.state = {
baseForm: baseSettingFormItem,
settingBaseInfo: {
2022-12-12 10:24:07 +08:00
name: "",
taxAgentId: "",
taxableItems: "1",
salaryCycleType: "3",
salaryCycleFromDay: "1",
taxCycleType: "3",
attendCycleType: "3",
attendCycleFromDay: "1",
socialSecurityCycleType: "3",
description: "",
canEdit: false
2022-12-09 14:16:11 +08:00
}
};
}
componentDidMount() {
this.getTaxAgentSelectListAsAdmin();
2022-12-12 10:24:07 +08:00
if (this.props.visible && this.props.editId) {
this.getLedgerBasicForm(this.props.editId);
}
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.editId) {
this.getLedgerBasicForm(nextProps.editId);
}
if (nextProps.visible !== this.props.visible && !nextProps.editId) {
this.handleResetBaseInfo();
}
2022-12-09 14:16:11 +08:00
}
2022-12-12 10:24:07 +08:00
handleResetBaseInfo = () => {
this.setState({
settingBaseInfo: {
name: "",
taxAgentId: "",
taxableItems: "1",
salaryCycleType: "3",
salaryCycleFromDay: "1",
taxCycleType: "3",
attendCycleType: "3",
attendCycleFromDay: "1",
socialSecurityCycleType: "3",
description: "",
2022-12-12 11:38:43 +08:00
canEdit: "true"
2022-12-12 10:24:07 +08:00
}
});
};
getLedgerBasicForm = (id) => {
getLedgerBasicForm({ id }).then(({ status, data }) => {
if (status) {
const { basicForm } = data;
const { settingBaseInfo } = this.state;
let tmpV = {};
_.map(Object.keys(settingBaseInfo), key => {
2022-12-16 11:05:07 +08:00
tmpV[key] = !_.isNil(basicForm[key]) ? basicForm[key].toString() : "";
2022-12-12 10:24:07 +08:00
});
this.setState({
settingBaseInfo: {
...settingBaseInfo,
...tmpV
}
}, () => {
this.props.onSaveParams(this.state.settingBaseInfo);
});
}
});
};
2022-12-09 14:16:11 +08:00
getTaxAgentSelectListAsAdmin = () => {
const { taxAgentStore } = this.props;
const { getTaxAgentSelectListAsAdmin } = taxAgentStore;
getTaxAgentSelectListAsAdmin().then(({ status, data }) => {
if (status) {
const { baseForm } = this.state;
this.setState({
baseForm: _.map(baseForm, it => {
if (it.key === "taxAgentId") {
return {
...it,
options: _.map(data, it => ({ key: it.id, showname: it.content }))
};
}
return { ...it };
})
});
}
});
};
handleChangeField = (key, value) => {
const { onSaveParams } = this.props;
const { settingBaseInfo } = this.state;
this.setState({
settingBaseInfo: {
...settingBaseInfo,
[key]: value
}
}, () => {
onSaveParams(this.state.settingBaseInfo);
});
};
render() {
2022-12-12 11:38:43 +08:00
const { editId } = this.props;
2022-12-09 14:16:11 +08:00
const { baseForm, settingBaseInfo } = this.state;
2022-12-12 11:38:43 +08:00
const { canEdit, taxAgentId } = settingBaseInfo;
let taxAgentIdDisabled = false, taxableItemsDisabled = false;
2022-12-09 14:16:11 +08:00
return (
<div className="baseSettingWrapper">
<Row gutter={20}>
<Col span={18} className="baseSettingLeft">
{
_.map(baseForm, item => {
const { key, label, type, options = [], children = [] } = item;
2022-12-12 11:38:43 +08:00
taxAgentIdDisabled = key === "taxAgentId" && taxAgentId;
taxableItemsDisabled = key === "taxableItems" && editId;
2022-12-09 14:16:11 +08:00
return <WeaFormItem
key={key} label={label}
labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}
>
{
type === "INPUT" ?
2022-12-12 11:38:43 +08:00
<WeaInput value={settingBaseInfo[key]} viewAttr={3} disabled={canEdit !== "true"}
2022-12-09 14:16:11 +08:00
onChange={(v) => this.handleChangeField(key, v)}/> :
type === "TEXTAREA" ?
2022-12-12 11:38:43 +08:00
<WeaTextarea value={settingBaseInfo[key]} disabled={canEdit !== "true"}
onChange={(v) => this.handleChangeField(key, v)}/> :
2022-12-09 14:16:11 +08:00
type === "CHECKBOX" ?
<React.Fragment>
<WeaCheckbox value={true} viewAttr={1}
content="【入职日期≤薪资周期止】且【离职日期≥薪资周期起】"/>
<WeaHelpfulTip width={200} title="提示:最后发薪日期为空,默认为无穷大" placement="topLeft"/>
</React.Fragment> :
type === "SELECT" ?
<WeaSelect value={settingBaseInfo[key]} options={options} viewAttr={3}
2022-12-12 11:38:43 +08:00
disabled={canEdit !== "true" || taxAgentIdDisabled || taxableItemsDisabled}
2022-12-09 14:16:11 +08:00
onChange={(v) => this.handleChangeField(key, v)}/> :
2022-12-12 10:24:07 +08:00
type === "CUSTOM" ?
<CustomSelect list={children} baseInfo={settingBaseInfo} inputStr={key}
onChange={(key, v) => this.handleChangeField(key, v)}/> : null
2022-12-09 14:16:11 +08:00
}
</WeaFormItem>;
})
}
</Col>
2022-12-09 15:26:21 +08:00
<Col span={6}><MonthCycleDesc {...settingBaseInfo}/></Col>
2022-12-09 14:16:11 +08:00
</Row>
</div>
);
}
}
export default LedgerBaseSetting;
const CustomSelect = (props) => {
2022-12-12 10:24:07 +08:00
const { list, baseInfo, onChange, inputStr } = props;
2022-12-12 11:38:43 +08:00
const { salaryCycleType, salaryCycleFromDay, attendCycleType, attendCycleFromDay, canEdit } = baseInfo;
2022-12-12 10:24:07 +08:00
const salaryCycleStrObj = initPeriodStr("inputStr", salaryCycleType, salaryCycleFromDay);
const attendCycleStrObj = initPeriodStr("inputStr", attendCycleType, attendCycleFromDay);
2022-12-09 14:16:11 +08:00
return <Row gutter={10} key={key}>
{
_.map(list, item => {
const { key, options = [] } = item;
return <Col span={6}>
<WeaSelect value={baseInfo[key]} options={options} viewAttr={3}
2022-12-12 11:38:43 +08:00
disabled={canEdit !== "true"}
2022-12-09 14:16:11 +08:00
onChange={(v) => onChange(key, v)}/>
</Col>;
})
}
2022-12-12 10:24:07 +08:00
<Col span={12}
className="desc">{inputStr === "salaryCycleStrObj" ? salaryCycleStrObj.inputStr : attendCycleStrObj.inputStr}</Col>
2022-12-09 14:16:11 +08:00
</Row>;
};
const MonthCycleDesc = (props) => {
2022-12-12 10:24:07 +08:00
const {
taxCycleType,
socialSecurityCycleType,
salaryCycleFromDay,
salaryCycleType,
attendCycleType,
attendCycleFromDay
} = props;
const salaryCycleStrObj = initPeriodStr("salaryCycleStr", salaryCycleType, salaryCycleFromDay);
const attendCycleStrObj = initPeriodStr("attendCycleStr", attendCycleType, attendCycleFromDay);
2022-12-09 14:16:11 +08:00
return <div className="baseSettingRight">
<div className="title">月份周期说明</div>
<div className="descContent">
2022-12-09 15:26:21 +08:00
<div>
薪资所属月是<span className="notice">{moment().format("YYYY-MM")}</span><span
className="notice">{moment().format("MM")}</span>
</div>
2022-12-09 14:16:11 +08:00
<div>根据您当前的选择相应的周期为</div>
<div className="descTitle">薪资周期</div>
2022-12-12 10:24:07 +08:00
<div>
<span className="notice">{getStartDate(salaryCycleType, salaryCycleFromDay)}</span>
<span className="notice">{salaryCycleStrObj.date}</span>
</div>
2022-12-09 14:16:11 +08:00
<div className="descTitle">税款所属期</div>
2022-12-09 15:26:21 +08:00
<div className="notice">{getMonth(taxCycleType)}</div>
2022-12-09 14:16:11 +08:00
<div className="descTitle">考勤取值周期</div>
2022-12-12 10:24:07 +08:00
<div>
<span className="notice">{getStartDate(attendCycleType, attendCycleFromDay)}</span>
<span className="notice">{attendCycleStrObj.date}</span>
</div>
2022-12-09 14:16:11 +08:00
<div className="descTitle">福利台账月份</div>
2022-12-09 15:26:21 +08:00
<div>引用<span className="notice">{getMonth(socialSecurityCycleType)}</span></div>
2022-12-09 14:16:11 +08:00
</div>
</div>;
};
2022-12-09 15:26:21 +08:00
2022-12-12 10:24:07 +08:00
// 获取开始日期
const getStartDate = (salaryCycleType, day) => {
day = Number(day);
return getMonth(salaryCycleType) + "-" + (day < 10 ? "0" + day : day);
};
2022-12-09 15:26:21 +08:00
const getMonth = (salaryCycleType) => {
switch (salaryCycleType) {
case "1": // 上上月
return getSubtractMonthYearMonth(2);
case "2": // 上月
return getSubtractMonthYearMonth(1);
case "3": // 本月
return getCurrentYearMonth();
case "4": // 下月
return getAddMonthYearMonth(1);
}
};
2022-12-12 10:24:07 +08:00
const initPeriodStr = (periodStrType, types, fromDay) => {
let str = "", tmpDate = null;
switch (types) {
case "1":
tmpDate = moment().subtract(2, "month");
const is_31H = moment(tmpDate, "YYYY-MM").daysInMonth() === 31;
if (fromDay == 1) {
tmpDate = moment().subtract(2, "month").endOf("month");
str = `至上上月最后一天`;
} else {
tmpDate = moment(new Date(`${moment(tmpDate).format("YYYY-MM")}-0${fromDay}`))
.add(is_31H ? 30 : 29, "days");
str = `至上月${moment(tmpDate).date()}`;
}
break;
case "2":
tmpDate = moment().subtract(1, "month");
const is_31 = moment(tmpDate, "YYYY-MM").daysInMonth() === 31;
if (fromDay == 1) {
tmpDate = moment().subtract(1, "month").endOf("month");
str = `至上月最后一天`;
} else {
tmpDate = moment(new Date(`${moment(tmpDate).format("YYYY-MM")}-0${fromDay}`))
.add(is_31 ? 30 : 29, "days");
str = `至本月${moment(tmpDate).date()}`;
}
break;
case "3":
tmpDate = moment().add(0, "month");
const is_31K = moment(tmpDate, "YYYY-MM").daysInMonth() === 31;
if (fromDay == 1) {
tmpDate = moment().endOf("month");
str = `至本月最后一天`;
} else {
tmpDate = moment(new Date(`${moment(tmpDate).format("YYYY-MM")}-0${fromDay}`))
.add(is_31K ? 30 : 29, "days");
str = `至下月${moment(tmpDate).date()}`;
}
break;
case "4":
tmpDate = moment().add(1, "month");
const is_31L = moment(tmpDate, "YYYY-MM").daysInMonth() === 31;
if (fromDay == 1) {
tmpDate = moment().add(1, "month").endOf("month");
str = `至下月最后一天`;
} else {
tmpDate = moment(new Date(`${moment(tmpDate).format("YYYY-MM")}-0${fromDay}`))
.add(is_31L ? 30 : 29, "days");
str = `至下下月${moment(tmpDate).date()}`;
}
break;
default:
break;
}
return {
[periodStrType]: str,
date: moment(tmpDate).format("YYYY-MM-DD")
};
};