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, Menu, Dropdown, Icon, Tooltip } from 'antd' import { WeaSwitch, WeaTableNew } from 'comsMobx' import { i18n } from '../../public/i18n'; import '../../style/common.less'; import NewTableDialog from '../NewTableDialog'; import NewAndEditDialog from '../NewAndEditDialog'; import NewWeaTable from '../NewWeaTableDialog'; import { renderNoright } from '../../util'; import { CompanyExtendStore } from '../../stores/companyextend'; const companyExtend = new CompanyExtendStore(); const toJS = mobx.toJS; const confirm = Modal.confirm; @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(); company.getMoveForm(); } getTopMenuBtns() { const { company } = this.props; const { topMenu, selectedRowKeys } = company; let btns = []; topMenu.map((item, i) => { if (item.menuFun !== 'batchDelete') { btns.push(); } else { btns.push(); } }); return btns; } log = () => { window.setLogViewProp({ logMoudleType: 8, keys: new Date().getTime(), }); } 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.setNewVisible(true); company.getCompanyForm(); } //联查部门 select(id) { const { company } = this.props; company.setNeDialogTitle(i18n.label.selectDept()); company.setVisible(true); company.setDialogLoadingStatus(true); company.getDeptTable(id); } //查看 view(id) { //companyExtend.isEditor = true; window.open(`/spa/organization/static/index.html#/main/organization/companyExtend/${id}`, "_blank") } transfer(id) { const { company } = this.props; confirm({ width: '500px', title: i18n.confirm.defaultTitle(), content: this.getTransferForm(), okText: i18n.button.ok(), cancelText: i18n.button.cancel(), onOk() { company.transfer(id) }, onCancel() { return false; } }); } version(record) { const { company } = this.props; confirm({ title: i18n.confirm.defaultTitle(), content: `确认将{${record.subCompanyDesc}}存为新版本?`, okText: i18n.button.ok(), cancelText: i18n.button.cancel(), onOk() { company.version(record.id); }, onCancel() { return false; }, }); } getTransferForm() { const { company } = this.props; const { transferCondition, form2, } = company; let formParams = form2.getFormParams(); const { isFormInit } = form2; let arr = []; isFormInit && transferCondition.map(c => { c.items.map((field, index) => { arr.push( {} ) }) }) return arr; } batchDelete() { const { company } = this.props; const { selectedRowKeys } = company; let keys = toJS(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: , 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) { const { company } = this.props; let _this = this; // `${columns}` && columns.push({ // title: '', // dataIndex: 'ops', // key: 'ops', // width: 80, // className:"wea-table-operates", // render: ( text, record, index )=> { // const menu = ( // // // { _this.doDel(record.id) }}>删除 // // // { _this.select(record.id) }}>联查部门 // // // ) // return ( // // // // ) // } // }); columns.forEach((c, index) => { if (c.dataIndex == 'showOrder') { c.render = function (text, record) { return {record.showOrder.toFixed(2)} } } if (c.dataIndex == 'canceled') { c.render = function (text, record) { return _this.updateForbiddenTag(checked, record.id)} /> } }; if (c.dataIndex == 'subCompanyDesc') { c.className = "wea-table-indent" c.render = function (text, record) { return { window.open(`/spa/organization/static/index.html#/main/organization/companyExtend/${record.id}`, "_blank") }}>{text} } } if (c.dataIndex == 'operate') { c.className = "wea-table-operates" c.width = 80 c.render = function (text, record) { const menu = ( { _this.doDel(record.id) }}>{i18n.button.delete()} { _this.select(record.id) }}>{i18n.button.joinDept()} { _this.view(record.id) }}>{i18n.button.view()} { _this.transfer(record.id) }}>{i18n.button.transfer()} {/* { _this.version(record) }}>另存为版本 */} ) return } } }) return columns; } updateForbiddenTag(checked, id) { const { company } = 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() { company.updateForbiddenTag(checked, id); }, onCancel() { return false; }, }); } doDel(id) { const { company } = this.props; company.setIds(id); this.showConfirm('del'); } handleSave() { const { company } = this.props; company.setSaveAndSetting(false); company.save(); } handleSaveAndSetting() { const { company } = this.props; company.setSaveAndSetting(true); company.save(); } getTabBtn() { const { company } = this.props; const { form } = company; const btn = [ (), (), (), ]; 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(
{}
) }) }) if (searchConditionLoading) { return (
) } else { return { if (e.keyCode == 13 && e.target.tagName === "INPUT") { company.getTableInfo(); company.setPanelStatus(false) } }}>{arr} } } //非空判断 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, loading, date, nEdialogTitle, dialogLoading, form1, isEdit, newVisible, deptDataSource, deptColumns, selectedRowKeys, total, current, pageSize, init, hasRight } = company; if (hasRight === false) { return renderNoright(); } const rowSelection = { selectedRowKeys: selectedRowKeys, type: "checkbox", onChange(selectedRowKeys, selectedRows) { company.setSelectedRowKeys(selectedRowKeys); }, getCheckboxProps: record => ({ disabled: record.isUsed === 1, // 配置无法勾选的列 }), }; const pagination = { current: current, pageSize: pageSize, total: total, showSizeChanger: true, showQuickJumper: true, onShowSizeChange(current, pageSize) { }, onChange(current) { }, showTotal(total) { return `${i18n.label.total()} ${total} ${i18n.label.items()}` } }; return ( hasRight &&
this.handleMenuClick(key)} > } iconBgcolor='#217346' loading={true} buttons={this.getTopMenuBtns()} showDropIcon={true} dropMenuDatas={this.getDropMenuDatas()} onDropMenuClick={(e) => this.handleMenuClick(e)} > company.setPanelStatus(bool)} hideSearchAd={() => company.setPanelStatus(false)} searchsAd={isPanelShow ? this.getPanelComponents() :
} advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20} hasMask={false} buttonsAd={this.getTabBtn()} onSearch={() => { company.setCurrent(1); company.setPageSize(10); company.getTableInfo() }} onSearchChange={val => this.onSearchChange(val)} /> { init ?
: record.id} ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@pgmg3x`} loading={loading} dataSource={dataSource} childrenColumnName="children" columns={this.reRenderColumns(columns)} rowSelection={rowSelection} pagination={pagination} onChange={(pagination, filters, sorter) => { company.setSortParams(sorter); company.setCurrent(pagination.current); company.setPageSize(pagination.pageSize); company.getTableInfo(); }} indentSize={15} /> }
company.setVisible(false)} /> this.handleSave()} onCancel={() => company.setNewVisible(false)} saveAndSetting={() => this.handleSaveAndSetting()} />
) } }