产品-薪資張濤月份说明数据的错误修改

This commit is contained in:
黎永顺 2023-04-17 11:53:21 +08:00
parent 7ea5936829
commit 8e36bc89be
2 changed files with 202 additions and 93 deletions

View File

@ -8,10 +8,16 @@ 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 {toJS} from 'mobx';
import { baseSettingFormItem } from "../config";
import { getLedgerBasicForm } from "../../../apis/ledger";
import { getAddMonthYearMonth, getCurrentYearMonth, getSubtractMonthYearMonth } from "../../../util/date";
import {
generateBasicInfo,
getAddMonthYearMonth,
getCurrentYearMonth,
getMonthDays,
getSubtractMonthYearMonth,
prefixAddZero
} from "../../../util/date";
import { commonEnumList } from "../../../apis/ruleconfig";
import moment from "moment";
import "./index.less";
@ -206,9 +212,8 @@ export default LedgerBaseSetting;
const CustomSelect = (props) => {
const { list, baseInfo, onChange, inputStr } = props;
const { salaryCycleType, salaryCycleFromDay, attendCycleType, attendCycleFromDay, canEdit } = baseInfo;
const salaryCycleStrObj = initPeriodStr("inputStr", salaryCycleType, salaryCycleFromDay);
const attendCycleStrObj = initPeriodStr("inputStr", attendCycleType, attendCycleFromDay);
const { canEdit } = baseInfo;
const selectInfo = buildEditBasicInfo(baseInfo);
return <Row gutter={10} key={inputStr}>
{
_.map(list, item => {
@ -221,20 +226,12 @@ const CustomSelect = (props) => {
})
}
<Col span={12}
className="desc">{inputStr === "salaryCycleStrObj" ? salaryCycleStrObj.inputStr : attendCycleStrObj.inputStr}</Col>
className="desc">{inputStr === "salaryCycleStrObj" ? selectInfo.salaryCycleInfo.salaryPeriodTip : selectInfo.attendCycleInfo.attendancePeriodTip}</Col>
</Row>;
};
const MonthCycleDesc = (props) => {
const {
taxCycleType,
socialSecurityCycleType,
salaryCycleFromDay,
salaryCycleType,
attendCycleType,
attendCycleFromDay
} = props;
const salaryCycleStrObj = initPeriodStr("salaryCycleStr", salaryCycleType, salaryCycleFromDay);
const attendCycleStrObj = initPeriodStr("attendCycleStr", attendCycleType, attendCycleFromDay);
const { taxCycleType, socialSecurityCycleType } = props;
const selectInfo = buildEditBasicInfo({ ...props });
return <div className="baseSettingRight">
<div className="title">月份周期说明</div>
<div className="descContent">
@ -245,28 +242,131 @@ const MonthCycleDesc = (props) => {
<div>根据您当前的选择相应的周期为</div>
<div className="descTitle">薪资周期</div>
<div>
<span className="notice">{getStartDate(salaryCycleType, salaryCycleFromDay)}</span>
<span className="notice">{salaryCycleStrObj.date}</span>
<span className="notice">{selectInfo.salaryCycleInfo.salaryPeriodStart}</span>
<span className="notice">{selectInfo.salaryCycleInfo.salaryPeriodEnd}</span>
</div>
<div className="descTitle">税款所属期</div>
<div className="notice">{getMonth(taxCycleType)}</div>
<div className="descTitle">考勤取值周期</div>
<div>
<span className="notice">{getStartDate(attendCycleType, attendCycleFromDay)}</span>
<span className="notice">{attendCycleStrObj.date}</span>
<span className="notice">{selectInfo.attendCycleInfo.attendancePeriodStart}</span>
<span className="notice">{selectInfo.attendCycleInfo.attendancePeriodEnd}</span>
</div>
<div className="descTitle">福利台账月份</div>
<div>引用<span className="notice">{getMonth(socialSecurityCycleType)}</span></div>
</div>
</div>;
};
// 获取开始日期
const getStartDate = (salaryCycleType, day) => {
day = Number(day);
return getMonth(salaryCycleType) + "-" + (day < 10 ? "0" + day : day);
const buildEditBasicInfo = (editBasicInfo) => {
const { attendCycleType, salaryCycleType } = editBasicInfo;
const now = new Date();
let nowYear = now.getFullYear();
let nowMonth = now.getMonth() + 1;
let tmpV = {};
// 薪资联动
switch (salaryCycleType) {
case "1" :
tmpV["salaryCycleInfo"] = buildSalaryInfo(editBasicInfo, -2, nowYear, nowMonth);
break;
case "2" :
tmpV["salaryCycleInfo"] = buildSalaryInfo(editBasicInfo, -1, nowYear, nowMonth);
break;
case "3" :
tmpV["salaryCycleInfo"] = buildSalaryInfo(editBasicInfo, 0, nowYear, nowMonth);
break;
case "4" :
tmpV["salaryCycleInfo"] = buildSalaryInfo(editBasicInfo, 1, nowYear, nowMonth);
break;
}
// 考勤联动
switch (attendCycleType) {
case "1" :
tmpV["attendCycleInfo"] = buildAttendanceInfo(editBasicInfo, -2, nowYear, nowMonth);
break;
case "2" :
tmpV["attendCycleInfo"] = buildAttendanceInfo(editBasicInfo, -1, nowYear, nowMonth);
break;
case "3" :
tmpV["attendCycleInfo"] = buildAttendanceInfo(editBasicInfo, 0, nowYear, nowMonth);
break;
case "4" :
tmpV["attendCycleInfo"] = buildAttendanceInfo(editBasicInfo, 1, nowYear, nowMonth);
break;
}
return tmpV;
};
/*
* Author: 黎永顺
* Description:构建薪资周期联动信息
* Params:
* Date: 2023/4/17
*/
const buildSalaryInfo = (editBasicInfo, monthCal, nowYear, nowMonth) => {
const { salaryCycleFromDay } = editBasicInfo;
let salaryCycleFromDayNum = Number(salaryCycleFromDay), customInfo = {};
const basicInfo = generateBasicInfo(monthCal, nowYear, nowMonth);
const { nowMonthStr, nextMonthStr, year, month } = basicInfo;
customInfo.salaryYear = year;
customInfo.salaryMonth = month;
if (salaryCycleFromDayNum === 1) {
customInfo.salaryPeriodTip = "至" + nowMonthStr + "最后一天";
customInfo.salaryPeriodStart = customInfo.salaryYear + "-"
+ prefixAddZero(customInfo.salaryMonth, 2) + "-01";
customInfo.salaryPeriodEnd = customInfo.salaryYear + "-"
+ prefixAddZero(customInfo.salaryMonth, 2) + "-"
+ prefixAddZero(getMonthDays(customInfo.salaryYear, customInfo.salaryMonth), 2);
} else {
customInfo.salaryPeriodTip = "至" + nextMonthStr + (salaryCycleFromDayNum - 1) + "号";
customInfo.salaryPeriodStart = customInfo.salaryYear + "-"
+ prefixAddZero(customInfo.salaryMonth, 2) + "-" + prefixAddZero(salaryCycleFromDayNum, 2);
let year = customInfo.salaryYear;
let month = customInfo.salaryMonth;
if (month === "12") {
year = Number(year) + 1;
month = 1;
} else {
month = Number(month) + 1;
}
customInfo.salaryPeriodEnd = year + "-"
+ prefixAddZero(month, 2) + "-"
+ prefixAddZero(salaryCycleFromDayNum - 1, 2);
}
return customInfo;
};
const buildAttendanceInfo = (editBasicInfo, monthCal, nowYear, nowMonth) => {
const { attendCycleFromDay } = editBasicInfo;
let attendCycleFromDayNum = Number(attendCycleFromDay), customInfo = {};
const basicInfo = generateBasicInfo(monthCal, nowYear, nowMonth);
const { nowMonthStr, nextMonthStr } = basicInfo;
let year = basicInfo.year;
let month = basicInfo.month;
if (attendCycleFromDayNum === 1) {
customInfo.attendancePeriodTip = "至" + nowMonthStr + "最后一天";
customInfo.attendancePeriodStart = year + "-"
+ prefixAddZero(month, 2) + "-01";
customInfo.attendancePeriodEnd = year + "-"
+ prefixAddZero(month, 2) + "-"
+ prefixAddZero(getMonthDays(year, month), 2);
} else {
customInfo.attendancePeriodTip = "至" + nextMonthStr + (attendCycleFromDayNum - 1) + "号";
customInfo.attendancePeriodStart = year + "-"
+ prefixAddZero(month, 2) + "-" + prefixAddZero(attendCycleFromDayNum, 2);
if (month === "12") {
year = (Number(year) + 1).toString();
month = "1";
} else {
month = (Number(month) + 1).toString();
}
customInfo.attendancePeriodEnd = year + "-"
+ prefixAddZero(month, 2) + "-"
+ prefixAddZero(attendCycleFromDayNum - 1, 2);
}
return customInfo;
};
const getMonth = (salaryCycleType) => {
switch (salaryCycleType) {
case "1": // 上上月
@ -279,62 +379,3 @@ const getMonth = (salaryCycleType) => {
return getAddMonthYearMonth(1);
}
};
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 : 27, "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 : 27, "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 : 27, "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")
};
};

View File

@ -1,21 +1,89 @@
import moment from 'moment'
import moment from "moment";
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
// 获取当前年月
export const getCurrentYearMonth = () => {
return moment(new Date()).format("YYYY-MM")
}
return moment(new Date()).format("YYYY-MM");
};
// 获取当前月份
export const getCurrentMonth = () => {
return (new Date()).getMonth() + 1
}
return (new Date()).getMonth() + 1;
};
// 获取前几个月的年月
export const getSubtractMonthYearMonth = (subtract = 1) => {
return moment(new Date()).subtract(subtract,'months').startOf('month').format('YYYY-MM')
}
return moment(new Date()).subtract(subtract, "months").startOf("month").format("YYYY-MM");
};
// 获取后几个月的年月
export const getAddMonthYearMonth = (add = 1) => {
return moment(new Date()).add(add,'months').startOf('month').format('YYYY-MM')
}
return moment(new Date()).add(add, "months").startOf("month").format("YYYY-MM");
};
/**
* 数字前面补零
* @param num
* @param length
*/
export const prefixAddZero = (num, length) => {
return (Array(length).join("0") + num).slice(-length);
};
/**
* 获取月份天数
* @param year
* @param month
*/
export const getMonthDays = (year, month) => {
const d = new Date(Number(year), Number(month), 0);
return d.getDate();
};
export const generateBasicInfo = (monthCal, nowYear, nowMonth) => {
let nowMonthStr = "", nextMonthStr = "";
switch (monthCal) {
case -2:
nowMonthStr = getLabel(111, "上上月");
nextMonthStr = getLabel(111, "上月");
break;
case -1:
nowMonthStr = getLabel(111, "上月");
nextMonthStr = getLabel(111, "本月");
break;
case 0:
nowMonthStr = getLabel(111, "本月");
nextMonthStr = getLabel(111, "下月");
break;
case 1:
nowMonthStr = getLabel(111, "下月");
nextMonthStr = getLabel(111, "下下月");
break;
}
let year, month;
if (monthCal < 0) {
let monthCalAbs = Math.abs(monthCal);
if (nowMonth <= monthCalAbs) {
// 跨年
year = (nowYear - 1).toString();
month = (12 - (monthCalAbs - nowMonth)).toString();
} else {
// 未跨年
year = nowYear.toString();
month = (nowMonth - monthCalAbs).toString();
}
} else if (monthCal === 0) {
year = nowYear.toString();
month = nowMonth.toString();
} else {
if (nowMonth + monthCal > 12) {
year = (nowYear + 1).toString();
month = (nowMonth + monthCal - 12).toString();
} else {
year = nowYear.toString();
month = (nowMonth + monthCal).toString();
}
}
return { year, month, nowMonthStr, nextMonthStr };
};