import React, { Component } from "react"; import { toJS } from "mobx"; import { inject, observer } from "mobx-react"; import { i18n } from "../../public/i18n"; import LeftTree from "./components/leftTree"; import NewAndEditDialog from "../NewAndEditDialog"; import { WeaTop, WeaTab, WeaFormItem, WeaRightMenu, WeaLeftRightLayout, } from "ecCom"; import { Row, Col, Spin, Modal, Button, message, Switch } from "antd"; import { WeaSwitch, WeaTableNew } from "comsMobx"; import "./index.less"; const confirm = Modal.confirm; const WeaTable = WeaTableNew.WeaTable; @inject("officeManageStore") @observer export default class OfficeManage extends Component { constructor(props) { super(props); this.state = { date: "", editId: "", loading: false, }; } componentDidMount() { const { officeManageStore } = this.props; officeManageStore.getTreeData && officeManageStore.getTreeData(); officeManageStore.getHasRight && officeManageStore.getHasRight(); officeManageStore.getPostInfoTable && officeManageStore.getPostInfoTable(); } getDropMenuDatas = () => { const { officeManageStore } = this.props; const { rightMenu } = officeManageStore; 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 { officeManageStore } = this.props; const { isPanelShow,tableStore} = officeManageStore; isPanelShow && officeManageStore.setPanelStatus(false); switch (key) { case "new": officeManageStore.getPostInfoForm(); officeManageStore.setVisible(true); officeManageStore.setNeDialogTitle(i18n.label.newOfficeName()); break; case "custom": tableStore.setColSetVisible(true); tableStore.tableColSet(true); break; default: break; } }; handleSave() { const { form, condition, savePostInfo, updatePostInfo } = this.props.officeManageStore; const { editId } = this.state; form.validateForm().then((f) => { if (f.isValid) { // 验证通过, balabala业务代码 const payload = editId ? { ...form.getFormParams(), id: editId } : { ...form.getFormParams() }; this.setState({ loading: true }); if (editId) { updatePostInfo(payload).then(({ code, msg }) => { this.setState({ loading: false }); if (code === 200) { message.success("编辑成功"); this.props.officeManageStore.setVisible(false); this.props.officeManageStore.getPostInfoTable(); this.setState({ editId: "" }); } else { message.error(msg || "编辑失败"); } }); return; } savePostInfo(payload).then(({ code, msg }) => { this.setState({ loading: false }); if (code === 200) { message.success("新增成功"); this.props.officeManageStore.setVisible(false); this.props.officeManageStore.getPostInfoTable(); this.setState({ editId: "" }); } else { message.error(msg || "新增失败"); } }); } else { f.showErrors(); this.setState({ date: new Date() }); // 改变一个state的变量,强制页面刷新 } }); } getTopMenuBtns = () => { const { officeManageStore } = this.props; const { topMenu, tableStore } = officeManageStore; let btns = []; topMenu.map((item, i) => { if (item.menuFun !== "batchDelete") { btns.push( ); } else { btns.push( ); } }); return btns; }; showConfirm = (v, ids) => { confirm({ title: i18n.confirm.defaultTitle(), content: v == "del" ? i18n.confirm.delete() : i18n.confirm.batchDeleteConfirm(), okText: i18n.button.ok(), cancelText: i18n.button.cancel(), onOk: () => this.deletePostinfoByIds(ids), onCancel() { return false; }, }); }; deletePostinfoByIds = (ids) => { const { officeManageStore } = this.props; const { deletePostinfoByIds } = officeManageStore; deletePostinfoByIds({ ids }).then(({ code, msg }) => { if (code === 200) { message.success("删除成功"); officeManageStore.getPostInfoTable(); } else { message.error(msg || "删除失败"); } }); }; reRenderColumns = (columns) => { let _this = this; columns.forEach((c, index) => { if (c.dataIndex == "forbidden_tag") { c.render = function (text, record) { return ( { confirm({ title: i18n.confirm.defaultTitle(), content: record.forbidden_tag === "0" ? "确定要禁用吗?" : "确定要启用吗?", okText: i18n.button.ok(), cancelText: i18n.button.cancel(), onOk: () => _this.updateForbiddenTag(checked, record.id), onCancel() { return false; }, }); }} /> ); }; } }); }; updateForbiddenTag = (forbiddentag, id) => { const { officeManageStore } = this.props; const { updateForbiddenTagById } = officeManageStore; const payload = { id, forbiddentag, }; updateForbiddenTagById(payload).then(({ code, msg }) => { if (code === 200) { message.success("操作成功"); officeManageStore.getPostInfoTable(); } else { message.error(msg || "操作失败"); } }); }; onOperatesClick = (record, index, operate) => { operate.index == "0" && this.doEdit(record.randomFieldId); operate.index === "1" && this.showConfirm("del", record.randomFieldId); }; doEdit = (editId) => { this.setState({ editId }); const { officeManageStore } = this.props; officeManageStore.isPanelShow && officeManageStore.setPanelStatus(false); officeManageStore.getPostInfoForm(editId); officeManageStore.setVisible(true); officeManageStore.setNeDialogTitle(i18n.label.editOfficeName()); }; custom = () => { debugger const { officeManageStore } = this.props, { tableStore, } = officeManageStore; } getPanelComponents = () => { const { officeManageStore } = this.props; const { searchCondition, form2, searchConditionLoading } = officeManageStore; 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") { officeManageStore.getPostInfoTable(); officeManageStore.setPanelStatus(false); } }}> {arr} ); } }; getTabBtn = () => { const { officeManageStore } = this.props; const { form2 } = officeManageStore; const btn = [ , , , ]; return btn; }; onSearchChange = (val) => { const { officeManageStore } = this.props; const { form2 } = officeManageStore; officeManageStore.setPostInfoName(val); !_.isEmpty(form2.getFormParams()) && officeManageStore.updateFields(val); }; render() { const { officeManageStore } = this.props; const { date, loading } = this.state; const { isPanelShow, form2, postInfoName, conditionNum, tableStore, nEdialogTitle, visible, condition, form, dialogLoading, } = officeManageStore; return (
} onCollapse={(showLeft) => console.log("showLeft:", showLeft)}> this.handleMenuClick(key)}> } iconBgcolor="#217346" loading={true} buttons={this.getTopMenuBtns()} showDropIcon={true} dropMenuDatas={this.getDropMenuDatas()} onDropMenuClick={(e) => this.handleMenuClick(e)}> officeManageStore.setPanelStatus(bool) } hideSearchAd={() => officeManageStore.setPanelStatus(false)} searchsAd={ isPanelShow ? this.getPanelComponents() :
} advanceHeight={Math.ceil(conditionNum / 2) * 52 + 20} hasMask={false} buttonsAd={this.getTabBtn()} onSearch={() => officeManageStore.getPostInfoTable()} onSearchChange={(val) => this.onSearchChange(val)} /> { console.log(record); return { disabled: true, // 配置无法勾选的列 }; }, }} getColumns={(c) => this.reRenderColumns(c)} onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate) } />
this.handleSave()} onCancel={() => { officeManageStore.setVisible(false); this.setState({ editId: "" }); }} />
); } }