salary-management-front/pc4mobx/hrmSalary/pages/salary/components/personalScopeModal.js

168 lines
7.2 KiB
JavaScript
Raw Normal View History

2024-10-08 14:08:16 +08:00
/*
* Author: 黎永顺
* name: 新增人员范围弹框
* Description:
* Date: 2022/11/30
*/
import React, { Component } from "react";
2024-10-09 14:51:55 +08:00
import { inject, observer } from "mobx-react";
2024-10-11 10:01:46 +08:00
import { WeaSwitch } from "comsMobx";
2025-03-11 09:38:06 +08:00
import { WeaCheckbox, WeaDialog, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaSearchGroup, WeaTools } from "ecCom";
2024-10-11 11:11:06 +08:00
import { Button, message } from "antd";
import { getTaxAgentRangeForm, taxAgentRangeEdit, taxAgentRangeSave } from "../../../apis/taxAgent";
2024-10-11 10:01:46 +08:00
import { personScopeConditions, scopeSelectLinkageDatas } from "./constants";
2024-10-08 14:08:16 +08:00
2024-10-09 14:51:55 +08:00
const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;
@inject("taxAgentStore")
@observer
2024-10-08 14:08:16 +08:00
class PersonalScopeModal extends Component {
constructor(props) {
super(props);
this.state = {
2024-10-11 15:19:38 +08:00
loading: false, conditions: [], employeeStatus: []
2024-10-08 14:08:16 +08:00
};
}
2024-10-09 14:51:55 +08:00
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) this.getTaxAgentRangeForm(nextProps);
2024-10-11 10:01:46 +08:00
if (nextProps.visible !== this.props.visible && !nextProps.visible) this.props.taxAgentStore.initPersonScopeForm();
2024-10-09 14:51:55 +08:00
}
getTaxAgentRangeForm = (props) => {
const { record } = props;
2024-10-08 14:08:16 +08:00
getTaxAgentRangeForm().then(({ status, data }) => {
if (status) {
const { employeeStatus, targetTypeList } = data;
this.setState({
2024-10-09 17:02:14 +08:00
employeeStatus, conditions: _.map(personScopeConditions, item => ({
2024-10-09 14:51:55 +08:00
...item, items: _.map(item.items, o => {
if (getKey(o) === "employeeStatus") {
return {
...o, label: getLabel(o.lanId, o.label), value: !_.isEmpty(record) ? record.status : "",
2024-10-11 10:01:46 +08:00
options: _.map(employeeStatus, it => ({ key: it.id, showname: it.name }))
2024-10-09 14:51:55 +08:00
};
}
return {
...o, label: getLabel(o.lanId, o.label), viewAttr: !_.isEmpty(record) ? 1 : 3,
2024-10-11 11:11:06 +08:00
options: _.map(targetTypeList, it => ({
key: it.id, showname: it.name,
selected: !_.isEmpty(record) ? it.id === record.targetType : it.id === "EMPLOYEE"
2024-10-11 11:11:06 +08:00
})),
selectLinkageDatas: {
..._.reduce(_.keys(scopeSelectLinkageDatas), (pre, cur) => {
if (cur !== "SQL") {
return {
...pre,
[cur]: {
...scopeSelectLinkageDatas[cur],
browserConditionParam: {
...scopeSelectLinkageDatas[cur].browserConditionParam,
replaceDatas: !_.isEmpty(record) ? [{
id: String(record.targetId),
name: record.targetName
}] : []
}
}
};
}
return {
...pre, [cur]: { ...scopeSelectLinkageDatas[cur], value: !_.isEmpty(record) ? record.target : "" }
};
}, {})
}
2024-10-09 14:51:55 +08:00
};
})
}))
}, () => this.props.taxAgentStore.personScopeForm.initFormFields(this.state.conditions));
2024-10-08 14:08:16 +08:00
}
});
};
taxAgentRangeSave = () => {
const { taxAgentStore: { personScopeForm }, record = {} } = this.props;
2024-10-11 10:01:46 +08:00
personScopeForm.validateForm().then(f => {
if (f.isValid) {
2024-10-11 11:11:06 +08:00
const { employeeStatus, targetType, target } = personScopeForm.getFormParams();
const { includeType, taxAgentId } = this.props;
2024-10-11 10:01:46 +08:00
const payload = {
includeType, taxAgentId, employeeStatus: employeeStatus.split(","), id: record.id,
2024-10-11 15:19:38 +08:00
targetParams: _.map(target.split(","), it => ({
targetType, targetId: targetType === "SQL" ? "0" : it,
target: targetType === "SQL" ? target : ""
}))
2024-10-11 10:01:46 +08:00
};
this.setState({ loading: true });
const API = !_.isEmpty(record) ? taxAgentRangeEdit : taxAgentRangeSave;
API(payload).then(({ status, errormsg }) => {
2024-10-11 10:01:46 +08:00
this.setState({ loading: false });
if (status) {
2024-10-11 11:11:06 +08:00
message.success(getLabel(111, "操作成功!"));
this.props.onCancel(this.props.onSuccess);
2024-10-11 10:01:46 +08:00
} else {
2024-10-11 11:11:06 +08:00
message.error(errormsg);
2024-10-11 10:01:46 +08:00
}
}).catch(() => this.setState({ loading: true }));
2024-10-08 14:08:16 +08:00
} else {
2024-10-11 10:01:46 +08:00
f.showErrors();
2024-10-08 14:08:16 +08:00
}
2024-10-11 10:01:46 +08:00
});
2024-10-08 14:08:16 +08:00
};
2024-10-11 10:01:46 +08:00
renderForm = () => {
const { taxAgentStore: { personScopeForm } } = this.props;
const { conditions, employeeStatus } = this.state, { isFormInit } = personScopeForm,
formParams = personScopeForm.getFormParams();
const checked = formParams.employeeStatus && _.every(_.map(employeeStatus, o => o.id), k => formParams.employeeStatus.indexOf(k) !== -1);
let group = [];
isFormInit && conditions.map(c => {
let items = [];
c.items.map(fields => {
items.push({
com: (
<WeaFormItem label={`${fields.label}`} labelCol={{ span: `${fields.labelcol}` }}
wrapperCol={{ span: `${fields.fieldcol}` }} error={personScopeForm.getError(fields)}
tipPosition="bottom">
{
getKey(fields) === "employeeStatus" &&
<WeaCheckbox value={checked ? "1" : "0"} content={getLabel(111, "全选")}
onChange={this.handleChangeAll}/>
}
2024-10-11 11:11:06 +08:00
<WeaSwitch fieldConfig={fields} form={personScopeForm} formParams={formParams}/>
2025-03-11 09:38:06 +08:00
{
personScopeForm.getFormParams().targetType === "SQL" && getKey(fields) === "targetType" &&
<WeaHelpfulTip placement="topLeft" style={{ position: "absolute", top: "50%", right: "-35px" }}
width={200} title={
<span
dangerouslySetInnerHTML={{ __html: getLabel(111, "注意事项:<br>1、sql需返回人员id<br>2、sql结尾不需要 ; go /等符号<br>使用例子:定义获取岗位是开发的人员<br>select id from hrmresource where JOBTITLE = 17") }}/>
}/>
}
2024-10-11 10:01:46 +08:00
</WeaFormItem>),
hide: fields.hide
});
});
group.push(<WeaSearchGroup col={1} needTigger showGroup={c.defaultshow} items={items}/>);
});
return group;
};
handleChangeAll = (val) => {
const { taxAgentStore: { personScopeForm } } = this.props, { employeeStatus } = this.state;
val === "1" ? personScopeForm.updateFields({ employeeStatus: { value: _.map(employeeStatus, o => o.id).join(",") } }) :
personScopeForm.updateFields({ employeeStatus: { value: "" } });
};
2024-10-08 14:08:16 +08:00
render() {
2024-10-11 15:19:38 +08:00
const { title, taxAgentStore: { personScopeForm } } = this.props, { loading } = this.state;
2024-10-08 14:08:16 +08:00
const buttons = [
2024-10-11 15:19:38 +08:00
<Button type="primary" onClick={this.taxAgentRangeSave} loading={loading}>{getLabel(111, "确定")}</Button>,
<Button type="ghost" onClick={() => personScopeForm.resetForm()}>{getLabel(111, "重置")}</Button>
2024-10-08 14:08:16 +08:00
];
return (
<WeaDialog {...this.props} initLoadCss title={title} style={{ width: 600, height: 159 }} buttons={buttons}>
2024-10-11 10:01:46 +08:00
<div className="form-dialog-layout">{this.renderForm()}</div>
2024-10-08 14:08:16 +08:00
</WeaDialog>
);
}
}
export default PersonalScopeModal;