trunk/pc4mobx/organization/components/office/officeManage.js

511 lines
16 KiB
JavaScript
Raw Normal View History

2022-05-13 18:06:15 +08:00
import React, { Component } from "react";
import { toJS } from "mobx";
import { inject, observer } from "mobx-react";
import { i18n } from "../../public/i18n";
import LeftTree from "./components/leftTree";
import NewAndEditDialog from "../NewAndEditDialog";
import { WeaFormItem, WeaLeftRightLayout, WeaRightMenu, WeaTab, WeaTop } from "ecCom";
import { Button, Col, message, Modal, Row, Spin, Switch } from "antd";
2022-05-13 18:06:15 +08:00
import { WeaSwitch, WeaTableNew } from "comsMobx";
import "./index.less";
2022-06-22 16:09:43 +08:00
import { renderNoright } from "../../util";
2022-05-13 18:06:15 +08:00
2022-05-16 17:13:37 +08:00
const confirm = Modal.confirm;
const WeaTable = WeaTableNew.WeaTable;
2022-05-13 18:06:15 +08:00
@inject("officeManageStore")
@observer
export default class OfficeManage extends Component {
2022-05-16 17:13:37 +08:00
constructor(props) {
super(props);
this.state = {
date: "",
editId: "",
loading: false,
2022-06-22 16:09:43 +08:00
deleteOfficeClassifyFlag: false
2022-05-16 17:13:37 +08:00
};
}
2022-05-13 18:06:15 +08:00
componentDidMount() {
const { officeManageStore } = this.props;
2022-05-16 17:13:37 +08:00
officeManageStore.getTreeData && officeManageStore.getTreeData();
2022-05-13 18:06:15 +08:00
officeManageStore.getHasRight && officeManageStore.getHasRight();
2022-05-16 17:13:37 +08:00
officeManageStore.getPostInfoTable && officeManageStore.getPostInfoTable();
2022-05-13 18:06:15 +08:00
}
2022-05-13 18:06:15 +08:00
getDropMenuDatas = () => {
const { officeManageStore } = this.props;
const { rightMenu } = officeManageStore;
let menus = [];
toJS(rightMenu).map((item, index) => {
let obj = {
key: item.menuFun,
icon: <i className={`${item.menuIcon}`}/>,
2022-06-22 16:09:43 +08:00
content: item.menuName
2022-05-13 18:06:15 +08:00
};
if (
item.menuFun == "collection" ||
item.menuFun == "help" ||
item.menuFun == "pageAddress"
) {
obj.disabled = true;
}
menus.push(obj);
});
return menus;
};
2022-07-07 18:06:02 +08:00
showlog = () => {
window.setLogViewProp({
logMoudleType: 6,
keys: new Date().getTime(),
});
}
2022-06-22 16:09:43 +08:00
handleMenuClick = key => {
2022-05-16 17:13:37 +08:00
const { officeManageStore } = this.props;
const { isPanelShow, tableStore, officeClassifyId } = officeManageStore;
2022-05-16 17:13:37 +08:00
isPanelShow && officeManageStore.setPanelStatus(false);
switch (key) {
case "new":
officeManageStore.getPostInfoForm({ planId: officeClassifyId });
2022-05-16 17:13:37 +08:00
officeManageStore.setVisible(true);
officeManageStore.setNeDialogTitle(i18n.label.newOfficeName());
break;
2022-07-07 18:06:02 +08:00
case "log":
this.showlog();
break;
2022-05-25 14:58:27 +08:00
case "custom":
tableStore.setColSetVisible(true);
tableStore.tableColSet(true);
break;
2022-05-16 17:13:37 +08:00
default:
break;
}
};
2022-05-13 18:06:15 +08:00
2022-05-16 17:13:37 +08:00
handleSave() {
2022-06-22 16:09:43 +08:00
const {
form,
condition,
savePostInfo,
updatePostInfo
} = this.props.officeManageStore;
2022-05-16 17:13:37 +08:00
const { editId } = this.state;
2022-06-22 16:09:43 +08:00
form.validateForm().then(f => {
2022-05-16 17:13:37 +08:00
if (f.isValid) {
// 验证通过, balabala业务代码
const payload = editId
? { ...form.getFormParams(), id: editId }
: { ...form.getFormParams() };
this.setState({ loading: true });
if (editId) {
updatePostInfo(payload).then(({ code, msg }) => {
this.setState({ loading: false });
if (code === 200) {
message.success("编辑成功");
this.setState({ editId: "" }, () => {
this.props.officeManageStore.setVisible(false);
this.props.officeManageStore.getPostInfoTable(this.props.officeManageStore.officeClassifyId);
});
2022-05-16 17:13:37 +08:00
} else {
message.error(msg || "编辑失败");
}
});
return;
}
savePostInfo(payload).then(({ code, msg }) => {
this.setState({ loading: false });
if (code === 200) {
message.success("新增成功");
this.setState({ editId: "" }, () => {
this.props.officeManageStore.setVisible(false);
this.props.officeManageStore.getPostInfoTable(this.props.officeManageStore.officeClassifyId);
});
2022-05-16 17:13:37 +08:00
} else {
message.error(msg || "新增失败");
}
});
} else {
f.showErrors();
this.setState({ date: new Date() }); // 改变一个state的变量,强制页面刷新
}
});
}
2022-05-13 18:06:15 +08:00
getTopMenuBtns = () => {
const { officeManageStore } = this.props;
2022-06-22 16:09:43 +08:00
const { topMenu, tableStore, officeClassifyId } = officeManageStore;
2022-05-13 18:06:15 +08:00
let btns = [];
topMenu.map((item, i) => {
2022-06-22 16:09:43 +08:00
if (item.menuFun !== "batchDelete" && item.menuFun !== "delPlan") {
2022-05-13 18:06:15 +08:00
btns.push(
<Button
type="primary"
2022-06-22 16:09:43 +08:00
disabled={item.menuFun == "editPlan" && !officeClassifyId}
2022-05-13 18:06:15 +08:00
onClick={() => {
const { officeManageStore } = this.props;
2022-06-22 16:09:43 +08:00
if (item.menuFun == "new") {
officeManageStore.isPanelShow &&
officeManageStore.setPanelStatus(false);
officeManageStore.getPostInfoForm({ planId: officeClassifyId });
2022-06-22 16:09:43 +08:00
officeManageStore.setVisible(true);
officeManageStore.setNeDialogTitle(i18n.label.newOfficeName());
} else if (
item.menuFun == "addPlan" ||
item.menuFun == "editPlan"
) {
officeManageStore.getPostForm(
item.menuFun == "editPlan" ? officeClassifyId : ""
);
officeManageStore.setOfficeVisible({
bool: true,
type: item.menuFun
});
}
2022-05-13 18:06:15 +08:00
}}>
{item.menuName}
</Button>
);
2022-06-22 16:09:43 +08:00
} else if (item.menuFun === "delPlan") {
btns.push(
<Button
type="primary"
onClick={() => {
confirm({
title: i18n.confirm.defaultTitle(),
content: i18n.confirm.delete(),
okText: i18n.button.ok(),
cancelText: i18n.button.cancel(),
onOk: () => {
this.setState({
deleteOfficeClassifyFlag: !this.state
.deleteOfficeClassifyFlag
});
},
onCancel() {
return false;
}
});
}}
disabled={
!officeClassifyId ||
(officeClassifyId && !_.isEmpty(toJS(tableStore.datas)))
}>
{item.menuName}
</Button>
);
2022-05-13 18:06:15 +08:00
} else {
btns.push(
<Button
type="primary"
2022-05-16 17:13:37 +08:00
onClick={() => {
const { officeManageStore } = this.props;
const { tableStore } = officeManageStore;
const ids = toJS(tableStore.selectedRowKeys).toString();
this.showConfirm("batchDel", ids);
}}
disabled={tableStore.selectedRowKeys.length > 0 ? false : true}>
2022-05-13 18:06:15 +08:00
{item.menuName}
</Button>
);
}
});
return btns;
};
2022-05-16 17:13:37 +08:00
showConfirm = (v, ids) => {
confirm({
title: i18n.confirm.defaultTitle(),
content:
v == "del" ? i18n.confirm.delete() : i18n.confirm.batchDeleteConfirm(),
okText: i18n.button.ok(),
cancelText: i18n.button.cancel(),
onOk: () => this.deletePostinfoByIds(ids),
onCancel() {
return false;
2022-06-22 16:09:43 +08:00
}
2022-05-16 17:13:37 +08:00
});
};
2022-06-22 16:09:43 +08:00
deletePostinfoByIds = ids => {
2022-05-16 17:13:37 +08:00
const { officeManageStore } = this.props;
const { deletePostinfoByIds } = officeManageStore;
deletePostinfoByIds({ ids }).then(({ code, msg }) => {
if (code === 200) {
message.success("删除成功");
officeManageStore.getPostInfoTable(officeManageStore.officeClassifyId);
2022-05-16 17:13:37 +08:00
} else {
message.error(msg || "删除失败");
}
});
};
2022-06-22 16:09:43 +08:00
reRenderColumns = columns => {
2022-05-16 17:13:37 +08:00
let _this = this;
columns.forEach((c, index) => {
if (c.dataIndex == "forbidden_tag") {
c.render = function (text, record) {
2022-05-16 17:13:37 +08:00
return (
<Switch
checked={record.forbidden_tag == "0" ? true : false}
2022-06-22 16:09:43 +08:00
onChange={checked => {
2022-05-16 17:13:37 +08:00
confirm({
title: i18n.confirm.defaultTitle(),
content:
2022-06-22 16:09:43 +08:00
record.forbidden_tag === "0" ? "确定禁用该记录吗?" : "确定启用该记录吗?",
2022-05-16 17:13:37 +08:00
okText: i18n.button.ok(),
cancelText: i18n.button.cancel(),
onOk: () => _this.updateForbiddenTag(checked, record.id),
onCancel() {
return false;
2022-06-22 16:09:43 +08:00
}
2022-05-16 17:13:37 +08:00
});
}}
/>
);
};
}
});
};
updateForbiddenTag = (forbiddentag, id) => {
const { officeManageStore } = this.props;
const { updateForbiddenTagById } = officeManageStore;
const payload = {
id,
2022-06-22 16:09:43 +08:00
forbiddentag
2022-05-16 17:13:37 +08:00
};
updateForbiddenTagById(payload).then(({ code, msg }) => {
if (code === 200) {
message.success("操作成功");
2022-09-02 11:00:27 +08:00
officeManageStore.getPostInfoTable(officeManageStore.officeClassifyId,true);
2022-05-16 17:13:37 +08:00
} else {
message.error(msg || "操作失败");
}
});
};
onOperatesClick = (record, index, operate) => {
operate.index == "0" && this.doEdit(record.randomFieldId);
operate.index === "1" && this.showConfirm("del", record.randomFieldId);
};
2022-06-22 16:09:43 +08:00
doEdit = editId => {
2022-05-16 17:13:37 +08:00
this.setState({ editId });
const { officeManageStore } = this.props;
officeManageStore.isPanelShow && officeManageStore.setPanelStatus(false);
officeManageStore.getPostInfoForm({ id: editId });
2022-05-16 17:13:37 +08:00
officeManageStore.setVisible(true);
officeManageStore.setNeDialogTitle(i18n.label.editOfficeName());
};
2022-05-13 18:06:15 +08:00
getPanelComponents = () => {
const { officeManageStore } = this.props;
2022-06-22 16:09:43 +08:00
const {
searchCondition,
form2,
searchConditionLoading
} = officeManageStore;
2022-05-13 18:06:15 +08:00
let arr = [];
let formParams = form2.getFormParams();
const { isFormInit } = form2;
isFormInit &&
searchCondition.map(c => {
c.items.map((field, index) => {
arr.push(
<Col
ecId={`${(this && this.props && this.props.ecId) ||
""}_Col@4cc308@${index}`}
span={index % 2 == 0 ? 10 : 11}
offset={1}>
<div style={{ marginTop: 20 }}>
<WeaFormItem
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaFormItem@u6ex85@${index}`}
label={`${field.label}`}
labelCol={{ span: `${field.labelcol}` }}
wrapperCol={{ span: `${field.fieldcol}` }}>
{
<WeaSwitch
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaSwitch@p7d3td@${index}`}
fieldConfig={field}
form={form2}
formParams={formParams}
/>
}
</WeaFormItem>
</div>
</Col>
);
2022-05-13 18:06:15 +08:00
});
});
2022-05-13 18:06:15 +08:00
if (searchConditionLoading) {
return (
<div className="hrm-loading-center-small" style={{ top: "25%" }}>
<Spin
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_Spin@lbktzb`}
2022-06-22 16:09:43 +08:00
spinning={searchConditionLoading}
/>
2022-05-13 18:06:15 +08:00
</div>
);
} else {
return (
<Row
ecId={`${(this && this.props && this.props.ecId) || ""}_Row@ppeb6z`}
2022-06-22 16:09:43 +08:00
onKeyDown={e => {
2022-05-16 17:13:37 +08:00
if (e.keyCode == 13 && e.target.tagName === "INPUT") {
officeManageStore.getPostInfoTable();
officeManageStore.setPanelStatus(false);
}
}}>
2022-05-13 18:06:15 +08:00
{arr}
</Row>
);
}
};
getTabBtn = () => {
const { officeManageStore } = this.props;
2022-05-16 17:13:37 +08:00
const { form2 } = officeManageStore;
2022-05-13 18:06:15 +08:00
const btn = [
<Button
ecId={`${(this && this.props && this.props.ecId) || ""}_Button@bx87i8`}
type="primary"
onClick={() => {
2022-05-16 17:13:37 +08:00
officeManageStore.getPostInfoTable();
officeManageStore.setPanelStatus(false);
2022-05-13 18:06:15 +08:00
}}>
{i18n.button.search()}
</Button>,
<Button
ecId={`${(this && this.props && this.props.ecId) || ""}_Button@218ju6`}
onClick={() => form2.reset()}>
{i18n.button.reset()}
</Button>,
<Button
ecId={`${(this && this.props && this.props.ecId) || ""}_Button@5u9mfz`}
2022-05-16 17:13:37 +08:00
onClick={() => officeManageStore.setPanelStatus(false)}>
2022-05-13 18:06:15 +08:00
{i18n.button.cancel()}
2022-06-22 16:09:43 +08:00
</Button>
2022-05-13 18:06:15 +08:00
];
return btn;
};
2022-06-22 16:09:43 +08:00
onSearchChange = val => {
2022-05-13 18:06:15 +08:00
const { officeManageStore } = this.props;
const { form2 } = officeManageStore;
2022-05-16 17:13:37 +08:00
officeManageStore.setPostInfoName(val);
2022-05-13 18:06:15 +08:00
!_.isEmpty(form2.getFormParams()) && officeManageStore.updateFields(val);
};
render() {
const { officeManageStore } = this.props;
2022-06-22 16:09:43 +08:00
const { date, loading, deleteOfficeClassifyFlag } = this.state;
2022-05-13 18:06:15 +08:00
const {
isPanelShow,
form2,
2022-05-16 17:13:37 +08:00
postInfoName,
2022-05-13 18:06:15 +08:00
conditionNum,
tableStore,
nEdialogTitle,
visible,
condition,
form,
dialogLoading,
2022-06-07 16:52:12 +08:00
hasRight
2022-05-13 18:06:15 +08:00
} = officeManageStore;
2022-06-07 16:52:12 +08:00
if (hasRight === false) {
return renderNoright();
}
2022-06-22 16:09:43 +08:00
2022-05-13 18:06:15 +08:00
return (
2022-08-18 17:42:15 +08:00
hasRight && <div className="office-wapper">
2022-05-13 18:06:15 +08:00
<WeaLeftRightLayout
isNew={true}
2022-09-02 16:17:54 +08:00
leftWidth={260}
2022-06-22 16:09:43 +08:00
leftCom={
<LeftTree deleteOfficeClassifyFlag={deleteOfficeClassifyFlag}/>
2022-06-22 16:09:43 +08:00
}
onCollapse={showLeft => console.log("showLeft:", showLeft)}>
2022-05-13 18:06:15 +08:00
<WeaRightMenu
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaRightMenu@cea97d`}
2022-05-13 18:06:15 +08:00
datas={this.getDropMenuDatas()}
2022-06-22 16:09:43 +08:00
onClick={key => this.handleMenuClick(key)}>
2022-05-13 18:06:15 +08:00
<WeaTop
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaTop@446d12`}
2022-05-16 17:13:37 +08:00
title={i18n.label.officeName()}
icon={<i className="icon-coms-hrm"/>}
2022-05-13 18:06:15 +08:00
iconBgcolor="#217346"
loading={true}
buttons={this.getTopMenuBtns()}
showDropIcon={true}
dropMenuDatas={this.getDropMenuDatas()}
2022-06-22 16:09:43 +08:00
onDropMenuClick={e => this.handleMenuClick(e)}>
2022-05-13 18:06:15 +08:00
<WeaTab
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaTab@39c727`}
2022-05-13 18:06:15 +08:00
searchType={["base", "advanced"]}
showSearchAd={isPanelShow}
searchsBaseValue={
_.isEmpty(form2.getFormParams())
2022-05-16 17:13:37 +08:00
? postInfoName
: form2.getFormParams().postInfoName
2022-05-13 18:06:15 +08:00
}
2022-06-22 16:09:43 +08:00
setShowSearchAd={bool => officeManageStore.setPanelStatus(bool)}
2022-05-13 18:06:15 +08:00
hideSearchAd={() => officeManageStore.setPanelStatus(false)}
searchsAd={isPanelShow ? this.getPanelComponents() : <div/>}
2022-05-13 18:06:15 +08:00
advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20}
hasMask={false}
buttonsAd={this.getTabBtn()}
2022-05-16 17:13:37 +08:00
onSearch={() => officeManageStore.getPostInfoTable()}
2022-06-22 16:09:43 +08:00
onSearchChange={val => this.onSearchChange(val)}
2022-05-13 18:06:15 +08:00
/>
2022-05-16 17:13:37 +08:00
<WeaTable
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_WeaTable@b43a4c`}
2022-05-13 18:06:15 +08:00
comsWeaTableStore={tableStore}
hasOrder={true}
needScroll={true}
2022-05-16 17:13:37 +08:00
rowSelection={{
2022-06-22 16:09:43 +08:00
getCheckboxProps: record => {
2022-05-16 17:13:37 +08:00
console.log(record);
return {
2022-06-22 16:09:43 +08:00
disabled: true // 配置无法勾选的列
2022-05-16 17:13:37 +08:00
};
2022-06-22 16:09:43 +08:00
}
2022-05-16 17:13:37 +08:00
}}
2022-06-22 16:09:43 +08:00
getColumns={c => this.reRenderColumns(c)}
2022-05-13 18:06:15 +08:00
onOperatesClick={(record, index, operate) =>
2022-06-22 16:09:43 +08:00
this.onOperatesClick(record, index, operate)}
2022-05-16 17:13:37 +08:00
/>
2022-05-13 18:06:15 +08:00
</WeaTop>
<NewAndEditDialog
2022-06-22 16:09:43 +08:00
ecId={`${(this && this.props && this.props.ecId) ||
""}_NewAndEditDialog@q4rrwm`}
2022-05-13 18:06:15 +08:00
title={nEdialogTitle}
visible={visible}
condition={toJS(condition)}
form={form}
isFormInit={form.isFormInit}
2022-05-16 17:13:37 +08:00
loading={dialogLoading || loading}
isEdit={true}
2022-05-13 18:06:15 +08:00
height={250}
conditionLen={3}
2022-05-16 17:13:37 +08:00
save={() => this.handleSave()}
onCancel={() => {
officeManageStore.setVisible(false);
this.setState({ editId: "" });
}}
2022-05-13 18:06:15 +08:00
/>
</WeaRightMenu>
</WeaLeftRightLayout>
</div>
);
}
}