diff --git a/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerBaseSetting.js b/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerBaseSetting.js
index cfe0f90b..2da6a2ac 100644
--- a/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerBaseSetting.js
+++ b/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerBaseSetting.js
@@ -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
{
_.map(list, item => {
@@ -221,20 +226,12 @@ const CustomSelect = (props) => {
})
}
{inputStr === "salaryCycleStrObj" ? salaryCycleStrObj.inputStr : attendCycleStrObj.inputStr}
+ className="desc">{inputStr === "salaryCycleStrObj" ? selectInfo.salaryCycleInfo.salaryPeriodTip : selectInfo.attendCycleInfo.attendancePeriodTip}
;
};
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
月份周期说明
@@ -245,28 +242,131 @@ const MonthCycleDesc = (props) => {
根据您当前的选择,相应的周期为:
薪资周期
- {getStartDate(salaryCycleType, salaryCycleFromDay)}至
- {salaryCycleStrObj.date}
+ {selectInfo.salaryCycleInfo.salaryPeriodStart}至
+ {selectInfo.salaryCycleInfo.salaryPeriodEnd}
税款所属期
{getMonth(taxCycleType)}
考勤取值周期
- {getStartDate(attendCycleType, attendCycleFromDay)}至
- {attendCycleStrObj.date}
+ {selectInfo.attendCycleInfo.attendancePeriodStart}至
+ {selectInfo.attendCycleInfo.attendancePeriodEnd}
福利台账月份
引用{getMonth(socialSecurityCycleType)}的福利台账数据
;
};
-
-// 获取开始日期
-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")
- };
-};
diff --git a/pc4mobx/hrmSalary/util/date.js b/pc4mobx/hrmSalary/util/date.js
index e014265e..e82f9039 100644
--- a/pc4mobx/hrmSalary/util/date.js
+++ b/pc4mobx/hrmSalary/util/date.js
@@ -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')
-}
\ No newline at end of file
+ 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 };
+};