salary-management-front/pc4mobx/hrmSalary/pages/fieldManagement/components/fieldSlide.js

346 lines
11 KiB
JavaScript
Raw Normal View History

2023-01-28 10:10:00 +08:00
/*
* Author: 黎永顺
* name: 编辑新增字段弹框
* Description:
* Date: 2023/1/19
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import {
WeaCheckbox,
WeaFormItem,
WeaHelpfulTip,
WeaInput,
WeaInputNumber,
WeaLocaleProvider,
WeaSelect,
WeaSlideModal,
WeaTextarea
} from "ecCom";
2023-01-28 13:42:32 +08:00
import { message, Modal } from "antd";
2023-01-28 10:10:00 +08:00
import SlideModalTitle from "../../../components/slideModalTitle";
2023-01-28 13:42:32 +08:00
import { getSalaryFieldForm, saveSalaryField } from "../../../apis/fieldManage";
2023-01-28 10:10:00 +08:00
import { commonEnumList } from "../../../apis/payrollFiles";
import { dataTypeOptions, patternOptions, roundingModeOptions } from "../../salaryItem/options";
const getLabel = WeaLocaleProvider.getLabel;
2023-01-28 10:10:00 +08:00
@inject("taxAgentStore")
@observer
class FieldSlide extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
2023-01-28 13:42:32 +08:00
name: "",
2023-02-10 11:13:29 +08:00
useInEmployeeSalary: "1",
useDefault: "0",
2023-08-16 10:30:37 +08:00
hideDefault: "0",
2023-02-10 11:01:51 +08:00
sharedType: "0",
2023-01-28 10:10:00 +08:00
shareTypeList: [],
taxAgentIds: "",
dataType: "number",
2023-02-10 11:01:51 +08:00
roundingMode: "1",
2023-01-31 10:25:07 +08:00
pattern: "2",
sortedIndex: "",
2023-01-28 13:42:32 +08:00
description: ""
2023-01-28 10:10:00 +08:00
};
}
componentDidMount() {
const { taxAgentStore } = this.props;
this.commonEnumList();
2023-02-15 16:54:23 +08:00
const { fetchTaxAgentOption } = taxAgentStore;
fetchTaxAgentOption();
2023-01-28 10:10:00 +08:00
}
2023-01-28 13:42:32 +08:00
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.record.id !== this.props.record.id && nextProps.record.id) {
this.getSalaryFieldForm(nextProps.record.id);
2023-01-28 13:42:32 +08:00
}
}
getSalaryFieldForm = (id) => {
getSalaryFieldForm({ id }).then(({ status, data }) => {
if (status) {
const { onChangeRecord } = this.props;
const {
name,
useDefault,
hideDefault,
useInEmployeeSalary,
dataType,
description,
sortedIndex,
sharedType,
roundingMode,
taxAgentIds,
pattern
} = data;
onChangeRecord(data);
2023-01-28 13:42:32 +08:00
this.setState({
name,
useInEmployeeSalary: useInEmployeeSalary ? useInEmployeeSalary.toString() : "0",
2023-01-28 13:42:32 +08:00
useDefault: useDefault ? useDefault.toString() : "0",
hideDefault: hideDefault ? hideDefault.toString() : "0",
2023-01-28 13:42:32 +08:00
dataType,
description,
sortedIndex,
2023-01-28 13:42:32 +08:00
sharedType: sharedType ? sharedType.toString() : "0",
roundingMode: roundingMode ? roundingMode.toString() : "0",
taxAgentIds,
pattern: pattern ? pattern.toString() : "0"
});
}
});
};
2023-01-28 10:10:00 +08:00
/*
* Author: 黎永顺
* Description: 获取可见性列表
* Params:
* Date: 2023/1/28
*/
commonEnumList = () => {
const payload = {
enumClass: "com.engine.salary.enums.sicategory.SharedTypeEnum"
2023-01-28 13:42:32 +08:00
};
2023-01-28 10:10:00 +08:00
commonEnumList(payload).then(({ status, data }) => {
if (status) {
const result = _.map(data, it => ({
key: String(it.value),
showname: it.defaultLabel
}));
this.setState({
2023-02-10 11:01:51 +08:00
shareTypeList: result
2023-01-28 10:10:00 +08:00
});
}
});
};
/*
* Author: 黎永顺
2023-01-28 13:42:32 +08:00
* Description: 保存字段信息
2023-01-28 10:10:00 +08:00
* Params:
* Date: 2022/12/12
*/
2023-01-28 13:42:32 +08:00
saveFieldInfo = () => {
2023-02-10 11:40:07 +08:00
if (_.isEmpty(this.state.name) || (this.state.sharedType === "1" && _.isEmpty(this.state.taxAgentIds))) {
2023-01-28 10:10:00 +08:00
Modal.warning({
title: "信息确认",
content: "必要信息不完整,红色*为必填项!"
});
return false;
}
const { onRefreshList, onCancel, record } = this.props;
const {
name,
useDefault,
hideDefault,
useInEmployeeSalary,
dataType,
description,
sortedIndex,
sharedType,
roundingMode,
taxAgentIds,
pattern
} = this.state;
2023-01-28 10:10:00 +08:00
const payload = {
2023-01-28 13:42:32 +08:00
name,
useInEmployeeSalary: Number(useInEmployeeSalary),
2023-01-28 13:42:32 +08:00
useDefault: Number(useDefault),
hideDefault: Number(hideDefault),
2023-01-28 13:42:32 +08:00
dataType,
description,
sortedIndex,
2023-01-28 13:42:32 +08:00
sharedType,
roundingMode: Number(roundingMode),
taxAgentIds,
pattern: Number(pattern)
2023-01-28 10:10:00 +08:00
};
this.setState({ loading: true });
saveSalaryField({ ...record, ...payload }).then(({ status, errormsg }) => {
2023-01-28 10:10:00 +08:00
this.setState({ loading: false });
if (status) {
2023-01-28 13:42:32 +08:00
onRefreshList();
onCancel();
this.handleReset();
2023-01-28 10:10:00 +08:00
message.success("保存成功");
} else {
message.error(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
2023-01-28 13:42:32 +08:00
* Description: 字段项修改
2023-01-28 10:10:00 +08:00
* Params:
* Date: 2022/12/14
*/
2023-01-28 13:42:32 +08:00
handleChangeFields = (type, value) => {
this.setState({ [type]: value });
};
handleReset = () => {
this.setState({
name: "",
2023-02-10 11:13:29 +08:00
useInEmployeeSalary: "1",
useDefault: "0",
hideDefault: "0",
2023-02-10 11:01:51 +08:00
sharedType: "0",
2023-01-28 13:42:32 +08:00
taxAgentIds: "",
dataType: "number",
2023-02-10 11:01:51 +08:00
roundingMode: "1",
2023-01-31 10:14:10 +08:00
pattern: "2",
sortedIndex: "",
2023-01-28 13:42:32 +08:00
description: ""
});
2023-01-28 10:10:00 +08:00
};
render() {
2023-02-22 10:39:47 +08:00
const {
title,
visible,
record: { id: editId },
taxAgentStore: { taxAgentOption, showSalaryItemBtn, showOperateBtn },
2023-02-22 10:39:47 +08:00
onCancel
} = this.props;
2023-01-28 13:42:32 +08:00
const {
loading,
name,
useInEmployeeSalary,
2023-01-28 13:42:32 +08:00
useDefault,
hideDefault,
2023-01-28 13:42:32 +08:00
shareTypeList,
sharedType,
taxAgentIds,
dataType,
roundingMode,
pattern,
sortedIndex,
2023-01-28 13:42:32 +08:00
description
} = this.state;
2023-01-28 10:10:00 +08:00
return (
<WeaSlideModal
className="slideOuterWrapper"
visible={visible}
top={0}
width={50}
2023-01-28 10:10:00 +08:00
height={100}
direction="right"
measure="%"
title={
<SlideModalTitle
subtitle={title}
tabs={[]}
2023-01-28 13:42:32 +08:00
loading={loading}
2023-02-15 16:54:23 +08:00
showOperateBtn={true}
editable={(showSalaryItemBtn || showOperateBtn)}
2023-01-28 13:42:32 +08:00
onSave={this.saveFieldInfo}
2023-01-28 10:10:00 +08:00
/>
}
content={
2023-01-28 13:42:32 +08:00
<div className="wea-form-item-group">
2023-02-10 10:47:18 +08:00
<WeaFormItem label="名称" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 13:42:32 +08:00
<WeaInput viewAttr={3} value={name}
onChange={value => this.handleChangeFields("name", value)}/>
2023-01-28 10:10:00 +08:00
</WeaFormItem>
2023-02-20 14:35:54 +08:00
{/*{*/}
{/* editId &&*/}
{/* <WeaFormItem label="薪资档案引用" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>*/}
{/* <WeaCheckbox*/}
{/* value={useInEmployeeSalary}*/}
{/* display="switch"*/}
{/* onChange={value => this.handleChangeFields("useInEmployeeSalary", value)}*/}
{/* />*/}
{/* <WeaHelpfulTip style={{ marginLeft: "10px" }} width={200}*/}
{/* title="提示:开启后,该薪资项目不可删除或设为无效,取值方式会默认置为输入"*/}
{/* placement="topLeft"*/}
{/* />*/}
{/* </WeaFormItem>*/}
{/*}*/}
<WeaFormItem label="默认使用" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
<WeaCheckbox
value={useDefault}
display="switch"
onChange={value => this.handleChangeFields("useDefault", value)}
/>
<WeaHelpfulTip style={{ marginLeft: "10px" }}
title="提示:开启后,每个薪资方案都有该薪资项目,可在具体薪资方案中删除"
placement="topLeft"
/>
</WeaFormItem>
<WeaFormItem label={getLabel(111, "核算时隐藏")} labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
<WeaCheckbox
value={hideDefault}
display="switch"
onChange={value => this.handleChangeFields("hideDefault", value)}
/>
<WeaHelpfulTip style={{ marginLeft: "10px" }}
title={getLabel(111, "提示:开启后,在薪资账套中添加该项目时,默认勾选隐藏且在核算时隐藏该薪资项目,可在具体薪资账套中设置是否隐藏")}
placement="topLeft"
/>
</WeaFormItem>
2023-02-10 10:47:18 +08:00
<WeaFormItem label="可见性" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaSelect
value={sharedType}
options={shareTypeList}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("sharedType", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
{
sharedType === "1" &&
2023-02-10 10:47:18 +08:00
<WeaFormItem label="可见性范围" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaSelect
multiple
viewAttr={3}
value={taxAgentIds}
2023-02-15 16:54:23 +08:00
options={taxAgentOption}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("taxAgentIds", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
}
2023-02-10 10:47:18 +08:00
<WeaFormItem label="字段类型" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaSelect
value={dataType}
options={dataTypeOptions}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("dataType", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
2023-02-10 10:47:18 +08:00
<WeaFormItem label="舍入规则" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaSelect
value={roundingMode}
options={roundingModeOptions}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("roundingMode", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
2023-02-10 10:47:18 +08:00
<WeaFormItem label="保留小数位" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaSelect
value={pattern}
options={patternOptions}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("pattern", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
<WeaFormItem label="显示顺序" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
<WeaInputNumber value={sortedIndex} precision={0}
onChange={value => this.handleChangeFields("sortedIndex", value)}/>
</WeaFormItem>
2023-02-10 10:47:18 +08:00
<WeaFormItem label="备注" labelCol={{ span: 6 }} wrapperCol={{ span: 12 }}>
2023-01-28 10:10:00 +08:00
<WeaTextarea
value={description}
2023-01-28 13:42:32 +08:00
onChange={value => this.handleChangeFields("description", value)}
2023-01-28 10:10:00 +08:00
/>
</WeaFormItem>
</div>
}
2023-01-28 13:42:32 +08:00
onClose={() => {
this.handleReset();
onCancel();
}}
2023-01-28 10:10:00 +08:00
/>
);
}
}
export default FieldSlide;