salary-management-front/pc4mobx/hrmSalary/pages/externalPersonManage/components/externalPersonManageEditSli...

134 lines
4.2 KiB
JavaScript
Raw Normal View History

2023-03-13 10:43:25 +08:00
/*
* Author: 黎永顺
* name: 非系统人员管理表单项
* Description:
* Date: 2023/3/13
*/
import React, { Component } from "react";
import { WeaSlideModal } from "ecCom";
2023-03-13 14:40:19 +08:00
import { message } from "antd";
2023-03-17 11:00:58 +08:00
import { getConditionDomkeys, getSearchs } from "../../../util";
2023-03-13 10:43:25 +08:00
import SlideModalTitle from "../../../components/slideModalTitle";
2023-03-13 14:40:19 +08:00
import { detail, save, update } from "../../../apis/externalPersonManage";
2023-03-13 10:43:25 +08:00
class ExternalPersonManageEditSlide extends Component {
2023-03-13 14:40:19 +08:00
constructor(props) {
super(props);
this.state = {
date: "",
loading: false
};
}
componentWillReceiveProps(nextProps, nextContext) {
2023-03-14 18:14:23 +08:00
if (nextProps.visible !== this.props.visible && nextProps.visible && nextProps.id) this.detail(nextProps);
2023-03-13 14:40:19 +08:00
}
detail = (props) => {
2023-03-17 11:00:58 +08:00
const { form, id, condition } = props;
2023-03-13 14:40:19 +08:00
detail({ id }).then(({ status, data }) => {
if (status) {
form.updateFields({
"departmentId": {
2023-03-17 11:00:58 +08:00
value: data["departmentId"],
valueSpan: data["departmentOrgName"],
valueObj: [{ id: data["departmentId"], name: data["departmentOrgName"] }]
2023-03-13 14:40:19 +08:00
}
});
form.updateFields({
"subcompanyId": {
2023-03-17 11:00:58 +08:00
value: data["subcompanyId"],
valueSpan: data["subcompanyOrgName"],
valueObj: [{ id: data["subcompanyId"], name: data["subcompanyOrgName"] }]
2023-03-13 14:40:19 +08:00
}
});
2023-03-17 11:00:58 +08:00
// form.updateFields({
// "jobtitleId": {
// value: jobtitleId,
// valueSpan: data["jobtitleOrgName"],
// valueObj: [{ id: jobtitleId, name: data["jobtitleOrgName"] }]
// }
// });
_.map(_.without(getConditionDomkeys(condition), "departmentId", "subcompanyId"), item => {
form.updateFields({ [item]: { value: data[item] } }, false);
2023-03-13 14:40:19 +08:00
});
}
});
};
handleSubmit = () => {
2023-03-14 18:14:23 +08:00
const { form, id, onCancel, title } = this.props;
2023-03-13 14:40:19 +08:00
form.validateForm().then(f => {
if (f.isValid) {
2023-03-16 09:05:34 +08:00
const tmpV = _.reduce(_.keys(form.getFormDatas()), (pre, cur) => {
if (cur === "departmentId") {
return _.assign(pre, {
[cur]: form.getFormDatas()[cur].value,
departmentName: form.getFormDatas()["departmentId"].valueSpan
});
} else if (cur === "subcompanyId") {
return _.assign(pre, {
[cur]: form.getFormDatas()[cur].value,
subcompanyName: form.getFormDatas()["subcompanyId"].valueSpan
});
}
return _.assign(pre, { [cur]: form.getFormDatas()[cur].value });
}, {});
2023-03-17 11:00:58 +08:00
const payload = _.omitBy(form.getFormParams(), _.isNil);
2023-03-13 14:40:19 +08:00
this.setState({ loading: true });
const APIFOX = !id ? save : update;
APIFOX(id ? { ...payload, id } : payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
2023-03-14 18:14:23 +08:00
message.success(`${title}成功`);
2023-03-13 14:40:19 +08:00
onCancel(true);
} else {
2023-03-14 18:14:23 +08:00
message.error(errormsg || `${title}失败`);
2023-03-13 14:40:19 +08:00
}
}).catch(() => this.setState({ loading: false }));
} else {
f.showErrors();
this.setState({ date: new Date() });
}
});
};
2023-03-16 09:05:34 +08:00
handleFormChange = (res) => {
const { form, id } = this.props;
2023-03-17 11:00:58 +08:00
if (_.keys(res)[0] === "departmentId" || _.keys(res)[0] === "subcompanyId") {
2023-03-16 09:05:34 +08:00
const key = _.replace(_.keys(res)[0], "Id", "Name");
form.updateFields({ [key]: res[_.keys(res)[0]].valueSpan || "" });
}
};
2023-03-13 14:40:19 +08:00
2023-03-13 10:43:25 +08:00
render() {
2023-03-13 14:40:19 +08:00
const { loading } = this.state;
const { visible, title, onCancel, showOperateBtn, form, condition } = this.props;
2023-03-13 10:43:25 +08:00
return (
<WeaSlideModal
className="slideOuterWrapper"
visible={visible}
top={0}
measureT="%"
width={800}
measureX="px"
height={100}
measureY="%"
direction="right"
title={
<SlideModalTitle
subtitle={title}
editable={true}
2023-03-13 14:40:19 +08:00
loading={loading}
2023-03-13 10:43:25 +08:00
showOperateBtn={showOperateBtn}
2023-03-13 14:40:19 +08:00
onSave={this.handleSubmit}
2023-03-13 10:43:25 +08:00
/>
}
2023-03-16 09:05:34 +08:00
content={getSearchs(form, condition, 1, false, this.handleFormChange)}
2023-03-13 10:43:25 +08:00
onClose={onCancel}
/>
);
}
}
export default ExternalPersonManageEditSlide;