383 lines
11 KiB
JavaScript
383 lines
11 KiB
JavaScript
import React from 'react'
|
|
import * as mobx from 'mobx'
|
|
import {
|
|
inject,
|
|
observer,
|
|
} from 'mobx-react'
|
|
import {
|
|
WeaTop,
|
|
WeaTab,
|
|
WeaFormItem,
|
|
WeaRightMenu,
|
|
WeaTable
|
|
} from 'ecCom'
|
|
import {
|
|
Row,
|
|
Col,
|
|
Spin,
|
|
Modal,
|
|
Button,
|
|
message,
|
|
Switch
|
|
} from 'antd'
|
|
import {
|
|
WeaSwitch,
|
|
WeaTableNew
|
|
} from 'comsMobx'
|
|
import {
|
|
i18n
|
|
} from '../../public/i18n';
|
|
|
|
import '../../style/common.less';
|
|
|
|
import NewAndEditDialog from '../NewAndEditDialog';
|
|
|
|
|
|
|
|
const toJS = mobx.toJS;
|
|
const confirm = Modal.confirm;
|
|
//const WeaTable = WeaTableNew.WeaTable
|
|
|
|
|
|
@inject('company')
|
|
@observer
|
|
export default class Company extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
}
|
|
|
|
componentWillMount() {
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.init();
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
|
|
if (this.props.location.key !== nextProps.location.key) {
|
|
this.init();
|
|
}
|
|
}
|
|
|
|
init() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
company.getTableInfo();
|
|
company.getHasRight();
|
|
}
|
|
|
|
getTopMenuBtns() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
topMenu,
|
|
selectedRowKeys
|
|
} = company;
|
|
|
|
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={selectedRowKeys.length > 0 ? false : true} >{item.menuName}</Button>);
|
|
}
|
|
|
|
});
|
|
|
|
return btns;
|
|
}
|
|
|
|
handleClick(item) {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
isPanelShow
|
|
} = company;
|
|
|
|
isPanelShow && company.setPanelStatus(false);
|
|
this[item.menuFun] && this[item.menuFun]();
|
|
}
|
|
|
|
new() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
|
|
// company.setNeDialogTitle(i18n.label.newcompany());
|
|
// company.setIsNew(true);
|
|
// company.setVisible(true);
|
|
// company.getForm();
|
|
}
|
|
|
|
batchDelete() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
tableStore
|
|
} = company;
|
|
|
|
let keys = toJS(tableStore.selectedRowKeys).toString();
|
|
company.setIds(keys);
|
|
this.showConfirm('batchDel');
|
|
}
|
|
showConfirm(v) {
|
|
let _this = this;
|
|
confirm({
|
|
title: i18n.confirm.defaultTitle(),
|
|
content: (v == 'del') ? i18n.confirm.delete() : i18n.confirm.batchDeleteConfirm(),
|
|
okText: i18n.button.ok(),
|
|
cancelText: i18n.button.cancel(),
|
|
onOk() {
|
|
_this.onOk();
|
|
},
|
|
onCancel() {
|
|
return false;
|
|
},
|
|
});
|
|
}
|
|
onOk() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
company.delete();
|
|
}
|
|
|
|
|
|
getDropMenuDatas() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
rightMenu
|
|
} = company;
|
|
|
|
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 {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
isPanelShow
|
|
} = company;
|
|
|
|
isPanelShow && company.setPanelStatus(false);
|
|
this[key] && this[key]();
|
|
}
|
|
|
|
|
|
|
|
onSearchChange(val) {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
form
|
|
} = company;
|
|
|
|
company.setCompanyName(val);
|
|
!this.isEmptyObject(form.getFormParams()) && company.updateFields(val);
|
|
}
|
|
|
|
reRenderColumns(columns) {
|
|
let _this = this;
|
|
columns.forEach((c, index) => {
|
|
if (c.dataIndex == 'forbiddenTag') {
|
|
c.render = function (text, record) {
|
|
return <Switch defaultChecked={record.forbidden_tag == "0" ? true : false} onChange={checked => _this.updateForbiddenTag(checked, record.id)} />
|
|
}
|
|
};
|
|
if (c.dataIndex == 'compName') {
|
|
c.render = function (text, record) {
|
|
return <a href='/spa/organization/static/index.html#/main/organization/companyExtend' target='_blank'>{text}</a>
|
|
}
|
|
}
|
|
})
|
|
return columns;
|
|
}
|
|
|
|
updateForbiddenTag(checked, id) {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
company.updateForbiddenTag(checked, id);
|
|
}
|
|
|
|
doDel(id) {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
company.setIds(id);
|
|
this.showConfirm('del');
|
|
}
|
|
|
|
|
|
handleSave() {
|
|
// const {
|
|
// company
|
|
// } = this.props;
|
|
// const {
|
|
// isNew
|
|
// } = company;
|
|
|
|
// isNew && company.save();
|
|
// !isNew && company.edit();
|
|
}
|
|
|
|
getTabBtn() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
form
|
|
} = company;
|
|
|
|
const btn = [
|
|
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bx87i8`} type="primary" onClick={() => { company.getTableInfo(); company.setPanelStatus(false) }}>{i18n.button.search()}</Button>),
|
|
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@218ju6`} onClick={() => form.reset()}>{i18n.button.reset()}</Button>),
|
|
(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5u9mfz`} onClick={() => company.setPanelStatus(false)}>{i18n.button.cancel()}</Button>),
|
|
];
|
|
|
|
return btn;
|
|
}
|
|
|
|
getPanelComponents() {
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
searchCondition,
|
|
form,
|
|
searchConditionLoading
|
|
} = company;
|
|
|
|
let arr = [];
|
|
let formParams = form.getFormParams();
|
|
const {
|
|
isFormInit
|
|
} = form;
|
|
|
|
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={form} formParams={formParams} />}
|
|
</WeaFormItem>
|
|
</div>
|
|
</Col>)
|
|
})
|
|
})
|
|
|
|
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 {
|
|
return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@ppeb6z`} onKeyDown={(e) => {
|
|
if (e.keyCode == 13 && e.target.tagName === "INPUT") {
|
|
company.getTableInfo();
|
|
company.setPanelStatus(false)
|
|
}
|
|
}}>{arr}</Row>
|
|
}
|
|
|
|
}
|
|
|
|
//非空判断
|
|
isEmptyObject(obj) {
|
|
for (let key in obj) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
company
|
|
} = this.props;
|
|
const {
|
|
isPanelShow, companyName, conditionNum, visible, condition, form, tableStore, dataSource, columns
|
|
} = company;
|
|
|
|
|
|
const rowSelection = {
|
|
onChange(selectedRowKeys, selectedRows) {
|
|
company.setSelectedRowKeys(selectedRowKeys);
|
|
|
|
},
|
|
};
|
|
|
|
|
|
return (
|
|
<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`}
|
|
title={i18n.label.companyName()}
|
|
icon={<i className='icon-coms-hrm' />}
|
|
iconBgcolor='#217346'
|
|
loading={true}
|
|
buttons={this.getTopMenuBtns()}
|
|
showDropIcon={true}
|
|
dropMenuDatas={this.getDropMenuDatas()}
|
|
onDropMenuClick={(e) => this.handleMenuClick(e)}
|
|
>
|
|
<WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@9c3zts`}
|
|
searchType={['base', 'advanced']}
|
|
showSearchAd={isPanelShow}
|
|
searchsBaseValue={this.isEmptyObject(form.getFormParams()) ? companyName : form.getFormParams().companyName}
|
|
setShowSearchAd={bool => company.setPanelStatus(bool)}
|
|
hideSearchAd={() => company.setPanelStatus(false)}
|
|
searchsAd={isPanelShow ? this.getPanelComponents() : <div></div>}
|
|
advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20}
|
|
hasMask={false}
|
|
buttonsAd={this.getTabBtn()}
|
|
onSearch={() => company.getTableInfo()}
|
|
onSearchChange={val => this.onSearchChange(val)}
|
|
/>
|
|
<WeaTable rowKey={record => record.id}
|
|
dataSource={dataSource} childrenColumnName="children"
|
|
columns={this.reRenderColumns(columns)}
|
|
rowSelection={rowSelection}
|
|
indentSize={15}
|
|
defaultExpandedRowKeys={[1,2]}
|
|
/>
|
|
</WeaTop>
|
|
</WeaRightMenu>
|
|
|
|
</div>
|
|
)
|
|
}
|
|
} |