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

406 lines
13 KiB
JavaScript
Raw Normal View History

2022-02-25 09:24:56 +08:00
import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
2022-04-18 11:42:45 +08:00
import { Button, Table, DatePicker, Switch, Modal } from 'antd';
2022-02-25 09:24:56 +08:00
2022-03-23 19:38:10 +08:00
import { WeaTop, WeaTab, WeaRightMenu, WeaRangePicker, WeaInputSearch, WeaSlideModal } from 'ecCom';
import { WeaTableNew } from "comsMobx"
2022-02-25 09:24:56 +08:00
import { renderNoright, getSearchs } from '../../util'; // 渲染form数据的方法因为多个页面都会使用所以抽的公共方法在util中
import CustomTab from '../../components/customTab';
import ContentWrapper from '../../components/contentWrapper';
2022-03-15 17:50:54 +08:00
import StepSlide from '../../components/stepSlide'
import SlideBaseForm from './slideBaseForm'
2022-03-16 10:41:38 +08:00
import SlideRefereUser from './slideRefereUser'
2022-02-25 09:24:56 +08:00
import { columns, dataSource } from './columns';
2022-03-16 10:41:38 +08:00
import SalaryItemForm from './salaryItemForm';
import CalRulesForm from './calcRulesForm';
import ValidRulesForm from './validRulesForm';
2022-03-16 13:28:34 +08:00
import SlideModalTitle from '../../components/slideModalTitle'
2022-03-16 13:45:35 +08:00
import CopyFormModal from './copyFormModal'
2022-02-25 09:24:56 +08:00
const { MonthPicker } = DatePicker;
2022-03-23 19:38:10 +08:00
const WeaTable = WeaTableNew.WeaTable;
@inject('ledgerStore')
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: "",
step1Request: {}
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-16 13:45:35 +08:00
refereUser() {
this.setState({
editSlideVisible: true,
selectedTab: 1
})
}
2022-03-15 17:50:54 +08:00
onEdit() {
this.setState({
2022-03-16 13:28:34 +08:00
editSlideVisible: true
2022-03-15 17:50:54 +08:00
})
}
2022-03-23 19:38:10 +08:00
componentWillMount() {
const { ledgerStore : {doInit}} = this.props;
doInit()
}
2022-03-24 16:58:57 +08:00
handleItemStatusChange(value, record) {
const { ledgerStore: { changeLedgerStatus }} = this.props;
changeLedgerStatus(record.id, value ? 0 : 1);
}
2022-03-30 20:04:34 +08:00
handleItemClick(record, selectedTab = 0) {
const { ledgerStore: {setSalarySobId} } = this.props;
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-03-25 16:41:59 +08:00
request: record
2022-03-24 16:58:57 +08:00
})
}
2022-03-29 17:33:54 +08:00
// 编辑Slide保存按钮
handleEditSlideSave() {
2022-03-30 20:04:34 +08:00
const { selectedTab, step1Request } = this.state;
const { ledgerStore: {saveLedgerItem, saveAdjustmentRule, saveLedgerBasic, baseInfoRequest}} = this.props;
if(selectedTab == 0) {
saveLedgerBasic(baseInfoRequest)
} else if(selectedTab == 2) {
2022-03-29 17:33:54 +08:00
saveLedgerItem()
2022-03-30 20:04:34 +08:00
} else if(selectedTab == 3) {
saveAdjustmentRule()
}
2022-03-29 17:33:54 +08:00
}
2022-03-23 19:38:10 +08:00
// 增加编辑功能重写columns绑定事件
getColumns = (columns) => {
let newColumns = '';
newColumns = columns.map(column => {
let newColumn = column;
newColumn.render = (text, record, index) => { //前端元素转义
let valueSpan = record[newColumn.dataIndex + "span"] !== undefined ? record[newColumn.dataIndex + "span"] : record[newColumn.dataIndex];
switch(newColumn.dataIndex) {
2022-03-24 16:58:57 +08:00
case 'name':
return <a onClick={() => {this.handleItemClick(record)}}>{text}</a>
2022-03-23 19:38:10 +08:00
case "disable":
2022-03-24 16:58:57 +08:00
return <Switch checked={text == 0} onChange={(value) => {this.handleItemStatusChange(value, record)}}/>
2022-03-31 21:03:17 +08:00
case "operate":
return <a onClick={() => {this.handleItemClick(record, 1)}}>关联人员</a>
2022-03-23 19:38:10 +08:00
default:
return <div dangerouslySetInnerHTML={{ __html: valueSpan }} />
}
}
return newColumn;
});
return newColumns;
}
onOperatesClick = (record, index, operate, flag) => {
2022-03-24 16:58:57 +08:00
const { ledgerStore: { deleteLedger }} = this.props;
2022-03-23 19:38:10 +08:00
switch(operate.index.toString()){
2022-03-30 20:04:34 +08:00
case "0": // 编辑
this.handleItemClick(record)
break;
2022-03-23 19:38:10 +08:00
case '1': // 复制
this.setState({
copyFormVisible: true,
currentReocrd: record
})
break;
2022-03-30 20:04:34 +08:00
case "3": // 关联人员
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-03-30 20:04:34 +08:00
title: '信息确认',
content: '确认删除',
onOk:() => {
deleteLedger([record.id])
},
onCancel: () => {
},
});
2022-03-24 16:58:57 +08:00
break;
2022-03-23 19:38:10 +08:00
}
};
handleCopySave = (value) => {
const { ledgerStore: { doCopy}} = this.props
2022-05-13 15:25:21 +08:00
doCopy(this.state.currentReocrd.id, value).then(() => {
this.setState({copyFormVisible: false})
})
2022-03-23 19:38:10 +08:00
}
2022-03-30 20:04:34 +08:00
handleNew = () => {
const { ledgerStore: { initSlideData }} = this.props;
initSlideData();
this.setState({stepSlideVisible: true, currentStep: 0})
}
2022-02-25 09:24:56 +08:00
render() {
2022-03-23 19:38:10 +08:00
const { ledgerStore } = this.props;
const { loading, hasRight, form, condition, tableStore, showSearchAd, getTableDatas, doSearch, setShowSearchAd } = ledgerStore;
2022-03-16 13:28:34 +08:00
const { currentStep, selectedTab } = this.state;
2022-02-25 09:24:56 +08:00
if (!hasRight && !loading) { // 无权限处理
return renderNoright();
}
const rightMenu = [// 右键菜单
{
key: 'BTN_COLUMN',
icon: <i className='icon-coms-Custom' />,
content: '显示列定制',
onClick: this.showColumn
},
];
const collectParams = { // 收藏功能配置
favname: '薪资账套',
favouritetype: 1,
objid: 0,
link: 'wui/index.html#/ns_demo03/index',
importantlevel: 1,
};
const adBtn = [ // 高级搜索内部按钮
<Button type="primary" onClick={doSearch}>搜索</Button>,
<Button type="ghost" onClick={() => form.resetForm()}>重置</Button>,
<Button type="ghost" onClick={() => setShowSearchAd(false)}>取消</Button>,
];
const topTab = [
2022-03-16 10:41:38 +08:00
];
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-03-30 20:04:34 +08:00
<Button type="primary" style={{marginRight: "10px"}} onClick={() => this.handleNew()}>新建</Button>
<WeaInputSearch value={this.state.searchValue} onChange={(value) => {this.setState({searchValue: value})}} onSearch={(value) => {this.handleSearch(value)}}/>
2022-03-15 17:50:54 +08:00
</div>
)
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})
}
const prevStep = () => {
const { currentStep } = this.state;
this.setState({currentStep: currentStep - 1});
}
2022-03-18 14:16:52 +08:00
const steps = [
"基础设置",
"关联人员",
"薪资项目",
"调薪记薪规则",
2022-04-24 17:52:38 +08:00
// "校验规则",
2022-03-18 14:16:52 +08:00
]
2022-03-16 10:41:38 +08:00
2022-03-24 16:58:57 +08:00
const handleStep1Save = () => {
2022-03-30 20:04:34 +08:00
const { step1Request } = this.state;
const { ledgerStore: {saveLedgerBasic, baseInfoRequest} } = this.props;
saveLedgerBasic(baseInfoRequest).then(() => {
nextStep();
})
}
const handleStep3Save = () => {
const { ledgerStore: {saveAdjustmentRule} } = this.props;
saveAdjustmentRule().then(() => {
nextStep()
})
2022-03-24 16:58:57 +08:00
}
2022-03-30 20:04:34 +08:00
const handleStepSave = () => {
const { currentStep } = this.state;
const { ledgerStore: { saveLedgerBasic, saveLedgerItem, saveAdjustmentRule, baseInfoRequest }} = this.props;
if(currentStep == 0) {
saveLedgerBasic(baseInfoRequest).then(() => {
nextStep();
})
} else if(currentStep == 1) {
nextStep()
}else if(currentStep == 2) {
saveLedgerItem().then(() => {
nextStep()
})
} else if(currentStep == 3) {
saveAdjustmentRule().then(() => {
2022-04-27 19:27:23 +08:00
this.setState({stepSlideVisible: false})
2022-03-30 20:04:34 +08:00
})
2022-04-27 19:27:23 +08:00
}
2022-03-30 20:04:34 +08:00
}
2022-03-29 17:33:54 +08:00
2022-02-25 09:24:56 +08:00
return (
<div className="mySalaryBenefitsWrapper">
<WeaRightMenu
datas={rightMenu} // 右键菜单
collectParams={collectParams} // 收藏功能: 配置之后显示 收藏、帮助、显示页面地址 这3个功能
>
<WeaTop
title="薪资账套" // 文字
icon={<i className='icon-coms-meeting' />} // 左侧图标
iconBgcolor='#F14A2D' // 左侧图标背景色
showDropIcon={true} // 是否显示下拉按钮
dropMenuDatas={rightMenu} // 下拉菜单(和页面的右键菜单相同)
dropMenuProps={{ collectParams }} // 收藏功能: 配置之后显示 收藏、帮助、显示页面地址 这3个功能
>
2022-03-15 17:50:54 +08:00
<CustomTab
searchOperationItem={
renderRightOperation()
}
onChange={(v) => {
}}
/>
2022-03-23 19:38:10 +08:00
<WeaTable // table内部做了loading加载处理页面就不需要再加了
comsWeaTableStore={tableStore} // table store
hasOrder={true} // 是否启用排序
needScroll={true} // 是否启用table内部列表滚动将自适应到父级高度
getColumns={this.getColumns}
onOperatesClick={this.onOperatesClick.bind(this)}
/>
2022-03-15 17:50:54 +08:00
{
this.state.stepSlideVisible && <StepSlide
visible={this.state.stepSlideVisible}
2022-03-18 14:16:52 +08:00
steps={steps}
2022-03-16 10:41:38 +08:00
currentStep={currentStep}
2022-03-15 17:50:54 +08:00
onCancel={() => {this.setState({stepSlideVisible: false})}}
2022-03-16 10:41:38 +08:00
customOperate = {
<div style={{display: "inline-block"}}>
{
2022-03-24 16:58:57 +08:00
currentStep == 0 && <Button type="primary" onClick={() => {handleStep1Save()}}>保存并进入下一步</Button>
2022-03-16 10:41:38 +08:00
}
{
currentStep == 1 && <div style={{display: "inline-block"}}>
<Button type="default" onClick={() => {this.setState({stepSlideVisible: false})}}>完成跳过所有步骤</Button>
2022-03-30 20:04:34 +08:00
<Button type="primary" style={{marginLeft: "10px"}} onClick={() => {handleStepSave()}}>下一步</Button>
2022-03-16 10:41:38 +08:00
</div>
}
{
2022-04-24 17:52:38 +08:00
currentStep == 2 && <div>
2022-03-16 10:41:38 +08:00
<Button type="default" onClick={() => {this.setState({stepSlideVisible: false})}}>完成跳过所有步骤</Button>
<Button type="default" style={{marginLeft: "10px"}} onClick={() => {prevStep()}}>上一步</Button>
2022-03-30 20:04:34 +08:00
<Button type="primary" style={{marginLeft: '10px'}} onClick={() => {handleStepSave()}}>保存并进入下一步</Button>
2022-03-16 10:41:38 +08:00
</div>
}
{
2022-04-24 17:52:38 +08:00
currentStep == 3 &&
2022-03-16 10:41:38 +08:00
<div>
<Button type="default" style={{marginRight: "10px"}} onClick={() => {prevStep()}}>上一步</Button>
2022-03-30 20:04:34 +08:00
<Button type="primary" onClick={() => {handleStepSave()}}>完成</Button>
2022-03-16 10:41:38 +08:00
</div>
}
</div>
}
2022-03-15 17:50:54 +08:00
title="新建账套"
2022-03-16 10:41:38 +08:00
content={
<div>
{
2022-04-06 14:26:16 +08:00
currentStep == 0 && <SlideBaseForm />
}
{
currentStep == 1 && <SlideRefereUser />
}
{
currentStep == 2 && <SalaryItemForm />
}
{
currentStep == 3 && <CalRulesForm />
}
2022-04-24 17:52:38 +08:00
{/* {
2022-04-06 14:26:16 +08:00
currentStep == 4 && <ValidRulesForm />
2022-04-24 17:52:38 +08:00
} */}
2022-04-02 17:34:40 +08:00
2022-03-16 10:41:38 +08:00
</div>
}
2022-03-15 17:50:54 +08:00
/>
}
2022-03-16 13:28:34 +08:00
{
this.state.editSlideVisible &&
<WeaSlideModal visible={this.state.editSlideVisible}
top={0}
width={40}
height={100}
direction={'right'}
measure={'%'}
title={
<SlideModalTitle
subtitle={"编辑账套"}
2022-04-24 17:52:38 +08:00
tabs={[{title: '基础设置', key: 0}, {title: "关联人员", key: 1}, {title: "薪资项目", key: 2}, {title: '调薪计薪规则', key: 3}]}
2022-03-16 13:28:34 +08:00
editable={true}
selectedTab={selectedTab}
2022-03-29 17:33:54 +08:00
onSave={() => this.handleEditSlideSave()}
2022-03-16 13:28:34 +08:00
subItemChange={
(item) => {this.setState({selectedTab: item.key})}
}
/>
}
content={<div>
{
2022-03-30 20:04:34 +08:00
selectedTab == 0 && <SlideBaseForm edit={true} />
2022-03-16 13:28:34 +08:00
}
{
2022-03-30 20:04:34 +08:00
selectedTab == 1 && <SlideRefereUser edit={true} />
2022-03-16 13:28:34 +08:00
}
{
2022-03-30 20:04:34 +08:00
selectedTab == 2 && <SalaryItemForm edit={true}/>
2022-03-16 13:28:34 +08:00
}
{
2022-03-30 20:04:34 +08:00
selectedTab == 3 && <CalRulesForm edit={true}/>
2022-03-16 13:28:34 +08:00
}
2022-04-24 17:52:38 +08:00
{/* {
2022-03-30 20:04:34 +08:00
selectedTab == 4 && <ValidRulesForm edit={true}/>
2022-04-24 17:52:38 +08:00
} */}
2022-03-16 13:28:34 +08:00
</div>}
onClose={() => this.setState({editSlideVisible: false})}
showMask={true}
closeMaskOnClick={() => this.setState({editSlideVisible: false})} />
}
2022-02-25 09:24:56 +08:00
</WeaTop>
</WeaRightMenu>
2022-03-16 13:45:35 +08:00
{
this.state.copyFormVisible &&
<CopyFormModal
visible={this.state.copyFormVisible}
2022-03-23 19:38:10 +08:00
onSave={(value) => this.handleCopySave(value)}
2022-03-16 13:45:35 +08:00
onCancel={() => {this.setState({copyFormVisible: false})}}
/>
}
2022-02-25 09:24:56 +08:00
</div>
)
}
}