salary-management-front/pc4mobx/hrmSalary/pages/ledger/index.js

575 lines
17 KiB
JavaScript
Raw Normal View History

2022-06-02 14:48:55 +08:00
import React from "react";
import { inject, observer } from "mobx-react";
2022-06-02 14:48:55 +08:00
2022-12-01 14:28:30 +08:00
import { Button, Dropdown, Menu, Modal, Switch } from "antd";
2022-06-02 14:48:55 +08:00
2022-12-01 14:28:30 +08:00
import { WeaInputSearch, WeaSlideModal, WeaTable, WeaTop } from "ecCom";
import { renderNoright } from "../../util"; // 渲染form数据的方法因为多个页面都会使用所以抽的公共方法在util中
2022-06-02 14:48:55 +08:00
import CustomTab from "../../components/customTab";
import StepSlide from "../../components/stepSlide";
import SlideBaseForm from "./slideBaseForm";
import SlideRefereUser from "./slideRefereUser";
import SalaryItemForm from "./salaryItemForm";
import CalRulesForm from "./calcRulesForm";
import ValidRulesForm from "./validRulesForm";
import SlideModalTitle from "../../components/slideModalTitle";
import CopyFormModal from "./copyFormModal";
import "./index.less";
2022-02-25 09:24:56 +08:00
2022-06-02 14:48:55 +08:00
@inject("ledgerStore", "taxAgentStore")
2022-02-25 09:24:56 +08:00
@observer
2022-03-10 10:58:26 +08:00
export default class Ledger extends React.Component {
2022-02-25 09:24:56 +08:00
constructor(props) {
super(props);
this.state = {
value: "",
2022-03-15 17:50:54 +08:00
selectedKey: "0",
stepSlideVisible: false,
2022-03-16 13:28:34 +08:00
editSlideVisible: false,
2022-03-16 13:45:35 +08:00
copyFormVisible: false,
2022-03-24 16:58:57 +08:00
currentStep: 0,
2022-03-16 13:28:34 +08:00
selectedTab: 0,
2022-03-23 19:38:10 +08:00
currentReocrd: {},
2022-03-30 20:04:34 +08:00
searchValue: "",
2022-06-29 17:04:01 +08:00
step1Request: {}
2022-06-02 14:48:55 +08:00
};
2022-02-25 09:24:56 +08:00
}
2022-03-15 17:50:54 +08:00
2022-03-30 20:04:34 +08:00
handleSearch(value) {
const { ledgerStore: { getTableDatas } } = this.props;
getTableDatas({ name: value });
2022-03-30 20:04:34 +08:00
}
2022-03-23 19:38:10 +08:00
componentWillMount() {
2022-06-02 14:48:55 +08:00
const {
ledgerStore: { doInit },
taxAgentStore: { getTaxAgentSelectListAsAdmin }
2022-06-02 14:48:55 +08:00
} = this.props;
doInit();
getTaxAgentSelectListAsAdmin();
2022-03-23 19:38:10 +08:00
}
2022-03-24 16:58:57 +08:00
handleItemStatusChange(value, record) {
const { ledgerStore: { changeLedgerStatus } } = this.props;
2022-03-24 16:58:57 +08:00
changeLedgerStatus(record.id, value ? 0 : 1);
}
2022-03-30 20:04:34 +08:00
handleItemClick(record, selectedTab = 0) {
const { ledgerStore: { setSalarySobId } } = this.props;
2022-06-02 14:48:55 +08:00
setSalarySobId(record.id);
2022-03-24 16:58:57 +08:00
this.setState({
2022-03-30 20:04:34 +08:00
selectedTab,
2022-03-24 16:58:57 +08:00
editSlideVisible: true,
2022-06-29 17:04:01 +08:00
request: record
2022-06-02 14:48:55 +08:00
});
2022-03-24 16:58:57 +08:00
}
2022-03-29 17:33:54 +08:00
// 编辑Slide保存按钮
handleEditSlideSave() {
const { selectedTab, step1Request } = this.state;
2022-06-02 14:48:55 +08:00
const {
ledgerStore: {
saveLedgerItem,
saveAdjustmentRule,
saveLedgerBasic,
2022-06-29 17:04:01 +08:00
baseInfoRequest
}
2022-06-02 14:48:55 +08:00
} = this.props;
if (selectedTab == 0) {
saveLedgerBasic(baseInfoRequest);
} else if (selectedTab == 2) {
saveLedgerItem();
} else if (selectedTab == 3) {
saveAdjustmentRule();
}
2022-03-29 17:33:54 +08:00
}
2022-03-23 19:38:10 +08:00
// 增加编辑功能重写columns绑定事件
2022-06-29 17:04:01 +08:00
getColumns = columns => {
2022-06-02 14:48:55 +08:00
let newColumns = "";
2022-06-29 17:04:01 +08:00
newColumns = columns.map(column => {
2022-03-23 19:38:10 +08:00
let newColumn = column;
2022-06-02 14:48:55 +08:00
newColumn.render = (text, record, index) => {
//前端元素转义
let valueSpan =
record[newColumn.dataIndex + "span"] !== undefined
? record[newColumn.dataIndex + "span"]
: record[newColumn.dataIndex];
switch (newColumn.dataIndex) {
case "name":
return (
<a
onClick={() => {
this.handleItemClick(record);
}}>
{text}
</a>
);
2022-03-23 19:38:10 +08:00
case "disable":
2022-06-02 14:48:55 +08:00
return (
<Switch
checked={text == 0}
2022-06-29 17:04:01 +08:00
onChange={value => {
2022-06-02 14:48:55 +08:00
this.handleItemStatusChange(value, record);
}}
/>
);
2022-03-31 21:03:17 +08:00
case "operate":
2022-06-02 14:48:55 +08:00
return (
<a
onClick={() => {
this.handleItemClick(record, 1);
}}>
关联人员
</a>
);
2022-03-23 19:38:10 +08:00
default:
return <div dangerouslySetInnerHTML={{ __html: valueSpan }}/>;
2022-03-23 19:38:10 +08:00
}
2022-06-02 14:48:55 +08:00
};
2022-03-23 19:38:10 +08:00
return newColumn;
});
return newColumns;
2022-06-02 14:48:55 +08:00
};
2022-03-23 19:38:10 +08:00
2022-06-02 14:48:55 +08:00
onOperatesClick = (record, type) => {
const { ledgerStore: { deleteLedger } } = this.props;
2022-06-02 14:48:55 +08:00
switch (type.toString()) {
2022-03-30 20:04:34 +08:00
case "0": // 编辑
2022-06-02 14:48:55 +08:00
this.handleItemClick(record);
2022-03-30 20:04:34 +08:00
break;
2022-06-02 14:48:55 +08:00
case "1": // 复制
2022-03-23 19:38:10 +08:00
this.setState({
copyFormVisible: true,
2022-06-29 17:04:01 +08:00
currentReocrd: record
2022-06-02 14:48:55 +08:00
});
2022-03-23 19:38:10 +08:00
break;
2022-03-30 20:04:34 +08:00
case "3": // 关联人员
2022-06-02 14:48:55 +08:00
this.handleItemClick(record, 1);
2022-05-30 09:38:45 +08:00
break;
2022-03-24 16:58:57 +08:00
case "4": // 删除
2022-04-22 18:12:16 +08:00
Modal.confirm({
2022-06-02 14:48:55 +08:00
title: "信息确认",
content: "确认删除",
onOk: () => {
deleteLedger([record.id]);
2022-03-30 20:04:34 +08:00
},
2022-07-04 19:03:14 +08:00
onCancel: () => {
}
2022-03-30 20:04:34 +08:00
});
2022-06-02 14:48:55 +08:00
2022-03-24 16:58:57 +08:00
break;
2022-03-23 19:38:10 +08:00
}
};
2022-06-29 17:04:01 +08:00
handleCopySave = value => {
const { ledgerStore: { doCopy } } = this.props;
doCopy({ id: this.state.currentReocrd.id, ...value }).then(() => {
this.setState({ copyFormVisible: false });
2022-06-02 14:48:55 +08:00
});
};
2022-03-23 19:38:10 +08:00
2022-03-30 20:04:34 +08:00
handleNew = () => {
const { ledgerStore: { initSlideData } } = this.props;
2022-03-30 20:04:34 +08:00
initSlideData();
this.setState({ stepSlideVisible: true, currentStep: 0 });
2022-06-02 14:48:55 +08:00
};
2022-03-30 20:04:34 +08:00
2022-02-25 09:24:56 +08:00
render() {
const { ledgerStore, taxAgentStore } = this.props;
2022-06-02 14:48:55 +08:00
const {
loading,
saveLoading,
2022-06-02 14:48:55 +08:00
dataSource,
columns,
pageObj,
setPageObj,
hasRight,
form,
condition,
tableStore,
showSearchAd,
getTableDatas,
doSearch,
setShowSearchAd,
2022-06-29 17:04:01 +08:00
baseInfoRequest
2022-06-02 14:48:55 +08:00
} = ledgerStore;
const { showOperateBtn } = taxAgentStore;
const { canEdit } = baseInfoRequest;
const { currentStep, selectedTab } = this.state;
2022-06-02 14:48:55 +08:00
if (!hasRight && !loading) {
// 无权限处理
2022-02-25 09:24:56 +08:00
return renderNoright();
}
2022-06-02 14:48:55 +08:00
const rightMenu = [
// 右键菜单
2022-07-11 18:21:47 +08:00
// {
// key: "BTN_COLUMN",
// icon: <i className="icon-coms-Custom"/>,
// content: "显示列定制",
// onClick: this.showColumn
// }
2022-02-25 09:24:56 +08:00
];
2022-06-02 14:48:55 +08:00
const collectParams = {
// 收藏功能配置
favname: "薪资账套",
2022-02-25 09:24:56 +08:00
favouritetype: 1,
objid: 0,
2022-06-02 14:48:55 +08:00
link: "wui/index.html#/ns_demo03/index",
2022-06-29 17:04:01 +08:00
importantlevel: 1
2022-02-25 09:24:56 +08:00
};
2022-06-02 14:48:55 +08:00
const adBtn = [
// 高级搜索内部按钮
<Button type="primary" onClick={doSearch}>
搜索
</Button>,
<Button type="ghost" onClick={() => form.resetForm()}>
重置
</Button>,
<Button type="ghost" onClick={() => setShowSearchAd(false)}>
取消
2022-06-29 17:04:01 +08:00
</Button>
2022-02-25 09:24:56 +08:00
];
2022-06-02 14:48:55 +08:00
const topTab = [];
2022-02-25 09:24:56 +08:00
2022-03-15 17:50:54 +08:00
const renderRightOperation = () => {
return (
<div style={{ display: "inline-block" }}>
2022-06-29 17:04:01 +08:00
{showOperateBtn &&
2022-06-21 14:27:16 +08:00
<Button
type="primary"
style={{ marginRight: "10px" }}
2022-06-21 14:27:16 +08:00
onClick={() => this.handleNew()}>
新建
2022-06-29 17:04:01 +08:00
</Button>}
2022-06-02 14:48:55 +08:00
<WeaInputSearch
value={this.state.searchValue}
2022-06-29 17:04:01 +08:00
onChange={value => {
this.setState({ searchValue: value });
2022-06-02 14:48:55 +08:00
}}
placeholder={"请输入薪资账套名称"}
2022-06-29 17:04:01 +08:00
onSearch={value => {
2022-06-02 14:48:55 +08:00
this.handleSearch(value);
}}
/>
2022-03-15 17:50:54 +08:00
</div>
2022-06-02 14:48:55 +08:00
);
};
2022-02-25 09:24:56 +08:00
2022-03-16 10:41:38 +08:00
const nextStep = () => {
const { currentStep } = this.state;
this.setState({ currentStep: currentStep + 1 });
2022-06-02 14:48:55 +08:00
};
2022-03-16 10:41:38 +08:00
const prevStep = () => {
const { currentStep } = this.state;
this.setState({ currentStep: currentStep - 1 });
2022-06-02 14:48:55 +08:00
};
2022-03-18 14:16:52 +08:00
const steps = [
"基础设置",
"关联人员",
"薪资项目",
2022-07-20 10:33:23 +08:00
"调薪计薪规则"
2022-07-11 18:21:47 +08:00
// "校验规则"
2022-06-02 14:48:55 +08:00
];
2022-03-16 10:41:38 +08:00
2022-03-24 16:58:57 +08:00
const handleStep1Save = () => {
const { step1Request } = this.state;
const { ledgerStore: { saveLedgerBasic, baseInfoRequest } } = this.props;
2022-03-30 20:04:34 +08:00
saveLedgerBasic(baseInfoRequest).then(() => {
nextStep();
2022-06-02 14:48:55 +08:00
});
};
2022-03-30 20:04:34 +08:00
const handleStep3Save = () => {
const { ledgerStore: { saveAdjustmentRule } } = this.props;
2022-03-30 20:04:34 +08:00
saveAdjustmentRule().then(() => {
2022-06-02 14:48:55 +08:00
nextStep();
});
};
2022-03-24 16:58:57 +08:00
2022-03-30 20:04:34 +08:00
const handleStepSave = () => {
const { currentStep } = this.state;
2022-06-02 14:48:55 +08:00
const {
ledgerStore: {
saveLedgerBasic,
saveLedgerItem,
saveAdjustmentRule,
2022-06-29 17:04:01 +08:00
baseInfoRequest
}
2022-06-02 14:48:55 +08:00
} = this.props;
if (currentStep == 0) {
2022-03-30 20:04:34 +08:00
saveLedgerBasic(baseInfoRequest).then(() => {
nextStep();
2022-06-02 14:48:55 +08:00
});
2022-07-20 10:33:23 +08:00
// } else if (currentStep == 1 || currentStep == 3) {
} else if (currentStep == 1) {
2022-06-02 14:48:55 +08:00
nextStep();
} else if (currentStep == 2) {
2022-03-30 20:04:34 +08:00
saveLedgerItem().then(() => {
2022-06-02 14:48:55 +08:00
nextStep();
});
2022-07-20 10:33:23 +08:00
// } else if (currentStep == 4) {
} else if (currentStep == 3) {
2022-03-30 20:04:34 +08:00
saveAdjustmentRule().then(() => {
this.setState({ stepSlideVisible: false });
2022-06-02 14:48:55 +08:00
});
}
};
const pagination = {
total: pageObj.total,
2022-06-29 17:04:01 +08:00
showTotal: total => `${total}`,
2022-06-02 14:48:55 +08:00
showSizeChanger: true,
2022-06-23 16:20:49 +08:00
pageSizeOptions: ["10", "20", "50", "100"],
2022-06-08 18:42:01 +08:00
onShowSizeChange: (current, pageSize) => {
setPageObj({ ...pageObj, current, pageSize });
getTableDatas({ current, pageSize, name: this.state.searchValue });
2022-06-02 14:48:55 +08:00
},
2022-06-29 17:04:01 +08:00
onChange: current => {
setPageObj({ ...pageObj, current, pageSize: pageObj.pageSize });
2022-06-02 14:48:55 +08:00
getTableDatas({
current,
pageSize: pageObj.pageSize,
2022-06-29 17:04:01 +08:00
name: this.state.searchValue
2022-06-02 14:48:55 +08:00
});
2022-06-29 17:04:01 +08:00
}
2022-06-02 14:48:55 +08:00
};
2022-06-29 17:04:01 +08:00
const newColumns = _.map([...columns], item => {
2022-06-02 14:48:55 +08:00
if (item.dataIndex === "name") {
return {
...item,
2022-06-29 17:04:01 +08:00
render: (text, record) =>
2022-06-02 14:48:55 +08:00
<div className="linkWapper">
<a
href="javaScript:void(0);"
onClick={() => {
this.handleItemClick(record);
}}>
{text}
</a>
</div>
};
} else if (item.dataIndex === "disable") {
return {
...item,
2022-06-29 17:04:01 +08:00
render: (text, record) =>
2022-06-02 14:48:55 +08:00
<Switch
checked={text == 0}
2022-06-21 14:27:16 +08:00
disabled={!showOperateBtn}
2022-06-29 17:04:01 +08:00
onChange={value => {
2022-06-02 14:48:55 +08:00
this.handleItemStatusChange(value, record);
}}
/>
};
2022-06-21 14:27:16 +08:00
} else if (item.dataIndex === "operate" && showOperateBtn) {
2022-06-02 14:48:55 +08:00
return {
...item,
2022-06-29 17:04:01 +08:00
render: (text, record) =>
2022-06-02 14:48:55 +08:00
<div className="linkWapper">
<a
onClick={() => {
this.handleItemClick(record, 1);
}}>
关联人员
</a>
<Dropdown
overlay={
<Menu
2022-06-29 17:04:01 +08:00
onClick={item => this.onOperatesClick(record, item.key)}>
2022-06-02 14:48:55 +08:00
<Menu.Item key="0">编辑</Menu.Item>
<Menu.Item key="1">复制</Menu.Item>
2022-07-04 19:03:14 +08:00
{/*<Menu.Item key="3">关联人员</Menu.Item>*/}
2022-06-02 14:48:55 +08:00
<Menu.Item key="4">删除</Menu.Item>
</Menu>
}>
<a className="ant-dropdown-link" href="javaScript:void(0);">
<i className="icon-coms-more" style={{ marginLeft: 18 }}/>
2022-06-02 14:48:55 +08:00
</a>
</Dropdown>
</div>
};
} else {
return { ...item };
2022-06-02 14:48:55 +08:00
}
});
2022-03-29 17:33:54 +08:00
2022-02-25 09:24:56 +08:00
return (
<div className="mySalaryBenefitsWrapper">
2022-12-01 14:28:30 +08:00
<WeaTop
title="薪资账套" // 文字
icon={<i className="icon-coms-fa"/>} // 左侧图标
iconBgcolor="#F14A2D" // 左侧图标背景色
showDropIcon={false} // 是否显示下拉按钮
dropMenuDatas={rightMenu} // 下拉菜单(和页面的右键菜单相同)
dropMenuProps={{ collectParams }}>
<CustomTab
searchOperationItem={renderRightOperation()}
onChange={v => {
}}
/>
<WeaTable
rowKey="id"
columns={
showOperateBtn
? newColumns
: _.filter(newColumns, it => it.dataIndex !== "operate")
}
dataSource={dataSource}
pagination={pagination}
loading={loading}
scroll={{ x: 1300 }}
/>
{this.state.stepSlideVisible &&
<StepSlide
visible={this.state.stepSlideVisible}
steps={steps}
currentStep={currentStep}
onCancel={() => {
this.setState({ stepSlideVisible: false });
2022-07-04 19:03:14 +08:00
}}
2022-12-01 14:28:30 +08:00
customOperate={
currentStep == 0 ? [
<Button
type="primary"
loading={saveLoading}
onClick={() => {
handleStep1Save();
}}>
保存并进入下一步
</Button>
] : currentStep == 1 ? [
<Button
type="default"
onClick={() => {
this.setState({ stepSlideVisible: false });
}}>
完成跳过所有步骤
</Button>,
<Button
type="primary"
style={{ marginLeft: "10px" }}
onClick={() => {
handleStepSave();
}}>
下一步
</Button>
] : currentStep == 2 ? [
<Button
type="default"
onClick={() => {
this.setState({ stepSlideVisible: false });
}}>
完成跳过所有步骤
</Button>,
<Button
type="default"
style={{ marginLeft: "10px" }}
onClick={() => {
prevStep();
}}>
上一步
</Button>,
<Button
type="primary"
loading={saveLoading}
2022-12-01 14:28:30 +08:00
style={{ marginLeft: "10px" }}
onClick={() => {
handleStepSave();
}}>
保存并进入下一步
</Button>
] : currentStep == 3 ? [
<Button
type="default"
style={{ marginRight: "10px" }}
onClick={() => {
prevStep();
}}>
上一步
</Button>,
<Button
type="primary"
onClick={() => {
handleStepSave();
}}>
完成
</Button>
] : []
}
title="新建账套"
content={
<div>
{currentStep == 0 && <SlideBaseForm/>}
{currentStep == 1 && <SlideRefereUser/>}
{currentStep == 2 && <SalaryItemForm/>}
{currentStep == 3 && <CalRulesForm/>}
{currentStep == 4 && <ValidRulesForm/>}
</div>
}
/>}
{this.state.editSlideVisible &&
<WeaSlideModal
className="slideOuterWrapper"
visible={this.state.editSlideVisible}
top={0}
width={65}
2022-12-01 14:28:30 +08:00
height={100}
direction={"right"}
measure={"%"}
title={
<SlideModalTitle
subtitle={`编辑账套`}
tabs={[
{ title: "基础设置", key: 0 },
{ title: "关联人员", key: 1 },
{ title: "薪资项目", key: 2 },
{ title: "调薪计薪规则", key: 3 }
// { title: "校验规则", key: 4 }
]}
loading={saveLoading}
showOperateBtn={showOperateBtn}
editable={canEdit === "true"}
selectedTab={selectedTab}
onSave={() => this.handleEditSlideSave()}
subItemChange={selectedTab => {
this.setState({ selectedTab });
}}
/>
}
content={
<div>
{selectedTab == 0 && <SlideBaseForm edit={true}/>}
{selectedTab == 1 && <SlideRefereUser edit={true}/>}
{selectedTab == 2 && <SalaryItemForm edit={true}/>}
{selectedTab == 3 && <CalRulesForm edit={true}/>}
{selectedTab == 4 && <ValidRulesForm edit={true}/>}
</div>
}
onClose={() => this.setState({ editSlideVisible: false }, () => {
this.setState({ selectedTab: 0 });
})}
showMask={true}
closeMaskOnClick={() =>
this.setState({ editSlideVisible: false }, () => {
this.setState({ selectedTab: 0 });
})}
2022-12-01 14:28:30 +08:00
/>}
</WeaTop>
2022-03-16 13:45:35 +08:00
2022-06-29 17:04:01 +08:00
{this.state.copyFormVisible &&
2022-06-02 14:48:55 +08:00
<CopyFormModal
taxAgentStore={taxAgentStore}
2022-03-16 13:45:35 +08:00
visible={this.state.copyFormVisible}
2022-06-29 17:04:01 +08:00
onSave={value => this.handleCopySave(value)}
2022-06-02 14:48:55 +08:00
onCancel={() => {
this.setState({ copyFormVisible: false });
2022-06-02 14:48:55 +08:00
}}
2022-06-29 17:04:01 +08:00
/>}
2022-02-25 09:24:56 +08:00
</div>
2022-06-02 14:48:55 +08:00
);
2022-02-25 09:24:56 +08:00
}
}