trunk/pc4mobx/organization/components/resource/resource.js

609 lines
20 KiB
JavaScript
Raw Normal View History

2022-06-20 17:08:10 +08:00
import React from 'react'
import * as mobx from 'mobx'
import {
inject,
observer,
} from 'mobx-react'
import {
WeaTop,
WeaTab,
2023-01-10 18:23:25 +08:00
WeaInput,
2022-06-20 17:08:10 +08:00
WeaFormItem,
WeaRightMenu,
WeaLeftRightLayout,
WeaOrgTree,
2023-01-05 18:02:33 +08:00
WeaDropdown,
2023-01-06 18:01:46 +08:00
WeaSelect,
2024-06-14 16:25:07 +08:00
WeaSearchGroup,
WeaLocaleProvider
2022-06-20 17:08:10 +08:00
} from 'ecCom'
import {
Row,
Col,
Spin,
Modal,
Button,
message,
Switch,
2023-01-05 18:02:33 +08:00
Select,
2022-06-20 17:08:10 +08:00
Menu, Dropdown, Icon
} from 'antd'
import {
WeaSwitch,
WeaTableNew
} from 'comsMobx'
import {
i18n
} from '../../public/i18n';
import NewAndEditDialog from '../NewAndEditDialog';
import { renderNoright } from '../../util';
2022-06-29 18:37:25 +08:00
import DatasImport from '../import/datasImport';
2023-01-05 18:02:33 +08:00
import SearchCustomDialog from './SearchCustomDialog';
2023-01-11 18:22:30 +08:00
import NewWeaTableEditDialog from '../NewWeaTableEditDialog';
2023-08-08 14:28:49 +08:00
import GroupList from './GroupList';
2022-06-20 17:08:10 +08:00
const toJS = mobx.toJS;
const confirm = Modal.confirm;
const WeaTable = WeaTableNew.WeaTable;
2022-06-29 18:37:25 +08:00
const { ButtonSelect } = WeaDropdown;
2024-06-14 16:25:07 +08:00
const getLabel = WeaLocaleProvider.getLabel;
2022-06-20 17:08:10 +08:00
2024-08-27 16:13:10 +08:00
const viewDepartment = (id) => {
window.open(`/spa/hrm/engine.html#/hrmengine/organization?showTree=false&isView=1&type=department&id=${id}`);
}
const viewSubCompany = (id) => {
window.open(`/spa/hrm/engine.html#/hrmengine/organization?showTree=false&isView=1&type=subcompany&id=${id}`);
}
window.viewDepartment = viewDepartment;
window.viewSubCompany = viewSubCompany;
2022-06-20 17:08:10 +08:00
@inject('resource')
2022-06-27 18:48:28 +08:00
@inject('datasImport')
2022-06-20 17:08:10 +08:00
@observer
export default class Resource extends React.Component {
constructor(props) {
super(props);
}
componentWillMount() {
}
componentDidMount() {
this.init();
}
componentWillReceiveProps(nextProps) {
const {
resource
} = this.props;
if (this.props.location.key !== nextProps.location.key) {
this.init();
}
}
init() {
const {
resource
} = this.props;
2024-07-25 18:50:53 +08:00
2022-06-20 17:08:10 +08:00
resource.getHasRight();
2024-07-25 18:50:53 +08:00
//1.获取快捷搜索内容
2023-08-16 13:58:08 +08:00
resource.getQuickSearchCondition();
2023-01-05 18:02:33 +08:00
let { hash } = window.location;
2022-11-01 17:48:33 +08:00
hash = hash.split("?")[1].split("&");
2023-01-05 18:02:33 +08:00
if (hash.length >= 2) {
2022-11-01 17:48:33 +08:00
let params = {};
2023-01-05 18:02:33 +08:00
let arr = hash[0].split("=");
2022-11-01 17:48:33 +08:00
params[arr[0]] = arr[1];
resource.doSearch(params);
2023-01-05 18:02:33 +08:00
} else {
2022-11-01 17:48:33 +08:00
resource.getTableInfo();
}
2022-06-20 17:08:10 +08:00
}
//左侧树
getTree = () => {
const {
resource
} = this.props;
const {
companysId,
} = resource
let tree = (
<WeaOrgTree ecId={`${this && this.props && this.props.ecId || ''}_WeaOrgTree@dhi1ro`}
ref='WeaOrgTree'
2022-06-21 18:39:50 +08:00
dataUrl={"/api/bs/hrmorganization/hrmresource/getSearchTree"}
2022-06-20 17:08:10 +08:00
loading
needSearch
noCache={true}
needDropMenu={false}
//onSelect={this.selectVirtual} //组织维度回调函数
isLoadSubDepartment={true}
topPrefix={'hrmSearch'}
companysId={companysId}
inputLeftDom={`<b>${i18n.label.organization()}</b>`}
treeNodeClick={this.treeNodeClick}
expandAllChildrenOnSearch={true}
2022-10-18 13:58:48 +08:00
renderNode={item => this.renderNode(item)}
2022-06-20 17:08:10 +08:00
/>
)
return tree;
}
2022-10-18 13:58:48 +08:00
renderNode(item) {
return <div className='text-elli' title={item.name}>
<i className={item.icon} style={{ marginRight: '5px' }}></i>
{item.name}
{item.canceled && <span style={{ color: 'red' }}>({i18n.label.forbidden()})</span>}
</div>
}
2022-10-21 17:51:28 +08:00
treeNodeClick = (event, ids, nodeids, nodes) => {
const {
resource
} = this.props;
const {
form2,
companysId
} = resource;
const type = event.node.props.type || '0';
const id = event.node.props.id || '';
let params = {};
2024-07-25 18:50:53 +08:00
form2.resetForm();
2022-10-21 17:51:28 +08:00
resource.setPanelStatus(false)
// resource.tabkey = 'default_3';
resource.nodeType = type;
if (type == '0') {
params['virtualtype'] = companysId;
}
if (type == '1') {
params['companyId'] = id;
}
if (type == '2') {
params['departmentId'] = id;
}
if (type == '3') {
params['jobTitle'] = id;
}
resource.doSearch(params);
}
2022-10-18 13:58:48 +08:00
2022-06-20 17:08:10 +08:00
getTopMenuBtns() {
const {
resource
} = this.props;
const {
topMenu,
tableStore
} = resource;
let btns = [];
topMenu.map((item, i) => {
if (item.menuFun !== 'batchDelete') {
btns.push(<Button type='primary' onClick={() => this.handleClick(item)}>{item.menuName}</Button>);
} else {
btns.push(<Button type='primary' onClick={() => this.handleClick(item)} disabled={tableStore.selectedRowKeysAllPages.length > 0 ? false : true} >{item.menuName}</Button>);
2022-06-20 17:08:10 +08:00
}
});
2022-06-29 18:37:25 +08:00
const datas = [
{
2024-06-14 16:25:07 +08:00
key: "1", show: (<span>{i18n.button.allExport()}</span>), text: `${i18n.button.allExport()}`, selected: true
2022-06-29 18:37:25 +08:00
},
{
2024-06-14 16:25:07 +08:00
key: "2", show: (<span>{i18n.button.batchExport()}</span>), text: `${i18n.button.batchExport()}`
2022-06-29 18:37:25 +08:00
}
];
btns.push(<ButtonSelect
datas={datas}
btnOnClick={key => {
if (key == "1") {
tableStore.selectedRowKeysAllPages = [];
2022-06-29 18:37:25 +08:00
resource.export();
}
2023-01-05 18:02:33 +08:00
if (key == "2") {
2024-06-13 11:40:45 +08:00
tableStore.selectedRowKeysAllPages.length > 0 ? resource.export() : message.error(`${i18n.message.checkExport()}`)
2022-06-29 18:37:25 +08:00
}
}}
menuOnClick={(key, e) => key == '1' ? tableStore.selectedRowKeysAllPages = [] : ''}
2022-06-29 18:37:25 +08:00
/>)
2022-06-20 17:08:10 +08:00
return btns;
}
handleClick(item) {
const {
resource
} = this.props;
const {
isPanelShow
} = resource;
isPanelShow && resource.setPanelStatus(false);
this[item.menuFun] && this[item.menuFun]();
}
2022-07-07 18:06:02 +08:00
log = () => {
window.setLogViewProp({
logMoudleType: 11,
keys: new Date().getTime(),
});
}
2022-06-20 17:08:10 +08:00
new() {
const {
resource
} = this.props;
2022-11-29 16:59:04 +08:00
// resource.setNeDialogTitle(i18n.label.newPeople());
// resource.setIsNew(true);
// resource.setVisible(true);
// resource.getForm();
2023-01-05 18:02:33 +08:00
window.open("/spa/hrm/index_mobx.html#/main/hrm/add", "_blank")
2022-06-20 17:08:10 +08:00
}
2024-06-14 16:25:07 +08:00
// import() {
// const {
// datasImport
// } = this.props;
// datasImport.visible = true;
// datasImport.title = i18n.button.importResource();
// datasImport.importType = 'resource';
// datasImport.getImportForm();
// }
2022-06-27 18:48:28 +08:00
2022-06-20 17:08:10 +08:00
getDropMenuDatas() {
const {
resource
} = this.props;
const {
rightMenu
} = resource;
let menus = [];
toJS(rightMenu).map((item, index) => {
let obj = {
key: item.menuFun,
icon: <i className={`${item.menuIcon}`} />,
content: item.menuName,
}
if (item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
obj.disabled = true;
}
menus.push(obj);
})
return menus;
}
handleMenuClick(key) {
const {
resource
} = this.props;
const {
isPanelShow
} = resource;
isPanelShow && resource.setPanelStatus(false);
this[key] && this[key]();
}
2023-01-10 18:23:25 +08:00
//列定制
customization() {
const {
resource
} = this.props;
2024-07-25 18:50:53 +08:00
resource.openCustomDialog();
2023-01-10 18:23:25 +08:00
}
//存为模板
saveTemplate() {
const {
resource
} = this.props, {
searchTemplateName
} = resource;
confirm({
2024-06-14 16:25:07 +08:00
title: getLabel(547548,'存为模板'),
2023-08-08 14:28:49 +08:00
content:
2023-01-10 18:23:25 +08:00
<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@62kt85`}
2024-06-14 16:25:07 +08:00
label= {getLabel(547654,'搜索模板名称')}
2023-01-10 18:23:25 +08:00
labelCol={{ span: 10 }}
wrapperCol={{ span: 14 }}>
<WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@j9bmvw`} viewAttr="3" value={searchTemplateName} {...window.inputType} onChange={v => resource.searchTemplateName = v} />
</WeaFormItem>,
okText: i18n.button.save(),
cancelText: i18n.button.cancel(),
onOk() {
resource.saveTemplate();
},
onCancel() {
return false;
},
});
}
2022-06-20 17:08:10 +08:00
getTabBtn() {
const {
resource
} = this.props;
const {
form2
} = resource;
const btn = [
2023-08-02 17:12:23 +08:00
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bx87i8`} type="primary" onClick={() => {
2024-07-30 16:22:54 +08:00
resource.isBaseValue = false;
resource.selectTreeNodeInfo = {}; resource.setPanelStatus(false);resource.getTableInfo();
2023-08-08 14:28:49 +08:00
}}>{i18n.button.search()}</Button>),
2023-01-10 18:23:25 +08:00
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@218ju6`} type="primary" onClick={() => this.saveTemplate()}>{i18n.button.saveTemplate()}</Button>),
2024-07-25 18:50:53 +08:00
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@218ju7`} type="primary" onClick={() => resource.openSearchDialog()}>{i18n.button.conditionSet()}</Button>),
2023-01-05 18:02:33 +08:00
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@218ju8`} onClick={() => form2.reset()}>{i18n.button.reset()}</Button>),
2022-06-20 17:08:10 +08:00
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5u9mfz`} onClick={() => resource.setPanelStatus(false)}>{i18n.button.cancel()}</Button>),
];
return btn;
}
custom = () => {
const {
resource
} = this.props, {
tableStore,
} = resource;
tableStore.setColSetVisible(true);
tableStore.tableColSet(true);
}
onSearchChange(val) {
const {
resource
} = this.props;
const {
form2
} = resource;
2022-10-21 17:51:28 +08:00
resource.setLastName(val);
2022-06-20 17:08:10 +08:00
!this.isEmptyObject(form2.getFormParams()) && resource.updateFields(val);
}
reRenderColumns(columns) {
let _this = this;
columns.forEach((c, index) => {
2023-01-16 09:50:36 +08:00
c.className = "wea-table-indent"
2022-12-08 18:06:21 +08:00
if (c.dataIndex == 'lastname') {
2022-06-21 18:39:50 +08:00
c.render = function (text, record) {
return <a href='javascript:void(0);' onClick={() => {
2022-10-18 13:58:48 +08:00
window.open(`/spa/organization/static/index.html#/main/organization/resourceCard/${record.id}`);
2022-06-21 18:39:50 +08:00
}}>{text}</a>
}
}
2022-06-20 17:08:10 +08:00
})
}
onOperatesClick(record, rowIndex, operate) {
const {
index
} = operate;
2022-10-18 13:58:48 +08:00
(index == '0') && this.view(record.randomFieldId);
2022-12-09 14:47:19 +08:00
(index == '1') && this.version(record);
2022-06-20 17:08:10 +08:00
}
2022-10-18 13:58:48 +08:00
view(id) {
window.open(`/spa/organization/static/index.html#/main/organization/resourceCard/${id}`);
2022-06-20 17:08:10 +08:00
}
2022-12-09 14:47:19 +08:00
version(record) {
const {
resource
} = this.props;
confirm({
title: i18n.confirm.defaultTitle(),
content: `确认将{${record.lastname}}存为新版本?`,
okText: i18n.button.ok(),
cancelText: i18n.button.cancel(),
onOk() {
2022-12-14 16:17:15 +08:00
resource.version(record.id);
2022-12-09 14:47:19 +08:00
},
onCancel() {
return false;
},
});
}
2022-06-20 17:08:10 +08:00
handleSave() {
const {
resource
} = this.props;
const {
isNew
} = resource;
isNew && resource.save();
!isNew && resource.edit();
}
2022-06-23 11:53:57 +08:00
2022-06-20 17:08:10 +08:00
getPanelComponents() {
const {
resource
} = this.props;
const {
2023-01-06 18:01:46 +08:00
defaultCondition,
2022-06-20 17:08:10 +08:00
form2,
2023-01-06 18:01:46 +08:00
searchConditionLoading,
2023-01-10 18:23:25 +08:00
templates,
searchTemplateId
2022-06-20 17:08:10 +08:00
} = resource;
let arr = [];
let formParams = form2.getFormParams();
const {
isFormInit
} = form2;
2024-07-25 18:50:53 +08:00
arr.push(<Row style={{ marginTop: 20 }}>
<Col offset={1} span={2}><span style={{ "lineHeight": "30px", "color": "red" }}>{getLabel(547655,'模板选择')}</span></Col>
<Col span={6} offset={1}>
<WeaSelect
style={{ width: "100%" }}
options={templates}
value={searchTemplateId}
onChange={v => {
resource.changeSearchTemplate(v)
}}
/>
</Col>
<Col offset={1} span={2}><Button onClick={() => resource.deleteSearchTemplate()}>{getLabel(547656,'删除模板 ')}</Button></Col>
</Row>)
2024-07-15 16:59:03 +08:00
isFormInit && templates.length > 0 && defaultCondition.map((c, i) => {
2023-01-06 18:01:46 +08:00
let _arr = [];
2022-06-20 17:08:10 +08:00
c.items.map((field, index) => {
2023-01-06 18:01:46 +08:00
_arr.push({
com: (
2022-06-20 17:08:10 +08:00
<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>
2023-01-06 18:01:46 +08:00
),
})
2022-06-20 17:08:10 +08:00
})
2024-07-25 18:50:53 +08:00
2024-07-15 16:59:03 +08:00
2024-07-25 18:50:53 +08:00
arr.push(<WeaSearchGroup className='organization-search' ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@qaih5l@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={_arr} col={2} />)
2022-06-20 17:08:10 +08:00
})
2023-01-10 18:23:25 +08:00
2022-06-20 17:08:10 +08:00
if (searchConditionLoading) {
return (
<div className='hrm-loading-center-small' style={{ top: '25%' }}>
<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@lbktzb`} spinning={searchConditionLoading}></Spin>
</div>
)
} else {
2023-01-10 18:23:25 +08:00
return <div onKeyDown={(e) => {
2022-06-20 17:08:10 +08:00
if (e.keyCode == 13 && e.target.tagName === "INPUT") {
2023-01-06 18:01:46 +08:00
rankScheme.getTableInfo();
rankScheme.setPanelStatus(false)
2022-06-20 17:08:10 +08:00
}
2023-01-06 18:01:46 +08:00
}}>{arr}</div>
2022-06-20 17:08:10 +08:00
}
}
isEmptyObject(obj) {
for (let key in obj) {
return false;
}
return true;
}
2024-07-10 16:52:53 +08:00
getTableWidth = (columns) => {
const columnLength = columns.filter((col)=>col.display === 'true').length;
if(columnLength>10){
2024-08-27 14:42:37 +08:00
return columnLength*100;
2024-07-10 16:52:53 +08:00
}else{
return '100%'
}
}
2022-06-20 17:08:10 +08:00
render() {
const {
2023-01-06 18:01:46 +08:00
resource: store
2022-06-20 17:08:10 +08:00
} = this.props;
const {
2022-06-29 18:37:25 +08:00
isPanelShow, form2, lastName, conditionNum, tableStore, nEdialogTitle, visible, condition,
2024-05-08 16:35:18 +08:00
form, dialogLoading, isEdit, date, hasRight, defaultShowLeft,enable,exSpinning
2023-08-08 14:28:49 +08:00
} = store;
2022-06-20 17:08:10 +08:00
if (hasRight === false) {
return renderNoright();
}
2024-07-10 16:52:53 +08:00
2022-06-20 17:08:10 +08:00
return (
hasRight && <div ref='page' style={{ height: '100%' }}>
<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@k6oc4u`}
datas={this.getDropMenuDatas()}
onClick={key => this.handleMenuClick(key)}
>
<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@bj98s7`}
2022-06-27 18:48:28 +08:00
title={i18n.label.resourceMange()}
2022-06-20 17:08:10 +08:00
icon={<i className='icon-coms-hrm' />}
iconBgcolor='#217346'
loading={true}
buttons={this.getTopMenuBtns()}
showDropIcon={true}
dropMenuDatas={this.getDropMenuDatas()}
onDropMenuClick={(e) => this.handleMenuClick(e)}
>
<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@7muhhb`} isNew={true} showLeft={defaultShowLeft} leftCom={this.getTree()}>
<WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@9c3zts`}
searchType={['base', 'advanced']}
showSearchAd={isPanelShow}
2024-07-30 16:22:54 +08:00
searchsBaseValue={this.isEmptyObject(form2.getFormParams()) ? lastName : form2.getFormParams()["-1_hrm_lastname"]}
2024-06-14 16:25:07 +08:00
searchsBasePlaceHolder=''
2023-08-08 14:28:49 +08:00
setShowSearchAd={bool => store.setPanelStatus(bool)}
hideSearchAd={() => store.setPanelStatus(false)}
2022-06-20 17:08:10 +08:00
searchsAd={isPanelShow ? this.getPanelComponents() : <div></div>}
advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20}
hasMask={false}
buttonsAd={this.getTabBtn()}
2024-06-11 18:55:29 +08:00
onSearch={() => {
2024-07-30 16:22:54 +08:00
store.isBaseValue = true;
store.hideRadioGroup();store.getTableInfo();
}}
2022-06-20 17:08:10 +08:00
onSearchChange={val => this.onSearchChange(val)}
/>
2024-06-14 16:25:07 +08:00
<Spin size="large" spinning={exSpinning} tip={getLabel(547647,'正在导出请稍候....')} className="hrm-loading-center-small"/>
2023-08-16 13:58:08 +08:00
{enable && <GroupList ecId={`${this && this.props && this.props.ecId || ''}_GroupList@2le78y`} store={store} />}
2022-06-20 17:08:10 +08:00
<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@pgmg3x`}
comsWeaTableStore={tableStore}
hasOrder={true}
needScroll={true}
getColumns={c => this.reRenderColumns(c)}
onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}
2024-07-10 16:52:53 +08:00
tableWidth={this.getTableWidth}
2022-06-20 17:08:10 +08:00
/>
</WeaLeftRightLayout>
</WeaTop>
</WeaRightMenu>
<NewAndEditDialog ecId={`${this && this.props && this.props.ecId || ''}_NewAndEditDialog@q4rrwm`}
title={nEdialogTitle}
visible={visible}
condition={toJS(condition)}
form={form}
isFormInit={form.isFormInit}
loading={dialogLoading}
isEdit={isEdit}
2022-10-26 16:05:39 +08:00
height={400}
conditionLen={2}
2022-06-20 17:08:10 +08:00
save={() => this.handleSave()}
onCancel={() => resource.setVisible(false)}
/>
2022-06-27 18:48:28 +08:00
<DatasImport ecId={`${this && this.props && this.props.ecId || ''}_DatasImport@q4rrwm`} />
2023-01-05 18:02:33 +08:00
<SearchCustomDialog ecId={`${this && this.props && this.props.ecId || ''}_SearchCustomDialog@q4rrwm`}
2023-08-08 14:28:49 +08:00
store={store} />
2023-01-11 18:22:30 +08:00
<NewWeaTableEditDialog ecId={`${this && this.props && this.props.ecId || ''}_NewWeaTableEditDialog@q4rrwm`}
2023-08-08 14:28:49 +08:00
store={store} />
2022-06-20 17:08:10 +08:00
</div>
)
}
}