trunk/pc4mobx/organization/components/columnSetting/permissionItem.js

90 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-11-07 16:35:58 +08:00
import React, { Component } from "react";
2022-11-08 17:43:26 +08:00
import { WeaTableNew } from "comsMobx";
2022-11-09 14:03:32 +08:00
import { WeaBrowser, WeaCheckbox } from "ecCom";
2022-11-08 15:56:34 +08:00
import { inject, observer } from "mobx-react";
2022-11-09 14:03:32 +08:00
import { toJS } from "mobx";
2022-11-08 17:43:26 +08:00
const WeaTable = WeaTableNew.WeaTable;
2022-11-07 16:35:58 +08:00
2022-11-10 18:50:45 +08:00
@inject("columnSetting")
2022-11-08 15:56:34 +08:00
@observer
2022-11-07 16:35:58 +08:00
class PermissionItem extends Component {
2022-11-08 15:56:34 +08:00
componentDidMount() {
this.init();
}
init = () => {
2022-11-10 18:50:45 +08:00
const { columnSetting } = this.props;
columnSetting.loadTabOneRelatedData();
2022-11-08 15:56:34 +08:00
};
2022-11-09 14:03:32 +08:00
changeSaveParams = (record, value, dataIndex) => {
2022-11-10 18:50:45 +08:00
const { columnSetting } = this.props;
const list = _.isEmpty(columnSetting.columnsPermissionData) ? toJS(columnSetting.tableStore.datas) : columnSetting.columnsPermissionData;
2022-11-09 14:03:32 +08:00
const dataSource = _.map([...list], it => {
if (record.id === it.id) {
return {
...it,
[dataIndex]: value
};
}
return { ...it };
});
2022-11-10 18:50:45 +08:00
columnSetting.setColumnsPermissionData(dataSource);
2022-11-09 14:03:32 +08:00
};
2022-11-08 17:43:26 +08:00
renderRenderColumns = columns => {
columns.forEach((c, index) => {
if (c.dataIndex === "status" || c.dataIndex === "all_people" ||
c.dataIndex === "superior" || c.dataIndex === "all_superior") {
2022-11-09 14:03:32 +08:00
c.render = (text, record) => {
2022-11-08 17:43:26 +08:00
return (
<WeaCheckbox
2022-11-09 14:03:32 +08:00
value={record[c.dataIndex]}
onChange={value => {
this.changeSaveParams(record, value, c.dataIndex);
}}
2022-11-08 17:43:26 +08:00
/>
);
};
} else if (c.dataIndex === "custom") {
2022-11-09 14:03:32 +08:00
c.render = (text, record) => {
2022-11-10 16:10:21 +08:00
const custom = record[c.dataIndex].split(",");
const customspan = record[`${c.dataIndex}span`].split(",");
const replaceDatas = _.map(custom, (item, index) => ({ id: custom[index], name: customspan[index] }));
2022-11-08 17:43:26 +08:00
return (
2022-11-09 14:03:32 +08:00
<WeaBrowser
inputStyle={{ width: 200 }}
type={65}
2022-11-09 17:02:55 +08:00
isSingle={false}
2022-11-09 14:03:32 +08:00
title="多角色"
linkUrl="/spa/hrm/engine.html#/hrmengine/roleInfo/info?id="
2022-11-10 16:10:21 +08:00
replaceDatas={replaceDatas}
2022-11-09 14:03:32 +08:00
onChange={value => {
this.changeSaveParams(record, value, c.dataIndex);
}}
/>
2022-11-08 17:43:26 +08:00
);
};
}
});
};
2022-11-08 15:56:34 +08:00
2022-11-07 16:35:58 +08:00
render() {
2022-11-10 18:50:45 +08:00
const { columnSetting } = this.props, { tableStore } = columnSetting;
2022-11-07 16:35:58 +08:00
return (
<div>
2022-11-08 17:43:26 +08:00
<WeaTable
ecId={`${(this && this.props && this.props.ecId) || ""}_WeaTable@b43a4c`}
comsWeaTableStore={tableStore}
hasOrder={true}
needScroll={true}
getColumns={c => this.renderRenderColumns(c)}
onOperatesClick={(record, index, operate) =>
this.onOperatesClick(record, index, operate)}
2022-11-07 16:35:58 +08:00
/>
</div>
);
}
}
export default PermissionItem;