90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
/*
|
|
* Author: 黎永顺
|
|
* name: 新建考勤自定义字段
|
|
* Description:
|
|
* Date: 2023/3/1
|
|
*/
|
|
import React, { Component } from "react";
|
|
import { inject, observer } from "mobx-react";
|
|
import { WeaDialog, WeaLocaleProvider, WeaTools } from "ecCom";
|
|
import { Button, message } from "antd";
|
|
import { conditions } from "../columns";
|
|
import { getSearchs } from "../../../../util";
|
|
import { saveAttendanceField } from "../../../../apis/attendance";
|
|
import "./index.less";
|
|
|
|
const getKey = WeaTools.getKey;
|
|
const getLabel = WeaLocaleProvider.getLabel;
|
|
|
|
@inject("attendanceStore")
|
|
@observer
|
|
class AttendanceCustomFieldsModal extends Component {
|
|
componentDidMount() {
|
|
const { attendanceStore: { form } } = this.props;
|
|
form.initFormFields(_.map(conditions, item => {
|
|
return {
|
|
...item,
|
|
items: _.map(item.items, o => {
|
|
if (getKey(o) === "fieldType") {
|
|
return {
|
|
...o, label: getLabel(o.lanId, o.label),
|
|
options: _.map(o.options, g => ({ ...g, showname: getLabel(g.lanId, g.showname) }))
|
|
};
|
|
}
|
|
return { ...o, label: getLabel(o.lanId, o.label) };
|
|
})
|
|
};
|
|
}));
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps, nextContext) {
|
|
const { attendanceStore: { initForm } } = nextProps;
|
|
if (nextProps.visible !== this.props.visible && nextProps.visible) this.handleResetForm();
|
|
if (nextProps.visible !== this.props.visible && !nextProps.visible) initForm();
|
|
}
|
|
|
|
/*
|
|
* Author: 黎永顺
|
|
* Description: 保存考勤字段
|
|
* Params:
|
|
* Date: 2023/3/1
|
|
*/
|
|
handleSubmitFields = () => {
|
|
const { attendanceStore: { form }, onRefresh, onCancel } = this.props;
|
|
form.validateForm().then(f => {
|
|
if (f.isValid) {
|
|
const payload = form.getFormParams();
|
|
saveAttendanceField(payload).then(({ status, errormsg }) => {
|
|
if (status) {
|
|
message.success(getLabel(528075, "新增成功"));
|
|
onCancel();
|
|
onRefresh();
|
|
} else {
|
|
message.error(errormsg || getLabel(543346, "新增失败"));
|
|
}
|
|
});
|
|
} else {
|
|
f.showErrors();
|
|
}
|
|
});
|
|
};
|
|
handleResetForm = () => {
|
|
const { attendanceStore: { form } } = this.props;
|
|
form.updateFields({ fieldName: "", fieldType: "NUMBER", enableStatus: "0", description: "" });
|
|
};
|
|
|
|
render() {
|
|
const { attendanceStore: { form } } = this.props;
|
|
const buttons = [
|
|
<Button type="primary" onClick={this.handleSubmitFields}>{getLabel(537558, "保存")}</Button>
|
|
];
|
|
return (
|
|
<WeaDialog {...this.props} style={{ width: 480, height: 202 }} buttons={buttons} initLoadCss>
|
|
<div className="form-dialog-layout"> {getSearchs(form, conditions, 1)}</div>
|
|
</WeaDialog>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default AttendanceCustomFieldsModal;
|