salary-management-front/pc4mobx/hrmSalary/pages/roleManagement/components/roleDetailSetDialog/editRoleDialog.js

156 lines
6.2 KiB
JavaScript
Raw Normal View History

2024-08-20 18:07:03 +08:00
/*
2024-09-10 12:23:18 +08:00
* 编辑角色操作者
2024-08-20 18:07:03 +08:00
*
* @Author: 黎永顺
* @Date: 2024/8/20
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
2024-08-21 16:00:28 +08:00
import { WeaDialog, WeaLocaleProvider, WeaTools } from "ecCom";
2024-08-20 18:07:03 +08:00
import { Button } from "antd";
import { roleOperatorConditions } from "../conditions";
import { getSearchs } from "../../../../util";
const getLabel = WeaLocaleProvider.getLabel;
2024-08-21 16:00:28 +08:00
const getKey = WeaTools.getKey;
2024-08-20 18:07:03 +08:00
@inject("taxAgentStore")
@observer
class EditRoleDialog extends Component {
constructor(props) {
super(props);
this.state = {
2024-09-10 12:23:18 +08:00
conditions: [], loading: false, targetSob: {}
2024-08-20 18:07:03 +08:00
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) {
this.setState({
conditions: _.map(roleOperatorConditions, item => ({
2024-08-21 16:00:28 +08:00
...item, items: _.map(item.items, o => {
o = { ...o, label: getLabel(o.lanId, o.label), value: String(nextProps.record[getKey(o)]) };
switch (getKey(o)) {
case "link":
o = { ...o, options: nextProps.linkOptions, hide: _.isEmpty(nextProps.linkOptions) };
break;
case "sortedIndex":
o = { ...o, hide: _.isEmpty(nextProps.linkOptions) };
break;
case "targetName":
o = ["EMP", "DEPARTMENT", "JOB", "SUB_COMPANY", "ROLE"].includes(nextProps.record.targetType) ?
{
...o, value: "", browserConditionParam: {
...this.renderBrowserType(nextProps.record.targetType),
replaceDatas: [{ id: nextProps.record["target"], name: nextProps.record[getKey(o)] }]
}
} :
nextProps.record.targetType === "SQL" ? {
...o, conditionType: "TEXTAREA", otherParams: { minRows: 3 }
} : nextProps.record.targetType === "LEVEL" ?
{
...o, startValue: nextProps.record[getKey(o)].split("-")[0],
endValue: nextProps.record[getKey(o)].split("-")[1],
conditionType: "SCOPE", precision: 0
2024-09-14 14:28:58 +08:00
} : (nextProps.record.targetType === "SOB" ||
nextProps.record.targetType === "TAX") ? {
2024-09-10 12:23:18 +08:00
...o, value: nextProps.record["target"],
conditionType: "CUSTOMBROWSER", browserConditionParam: {
2024-09-14 14:28:58 +08:00
completeURL: nextProps.record.targetType === "SOB" ?
"/api/bs/hrmsalary/salarysob/listAuth" : "/api/bs/hrmsalary/taxAgent/listAuth",
2024-09-10 12:23:18 +08:00
dataParams: { filterType: "QUERY_DATA" },
filterByName: true, isSingle: true,
tableProps: {}, searchParamsKey: "name",
replaceDatas: [{ id: nextProps.record["target"], name: nextProps.record["targetName"] }]
}
2024-08-21 16:00:28 +08:00
} : { ...o };
break;
default:
break;
}
return o;
})
2024-09-14 14:28:58 +08:00
})),
targetSob: { id: nextProps.record["target"], name: nextProps.record["targetName"] }
2024-08-20 18:07:03 +08:00
}, () => nextProps.taxAgentStore.roleOperatorForm.initFormFields(this.state.conditions));
}
2024-09-10 12:23:18 +08:00
if (nextProps.visible !== this.props.visible && !nextProps.visible) {
this.setState({ targetSob: {} });
nextProps.taxAgentStore.initRoleOperatorForm();
}
2024-08-21 16:00:28 +08:00
if (nextProps.loading !== this.props.loading && !nextProps.loading) this.props.onCancel();
2024-08-20 18:07:03 +08:00
}
2024-08-21 16:00:28 +08:00
renderBrowserType = (enumType) => {
let browserType = {};
switch (enumType) {
case "EMP":
browserType = { ...browserType, type: 17, isSingle: true, title: getLabel(82246, "人员选择") };
break;
case "DEPARTMENT":
browserType = { ...browserType, type: 57, isSingle: true, title: getLabel(111, "部门选择") };
break;
case "JOB":
browserType = { ...browserType, type: 278, isSingle: true, title: getLabel(111, "岗位选择") };
break;
case "SUB_COMPANY":
browserType = { ...browserType, type: 164, isSingle: true, title: getLabel(111, "分部选择") };
break;
case "ROLE":
browserType = { ...browserType, type: 65, isSingle: true, title: getLabel(111, "角色选择") };
break;
default:
break;
}
return browserType;
};
save = () => {
2024-09-10 12:23:18 +08:00
const { targetSob } = this.state;
2024-08-21 16:00:28 +08:00
const { taxAgentStore: { roleOperatorForm }, record, onChange } = this.props;
roleOperatorForm.validateForm().then(f => {
if (f.isValid) {
const { targetName: __, link, sortedIndex } = roleOperatorForm.getFormParams();
const targetName = roleOperatorForm.getFormDatas().targetName;
onChange([_.assign(record, {
editId: record.id, sortedIndex,
id: record.targetType === "LEVEL" ? targetName.value.join("-") : targetName.value,
name: record.targetType === "SQL" ? __ :
2024-09-10 12:23:18 +08:00
record.targetType === "LEVEL" ? __.join("-") : (targetName.valueSpan || targetSob.name),
2024-08-21 16:00:28 +08:00
link: link === "undefined" ? "OR" : link
})]);
} else {
f.showErrors();
}
});
};
2024-09-10 12:23:18 +08:00
handleFormChange = (val) => {
const { record } = this.props;
const key = _.keys(val)[0];
2024-09-14 14:28:58 +08:00
if (key === "targetName" && (record.targetType === "SOB" || record.targetType === "TAX"))
this.setState({ targetSob: _.head(val[key]) });
2024-09-10 12:23:18 +08:00
};
2024-08-21 16:00:28 +08:00
2024-08-20 18:07:03 +08:00
render() {
2024-08-21 16:00:28 +08:00
const { conditions } = this.state;
const { taxAgentStore: { roleOperatorForm }, linkOptions, loading } = this.props;
2024-08-20 18:07:03 +08:00
return (
<WeaDialog
2024-08-21 16:00:28 +08:00
{...this.props} style={{ width: 480, height: _.isEmpty(linkOptions) ? 129 : 223 }}
initLoadCss title={getLabel(111, "编辑操作者")}
2024-08-20 18:07:03 +08:00
buttons={[
2024-08-21 16:00:28 +08:00
<Button type="primary" loading={loading} onClick={this.save}>{getLabel(111, "保存")}</Button>
2024-08-20 18:07:03 +08:00
]}
>
2024-09-10 12:23:18 +08:00
<div className="form-dialog-layout">
{getSearchs(roleOperatorForm, conditions, 1, false, this.handleFormChange)}
</div>
2024-08-20 18:07:03 +08:00
</WeaDialog>
);
}
}
export default EditRoleDialog;