salary-management-front/pc4mobx/hrmSalary/pages/ledger/step3/canMoveItem.js

359 lines
10 KiB
JavaScript
Raw Normal View History

2022-06-17 16:53:27 +08:00
import React, { Fragment } from "react";
import { Icon, message, Modal, Button} from "antd";
import { WeaCheckbox, WeaHelpfulTip, WeaTable } from "ecCom";
2022-06-17 16:53:27 +08:00
import { slideStep3Columns } from "../columns";
import AddSalaryItemModal from "./AddSalaryItemModal";
import { inject, observer } from "mobx-react";
2022-07-28 17:16:40 +08:00
import { toJS } from "mobx";
2022-06-17 16:53:27 +08:00
import FormalFormModal from "../../salaryItem/formalFormModal";
import AddCategoryModal from "../step3/AddCategoryModal";
2022-07-28 17:16:40 +08:00
const helpContent = () => {
return <span>
<span>1新建薪资账套时核算公式与薪资项目管理菜单一致</span><br/>
<span>2取值方式为公式的薪资项目核算公式显示为具体公式点击公式可编辑公式核算时按照当前薪资项目的公式进行核算</span><br/>
2022-08-25 17:54:18 +08:00
<span>3薪资账套内的薪资项目的公式或SQL的修改或公式的修改都不影响薪资项目管理菜单的薪资项目取值方式或公式只对当前账套生效</span><br/>
2022-07-28 17:16:40 +08:00
</span>;
};
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
@inject("ledgerStore")
2022-03-29 17:33:54 +08:00
@observer
export default class CanMoveItem extends React.Component {
2022-06-17 16:53:27 +08:00
constructor(props) {
super(props);
let columns = slideStep3Columns.map(item => {
item = { ...item };
2022-07-28 17:16:40 +08:00
if (item.key === "formulaContent") {
item.title = <span>
<span style={{ marginRight: 8 }}>{item.title}</span>
<WeaHelpfulTip
title={helpContent()}
placement="bottom"
width={200}
/>
</span>;
2022-06-17 16:53:27 +08:00
item.render = (text, record) => {
if (record.canEdit) {
return (
<span className="linkWapper">
<a
onClick={() => {
this.handleFormulaClick(record.formulaId, record);
}}>
{text}
</a>
</span>
);
} else {
return (
<span>
{text}
</span>
);
}
};
}
return item;
});
this.state = {
addItemVisible: false,
showContent: true,
selectedRowKeys: [],
columns,
formalModalVisible: false,
addCategoryVisible: false
};
2022-04-20 15:28:40 +08:00
2022-06-17 16:53:27 +08:00
this.formulaId = "";
this.record = {};
this.title = "";
}
2022-04-20 15:28:40 +08:00
handleChangeItem = (value, id) => {
2022-08-25 17:54:18 +08:00
const { dataSource } = this.props;
let result = [...dataSource];
this.props.onChange(
_.map(result, item => {
if (id === item.id) {
2022-08-25 17:54:18 +08:00
return {
...item,
itemHide: String(value)
};
2022-08-25 17:54:18 +08:00
}
return { ...item };
2022-08-25 17:54:18 +08:00
})
);
};
handleChangeAllItem = (value) => {
2022-08-25 17:54:18 +08:00
const { dataSource } = this.props;
let result = [...dataSource];
this.props.onChange(
_.map(result, item => {
return {
...item,
itemHide: String(value)
};
2022-08-25 17:54:18 +08:00
})
);
};
2022-08-25 17:54:18 +08:00
2022-06-17 16:53:27 +08:00
// 编辑公式
handleFormulaClick(formulaId, record) {
this.formulaId = formulaId;
this.record = record;
this.setState({
formalModalVisible: true
});
}
2022-04-20 15:28:40 +08:00
2022-06-17 16:53:27 +08:00
handleTiggleContent() {
this.setState({ showContent: !this.state.showContent });
}
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
onSelectChange = selectedRowKeys => {
this.setState({ selectedRowKeys });
};
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
// 删除
handleDelete = () => {
const { selectedRowKeys } = this.state;
if (selectedRowKeys.length == 0) {
2022-08-25 17:54:18 +08:00
message.warning("未选择任何条目");
2022-06-17 16:53:27 +08:00
return;
2022-04-20 15:28:40 +08:00
}
2022-06-17 16:53:27 +08:00
Modal.confirm({
title: "信息确认",
content: "确认删除",
onOk: () => {
const { dataSource } = this.props;
let result = [...dataSource];
this.props.onChange(
result.filter(item => selectedRowKeys.indexOf(item.key) < 0)
);
},
2022-07-28 17:16:40 +08:00
onCancel: () => {
}
2022-06-17 16:53:27 +08:00
});
};
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
// 保存
handleSaveFormal(data) {
let record = { ...this.record };
record.formulaId = data.id;
let dataSource = [...this.props.dataSource];
dataSource.map(item => {
if (item.id == record.id) {
item.formulaId = data.id;
item.formulaContent = data.formula;
}
});
this.props.onDataSourceChange(dataSource);
}
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
// 编辑分类名称
handleUpdateCategorySave(name) {
this.props.onTitleChange && this.props.onTitleChange(name);
this.setState({
addCategoryVisible: false
});
}
2022-05-13 15:25:21 +08:00
2022-06-17 16:53:27 +08:00
// 修改分类名称,弹出修改弹出
handleEditGroupIconClick(title) {
this.title = title;
this.setState({ addCategoryVisible: true });
}
2022-05-13 15:25:21 +08:00
2022-06-17 16:53:27 +08:00
// 删除分类回调
handleDeleteGroupIconClick() {
Modal.confirm({
title: "信息确认",
content: "确认删除",
onOk: () => {
this.props.onGroupDelete && this.props.onGroupDelete();
},
2022-07-28 17:16:40 +08:00
onCancel: () => {
}
2022-06-17 16:53:27 +08:00
});
}
2022-05-31 18:51:23 +08:00
2022-06-17 16:53:27 +08:00
render() {
const {
disabled,
2022-07-28 17:16:40 +08:00
sortedIndex,
ledgerStore: { setAddItemVisible, addItemVisible, itemGroups = [] }
2022-06-17 16:53:27 +08:00
} = this.props;
const checkValue = _.every(this.props.dataSource, it => it.itemHide && it.itemHide === "1") ? "1" : "0";
2022-06-17 16:53:27 +08:00
const {
selectedRowKeys,
formalModalVisible,
2022-08-25 17:54:18 +08:00
addCategoryVisible,
columns
2022-06-17 16:53:27 +08:00
} = this.state;
const rowSelection = {
selectedRowKeys,
onChange: this.onSelectChange,
getCheckboxProps: record => ({
disabled: !record.canDelete
})
};
2022-08-25 17:54:18 +08:00
const newColumns = [...columns, {
2022-08-25 17:54:18 +08:00
title: <span>
<WeaCheckbox
value={checkValue}
onChange={value => {
this.handleChangeAllItem(value);
2022-08-25 17:54:18 +08:00
}}
/>
<span style={{ marginLeft: 8 }}>隐藏</span>
</span>,
dataIndex: "itemHide",
key: "itemHide",
render: (text, record) => <WeaCheckbox
2022-08-25 17:54:18 +08:00
value={text ? String(text) : !text ? "0" : "1"}
onChange={value => {
this.handleChangeItem(value, record.id);
2022-08-25 17:54:18 +08:00
}}
/>
}];
2022-03-29 17:33:54 +08:00
2022-06-17 16:53:27 +08:00
return (
<div className="tableItemWrapper">
<div style={{ padding: "10px" }}>
<span className="itemTitle">
{this.props.title}
{this.props.title !== "未分类" &&
<span>
{!disabled &&
<Fragment>
<i
className="icon-coms-edit"
style={{
marginLeft: "10px",
marginRight: "10px",
cursor: "pointer"
}}
title="编辑"
2022-06-17 16:53:27 +08:00
onClick={() => {
this.handleEditGroupIconClick(this.props.title);
}}
2022-06-14 10:16:04 +08:00
/>
2022-06-17 16:53:27 +08:00
<i
className="icon-coms-Delete"
style={{ cursor: "pointer" }}
title="删除"
2022-06-17 16:53:27 +08:00
onClick={() => {
this.handleDeleteGroupIconClick();
}}
2022-03-29 17:33:54 +08:00
/>
2022-06-17 16:53:27 +08:00
</Fragment>}
</span>}
2022-07-28 17:16:40 +08:00
<span style={{
marginLeft: 10,
cursor: "pointer"
}}>
{
sortedIndex !== 0 &&
<i className="icon-coms-Reverse"
onClick={() => this.props.onUpgo(sortedIndex)}
title="向上移动"
2022-07-28 17:16:40 +08:00
style={{
marginRight: 10,
cursor: "pointer"
}}
/>
}
{
sortedIndex !== toJS(itemGroups).length - 1 &&
<i className="icon-coms-positive-sequence"
onClick={() => this.props.onDowngo(sortedIndex)}
title="向下移动"
2022-07-28 17:16:40 +08:00
style={{
cursor: "pointer"
}}
/>
}
</span>
2022-06-17 16:53:27 +08:00
</span>
<span className="rightBtnsWrapper">
{
!disabled &&
<React.Fragment>
<Button type="primary"
size="small"
onClick={() => {
this.handleDelete();
}}
><span className="icon-coms-form-delete-hot" title="删除"></span></Button>
<Button type="primary"
size="small"
style={{ marginRight: 10 }}
onClick={() => {
this.setState({ addItemVisible: true });
}}
><span className="icon-coms-Add-to-hot" title="添加"></span></Button>
</React.Fragment>
}
<i
className={this.state.showContent ? "icon-coms-down2" : "icon-coms-up2"}
style={{ cursor: "pointer",fontSize: 18 }}
2022-06-17 16:53:27 +08:00
onClick={() => {
this.handleTiggleContent();
}}
/>
</span>
</div>
{this.state.showContent &&
<WeaTable
rowSelection={rowSelection}
dataSource={this.props.dataSource}
2022-08-25 17:54:18 +08:00
columns={newColumns}
2022-06-17 16:53:27 +08:00
onRow={(record, index) => ({
index,
moveRow: record
})}
pagination={false}
onDrop={datas => this.props.onDataSourceChange(datas)}
draggable={true}
/>}
{this.state.addItemVisible &&
<AddSalaryItemModal
visible={this.state.addItemVisible}
title={this.props.title}
onCancel={() => {
this.setState({ addItemVisible: false });
}}
/>}
2022-04-20 15:28:40 +08:00
2022-06-17 16:53:27 +08:00
{formalModalVisible &&
<FormalFormModal
formulaId={this.formulaId}
2022-12-01 14:28:30 +08:00
valueType={this.record.valueType}
2022-06-17 16:53:27 +08:00
visible={formalModalVisible}
onSaveFormal={data => {
this.handleSaveFormal(data);
}}
onCancel={() =>
this.setState({
formalModalVisible: false
})}
/>}
{/* 编辑分类名称 */}
{addCategoryVisible &&
<AddCategoryModal
title={this.title}
onSave={value => {
this.handleUpdateCategorySave(value);
}}
visible={addCategoryVisible}
onCancel={() => {
this.setState({ addCategoryVisible: false });
}}
/>}
</div>
);
}
}