import React from 'react' import * as mobx from 'mobx' import { inject, observer } from 'mobx-react' import { WeaTop, WeaTab, WeaFormItem, WeaRightMenu, WeaAlertPage } 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'; // 从util文件引入公共的方法 const toJS = mobx.toJS; const confirm = Modal.confirm; const WeaTable = WeaTableNew.WeaTable; @inject('managerDetach') @observer export default class ManagerDetach extends React.Component { constructor(props) { super(props); } componentWillMount() { } componentDidMount() { this.init(); } componentWillUnmount() { } componentWillReceiveProps(nextProps) { const { managerDetach } = this.props; if (this.props.location.key !== nextProps.location.key) { this.init(); } } init() { const { managerDetach } = this.props; managerDetach.getHasRight(); managerDetach.getTableInfo(); } getTopMenuBtns() { const { managerDetach } = this.props; const { topMenu, tableStore } = managerDetach; let btns = []; topMenu.map((item, i) => { if (item.menuFun !== 'batchDelete') { btns.push(); } else { btns.push(); } }); return btns; } handleClick(item) { const { managerDetach } = this.props; const { isPanelShow } = managerDetach; isPanelShow && managerDetach.setPanelStatus(false); this[item.menuFun] && this[item.menuFun](); } new() { const { managerDetach } = this.props; managerDetach.setNeDialogTitle(i18n.label.newRankScheme()); managerDetach.setIsNew(true); managerDetach.setVisible(true); managerDetach.getForm(); } batchDelete() { const { managerDetach } = this.props; const { tableStore } = managerDetach; let keys = toJS(tableStore.selectedRowKeys).toString(); managerDetach.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 { managerDetach } = this.props; managerDetach.delete(); } getDropMenuDatas() { const { managerDetach } = this.props; const { rightMenu } = managerDetach; 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 { managerDetach } = this.props; const { isPanelShow } = managerDetach; isPanelShow && managerDetach.setPanelStatus(false); this[key] && this[key](); } getTabBtn() { const { managerDetach } = this.props; const { form2 } = managerDetach; const btn = [ (), (), (), ]; return btn; } custom = () => { const { managerDetach } = this.props, { tableStore, } = managerDetach; tableStore.setColSetVisible(true); tableStore.tableColSet(true); } onSearchChange(val) { const { managerDetach } = this.props; const { form2 } = managerDetach; managerDetach.setSchemeName(val); !this.isEmptyObject(form2.getFormParams()) && managerDetach.updateFields(val); } reRenderColumns(columns) { let _this = this; columns.forEach((c, index) => { if (c.dataIndex == 'forbidden_tag') { c.render = function (text, record) { return _this.updateForbiddenTag(checked, record.id)} /> } }; }) } updateForbiddenTag(checked, id) { const { managerDetach } = this.props; confirm({ title: i18n.confirm.defaultTitle(), content: (checked == true) ? i18n.confirm.enableTag() : i18n.confirm.forbiddenTag(), okText: i18n.button.ok(), cancelText: i18n.button.cancel(), onOk() { managerDetach.updateForbiddenTag(checked, id); }, onCancel() { return false; }, }); } onOperatesClick(record, rowIndex, operate) { const { index } = operate; (index == '0') && this.doEdit(record.randomFieldId); (index == '1') && this.doDel(record.randomFieldId); } doEdit(id) { const { managerDetach } = this.props; managerDetach.setNeDialogTitle(i18n.label.editRankScheme()); managerDetach.setSchemeId(id); managerDetach.setIsNew(false); managerDetach.setVisible(true); managerDetach.getForm(); } doDel(id) { const { managerDetach } = this.props; managerDetach.setIds(id); this.showConfirm('del'); } log = () => { window.setLogViewProp({ logMoudleType: 1, keys: new Date().getTime(), }); } handleSave() { const { managerDetach } = this.props; const { isNew } = managerDetach; isNew && managerDetach.save(); !isNew && managerDetach.edit(); } getPanelComponents() { const { managerDetach } = this.props; const { searchCondition, form2, searchConditionLoading } = managerDetach; 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") { managerDetach.getTableInfo(); managerDetach.setPanelStatus(false) } }}>{arr} } } isEmptyObject(obj) { for (let key in obj) { return false; } return true; } render() { const { managerDetach } = this.props; const { isPanelShow, form2, schemeName, conditionNum, tableStore, nEdialogTitle, visible, condition, form, dialogLoading, isEdit, date, hasRight } = managerDetach; 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)} > managerDetach.setPanelStatus(bool)} hideSearchAd={() => managerDetach.setPanelStatus(false)} searchsAd={isPanelShow ? this.getPanelComponents() :
} advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20} hasMask={false} buttonsAd={this.getTabBtn()} onSearch={() => managerDetach.getTableInfo()} onSearchChange={val => this.onSearchChange(val)} /> this.reRenderColumns(c)} onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)} />
this.handleSave()} onCancel={() => managerDetach.setVisible(false)} />
) } }