import React from "react"; import { WeaCheckbox, WeaFormItem, WeaHelpfulTip, WeaInput, WeaInputNumber, WeaLocaleProvider, WeaSearchGroup, WeaSelect, WeaTimePicker } from "ecCom"; import { inject, observer } from "mobx-react"; import { getReplenishRuleSetOptions } from "../../../apis/payroll"; import { commonEnumList } from "../../../apis/payrollFiles"; import moment from "moment"; import { toJS } from "mobx"; import "./index.less"; const getLabel = WeaLocaleProvider.getLabel; @inject("payrollStore") @observer export default class BaseInformForm extends React.Component { constructor(props) { super(props); this.state = { inited: false, options: [], replenishRuleOptions: [], salaryMonthOptions: [], request: {} }; } componentWillMount() { const { payrollStore } = this.props; const { getPayrollBaseForm } = payrollStore; const templateBaseData = window.localStorage.getItem("template-basedata") || "{}"; this.commonEnumList(); getPayrollBaseForm(this.props.id).then(data => { this.setState( { replenishRuleOptions: _.map(data.replenishRuleSetOption, it => ({ key: it.id, showname: it.content })), options: _.isEmpty(toJS(data.salarySobOptions)) ? [{ key: "", showname: "" }] : [{ key: "", showname: "" }, ...toJS(data.salarySobOptions)], request: { ...data.templateBaseData, msgStatus: !this.props.id ? "1" : data.templateBaseData.msgStatus, reissueRule: data.templateBaseData.replenishRule ? "1" : "0", ...JSON.parse(templateBaseData), sendEmail: "", autoSendStatus: !_.isNil(data.templateBaseData.autoSendStatus) ? data.templateBaseData.autoSendStatus : false } }, () => { this.props.onChange && this.props.onChange(this.state.request); this.setState({ inited: true }); } ); }); JSON.parse(templateBaseData).salarySob && this.getReplenishRuleSetOptions({ salarySobId: JSON.parse(templateBaseData).salarySob }); } handleChange = (params) => { let request = { ...this.state.request, ...params }; this.setState({ request }, () => { if (this.state.request.reissueRule === "1" && this.state.request.salarySob) { // TODO:获取规则设置枚举项 this.getReplenishRuleSetOptions(); } }); this.props.onChange && this.props.onChange(request); }; getReplenishRuleSetOptions = (params = {}) => { const { request } = this.state; getReplenishRuleSetOptions({ salarySobId: request.salarySob, ...params }).then(({ status, data }) => { if (status && !_.isEmpty(data)) { this.setState({ replenishRuleOptions: _.map(data, it => ({ key: it.id, showname: it.content })) }); } }); }; commonEnumList = () => { commonEnumList({ enumClass: "com.engine.salary.enums.salarysend.SalaryAutoSendCycleTypeEnum" }) .then(({ status, data }) => { if (status && !_.isEmpty(data)) { this.setState({ salaryMonthOptions: _.map(data, it => ({ key: it.value.toString(), showname: it.defaultLabel })) }); } }); }; render() { const { request, options, replenishRuleOptions, salaryMonthOptions } = this.state; const { salarySob, name, description, replenishName, replenishRule, reissueRule, msgStatus, emailStatus, ackFeedbackStatus, autoAckDays, feedbackUrl, autoSendStatus, autoSendDayOfMonth, autoSendTimeOfDay, autoSendCycleType } = request; return ( { this.state.inited && this.handleChange({ salarySob: value })}/> } this.handleChange({ name: value })} /> this.handleChange({ replenishName: value })} /> this.handleChange({ reissueRule: value })} /> { reissueRule !== "0" && this.handleChange({ replenishRule: value })} /> } this.handleChange({ description: value })} /> this.handleChange({ msgStatus: value === "1" })}/> this.handleChange({ emailStatus: value === "1" })}/> { this.handleChange({ autoSendStatus: value === "1", autoSendDayOfMonth: value === "1" ? "1" : null, autoSendTimeOfDay: value === "1" ? "09:00" : null, autoSendCycleType: value === "1" ? 1 : null }); }}/> { autoSendStatus && } this.handleChange({ ackFeedbackStatus: value === "1", autoAckDays: 7, feedbackUrl: "/" })}/> { ackFeedbackStatus && this.handleChange({ autoAckDays })} /> this.handleChange({ feedbackUrl })} /> } ); } } const SendTimeComp = (props) => { const { value, onChange, salaryMonthOptions } = props; const { autoSendDayOfMonth, autoSendTimeOfDay, autoSendCycleType } = value; const handleChangeSendtime = (key, val) => { onChange({ autoSendDayOfMonth, autoSendTimeOfDay, autoSendCycleType, [key]: val }); }; return
{getLabel(542604, "薪资所属月")} handleChangeSendtime("autoSendCycleType", Number(v))} /> ({ key: item, showname: item }))} onChange={v => handleChangeSendtime("autoSendDayOfMonth", v)} /> {getLabel(16992, "号")}
handleChangeSendtime("autoSendTimeOfDay", v)}/>
; }; const getDay = (num = 1) => { let days = []; let day = getDaysInMonth(moment().year(), moment().month() + num); for (let i = 1; i <= day; i++) { days.push(i); } return days; }; const getDaysInMonth = (year, month) => { month = parseInt(month, 10); let d = new Date(year, month, 0); return d.getDate(); };