import React from "react"; import {Col, Row} from "antd"; import {WeaCheckbox, WeaInput, WeaSelect, WeaTextarea} from "ecCom"; import "./index.less"; import TipLabel from "../../components/TipLabel"; import {cycleTypeOption, daysOptions} from "./options"; import {inject, observer} from "mobx-react"; import RequiredLabelTip from "../../components/requiredLabelTip"; import {getAddMonthYearMonth, getCurrentMonth, getCurrentYearMonth, getSubtractMonthYearMonth} from "../../util/date"; import moment from "moment"; @inject("ledgerStore", "taxAgentStore") @observer export default class SlideBaseForm extends React.Component { constructor(props) { super(props); this.state = { name: "", taxableItems: 1 }; } componentWillMount() { const {edit} = this.props; const {ledgerStore: {initBaseInfoRequest}} = this.props; if (edit) { const {ledgerStore: {getLedgerBasicForm}} = this.props; getLedgerBasicForm(); } else { initBaseInfoRequest(); } } handleChange(params) { const {ledgerStore: {baseInfoRequest, setBaseInfoRequest}} = this.props; let request = {...baseInfoRequest}; Object.keys(params).map(key => { request[key] = params[key]; }); setBaseInfoRequest(request); } // 获取开始日期 getStartDate(salaryCycleType, day) { day = Number(day); return this.getMonth(salaryCycleType) + "-" + (day < 10 ? "0" + day : day); } // 获取开始月份 getMonth(salaryCycleType) { switch (salaryCycleType) { case "1": // 上上月 return getSubtractMonthYearMonth(2); case "2": // 上月 return getSubtractMonthYearMonth(1); case "3": // 本月 return getCurrentYearMonth(); case "4": // 下月 return getAddMonthYearMonth(1); } } initPeriodStr = (periodStrType, type, fromDay) => { let str = "", tmpDate = null; switch (type) { 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") }; }; render() { const {request, ledgerStore, taxAgentStore, edit} = this.props; const {baseInfoRequest} = ledgerStore; const {taxAgentAdminOption} = taxAgentStore; const { canEdit = "true", name, taxAgentId, taxableItems, salaryCycleType, salaryCycleFromDay, taxCycleType, attendCycleType, attendCycleFromDay, socialSecurityCycleType, description } = baseInfoRequest; const salaryCycleStrObj = this.initPeriodStr("salaryCycleStr", salaryCycleType, salaryCycleFromDay); const attendCycleStrObj = this.initPeriodStr("attendCycleStr", attendCycleType, attendCycleFromDay); return (
例:薪资所属月是 {getCurrentYearMonth()} (即核算员工 {getCurrentMonth()} 月的工资)
根据您当前的选择,相应的周期为:
{this.getStartDate(salaryCycleType, salaryCycleFromDay)} 至 {salaryCycleStrObj.date}
{this.getMonth(taxCycleType)}
{this.getStartDate(attendCycleType, attendCycleFromDay)} 至 {attendCycleStrObj.date}
引用 {this.getMonth(socialSecurityCycleType)} 的福利台账数据