import React from 'react'
import * as mobx from 'mobx'
import {
inject,
observer
} from 'mobx-react'
import {
WeaTop,
WeaTab,
WeaFormItem,
WeaRightMenu,
WeaLeftRightLayout,
WeaOrgTree
} 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';
import { renderNoright } from '../../util';
const toJS = mobx.toJS;
const confirm = Modal.confirm;
const WeaTable = WeaTableNew.WeaTable;
@inject('staff')
@observer
export default class Staff extends React.Component {
constructor(props) {
super(props);
}
componentWillMount() {
}
componentDidMount() {
this.init();
}
componentWillReceiveProps(nextProps) {
const {
staff
} = this.props;
if (this.props.location.key !== nextProps.location.key) {
this.init();
}
}
init() {
const {
staff
} = this.props;
staff.getTableInfo();
staff.getHasRight();
}
getTopMenuBtns() {
const {
staff
} = this.props;
const {
topMenu,
tableStore
} = staff;
let btns = [];
topMenu.map((item, i) => {
if (item.menuFun !== 'batchDelete') {
btns.push();
} else {
btns.push();
}
});
return btns;
}
handleClick(item) {
const {
staff
} = this.props;
const {
isPanelShow
} = staff;
isPanelShow && staff.setPanelStatus(false);
this[item.menuFun] && this[item.menuFun]();
}
new() {
const {
staff
} = this.props;
staff.setNeDialogTitle(i18n.label.newStaff());
staff.setIsNew(true);
staff.setVisible(true);
staff.getForm();
}
log = () => {
window.setLogViewProp({
logMoudleType: 13,
keys: new Date().getTime(),
});
}
batchDelete() {
const {
staff
} = this.props;
const {
tableStore
} = staff;
let keys = toJS(tableStore.selectedRowKeys).toString();
staff.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 {
staff
} = this.props;
staff.delete();
}
getDropMenuDatas() {
const {
staff
} = this.props;
const {
rightMenu
} = staff;
let menus = [];
toJS(rightMenu).map((item, index) => {
let obj = {
key: item.menuFun,
icon: ,
content: item.menuName,
}
if (item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
obj.disabled = true;
}
menus.push(obj);
})
return menus;
}
handleMenuClick(key) {
const {
staff
} = this.props;
const {
isPanelShow
} = staff;
isPanelShow && staff.setPanelStatus(false);
this[key] && this[key]();
}
getTabBtn() {
const {
staff
} = this.props;
const {
form2
} = staff;
const btn = [
(),
(),
(),
];
return btn;
}
onSearchChange(val) {
const {
staff
} = this.props;
const {
form2
} = staff;
staff.setStaffName(val);
//!this.isEmptyObject(form2.getFormParams()) && staff.updateFields(val);
}
reRenderColumns(columns) {
let _this = this;
// columns.forEach((c, index) => {
// })
}
getTree = () => {
const {
staff
} = this.props;
const {
companysId,
} = staff
let tree = (
${i18n.label.organization()}`}
treeNodeClick={this.treeNodeClick}
expandAllChildrenOnSearch={true}
/>
)
return tree;
}
treeNodeClick = (event, ids, nodeids, nodes) => {
const {
staff
} = this.props;
const {
form2,
companysId
} = staff;
const type = event.node.props.type || '0';
const id = event.node.props.id || '';
let params = {};
form2.resetConditionValue();
if (type == '0') {
params['virtualtype'] = companysId;
}
if (type == '1') {
params['compId'] = id;
}
if (type == '2') {
params['deptId'] = id;
}
staff.doSearch(params);
}
replaceLeft() {
const {
staff
} = this.props;
const {
leftCondition,
form1,
} = staff;
let formParams = form1.getFormParams();
const {
isFormInit
} = form1;
let arr = [];
isFormInit && leftCondition.map(c => {
c.items.map((field, index) => {
arr.push(
{}
)
})
})
return arr;
}
onChange = data => {
const {
staff
} = this.props;
staff.setPlanId(data.planId.value)
};
onOperatesClick(record, rowIndex, operate) {
const {
index
} = operate;
(index == '0') && this.doEdit(record.randomFieldId);
(index == '1') && this.doDel(record.randomFieldId);
(index == '2') && this.doChange(record.randomFieldId);
}
doEdit(id) {
const {
staff
} = this.props;
staff.setNeDialogTitle(i18n.label.editStaff());
staff.setStaffId(id);
staff.setOperateType("1");
staff.setIsNew(false);
staff.setVisible(true);
staff.getForm();
}
doChange(id) {
const {
staff
} = this.props;
staff.setNeDialogTitle(i18n.label.changeStaff());
staff.setStaffId(id);
staff.setOperateType("2");
staff.setIsNew(false);
staff.setVisible(true);
staff.getForm();
}
custom = () => {
const {
staff
} = this.props, {
tableStore,
} = staff;
tableStore.setColSetVisible(true);
tableStore.tableColSet(true);
}
doDel(id) {
const {
staff
} = this.props;
staff.setIds(id);
this.showConfirm('del');
}
handleSave() {
const {
staff
} = this.props;
const {
isNew
} = staff;
isNew && staff.save();
!isNew && staff.edit();
}
getPanelComponents() {
const {
staff
} = this.props;
const {
searchCondition,
form2,
searchConditionLoading
} = staff;
let arr = [];
let formParams = form2.getFormParams();
const {
isFormInit
} = form2;
isFormInit && searchCondition.map(c => {
c.items.map((field, index) => {
arr.push(
{}
)
})
})
if (searchConditionLoading) {
return (
)
} else {
return {
if (e.keyCode == 13 && e.target.tagName === "INPUT") {
staff.getTableInfo();
staff.setPanelStatus(false)
}
}}>{arr}
}
}
//非空判断
isEmptyObject(obj) {
for (let key in obj) {
return false;
}
return true;
}
render() {
const {
staff
} = this.props;
const {
isPanelShow, form2, staffName, conditionNum, tableStore, nEdialogTitle, visible, condition,
form, dialogLoading, isEdit, date, hasRight
} = staff;
if (hasRight === false) {
return renderNoright();
}
return (
hasRight &&
this.handleMenuClick(key)}
>
}
iconBgcolor='#217346'
loading={true}
buttons={this.getTopMenuBtns()}
showDropIcon={true}
dropMenuDatas={this.getDropMenuDatas()}
onDropMenuClick={(e) => this.handleMenuClick(e)}
>
staff.setPanelStatus(bool)}
hideSearchAd={() => staff.setPanelStatus(false)}
searchsAd={isPanelShow ? this.getPanelComponents() : }
advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20}
hasMask={false}
buttonsAd={this.getTabBtn()}
onSearch={() => staff.getTableInfo()}
onSearchChange={val => this.onSearchChange(val)}
replaceLeft={this.replaceLeft()}
/>
this.reRenderColumns(c)}
onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}
/>
this.handleSave()}
onCancel={() => staff.setVisible(false)}
moduleName={"staff"}
bindChangeEnvent={val => staff.updateConditions(val)}
/>
)
}
}