import React from "react"; import { inject, observer } from "mobx-react"; import { Button, Dropdown, Menu, Modal, Switch } from "antd"; import { WeaInputSearch, WeaSlideModal, WeaTable, WeaTop } from "ecCom"; import { renderNoright } from "../../util"; // 渲染form数据的方法:因为多个页面都会使用,所以抽的公共方法在util中 import CustomTab from "../../components/customTab"; import StepSlide from "../../components/stepSlide"; import SlideBaseForm from "./slideBaseForm"; import SlideRefereUser from "./slideRefereUser"; import SalaryItemForm from "./salaryItemForm"; import CalRulesForm from "./calcRulesForm"; import ValidRulesForm from "./validRulesForm"; import SlideModalTitle from "../../components/slideModalTitle"; import CopyFormModal from "./copyFormModal"; import "./index.less"; @inject("ledgerStore", "taxAgentStore") @observer export default class Ledger extends React.Component { constructor(props) { super(props); this.state = { value: "", selectedKey: "0", stepSlideVisible: false, editSlideVisible: false, copyFormVisible: false, currentStep: 0, selectedTab: 0, currentReocrd: {}, searchValue: "", step1Request: {} }; } handleSearch(value) { const { ledgerStore: { getTableDatas } } = this.props; getTableDatas({ name: value }); } componentWillMount() { const { ledgerStore: { doInit }, taxAgentStore: { getTaxAgentSelectListAsAdmin } } = this.props; doInit(); getTaxAgentSelectListAsAdmin(); } handleItemStatusChange(value, record) { const { ledgerStore: { changeLedgerStatus } } = this.props; changeLedgerStatus(record.id, value ? 0 : 1); } handleItemClick(record, selectedTab = 0) { const { ledgerStore: { setSalarySobId } } = this.props; setSalarySobId(record.id); this.setState({ selectedTab, editSlideVisible: true, request: record }); } // 编辑Slide保存按钮 handleEditSlideSave() { const { selectedTab, step1Request } = this.state; const { ledgerStore: { saveLedgerItem, saveAdjustmentRule, saveLedgerBasic, baseInfoRequest } } = this.props; if (selectedTab == 0) { saveLedgerBasic(baseInfoRequest); } else if (selectedTab == 2) { saveLedgerItem(); } else if (selectedTab == 3) { saveAdjustmentRule(); } } // 增加编辑功能,重写columns绑定事件 getColumns = columns => { let newColumns = ""; newColumns = columns.map(column => { let newColumn = column; newColumn.render = (text, record, index) => { //前端元素转义 let valueSpan = record[newColumn.dataIndex + "span"] !== undefined ? record[newColumn.dataIndex + "span"] : record[newColumn.dataIndex]; switch (newColumn.dataIndex) { case "name": return ( { this.handleItemClick(record); }}> {text} ); case "disable": return ( { this.handleItemStatusChange(value, record); }} /> ); case "operate": return ( { this.handleItemClick(record, 1); }}> 关联人员 ); default: return
; } }; return newColumn; }); return newColumns; }; onOperatesClick = (record, type) => { const { ledgerStore: { deleteLedger } } = this.props; switch (type.toString()) { case "0": // 编辑 this.handleItemClick(record); break; case "1": // 复制 this.setState({ copyFormVisible: true, currentReocrd: record }); break; case "3": // 关联人员 this.handleItemClick(record, 1); break; case "4": // 删除 Modal.confirm({ title: "信息确认", content: "确认删除", onOk: () => { deleteLedger([record.id]); }, onCancel: () => { } }); break; } }; handleCopySave = value => { const { ledgerStore: { doCopy } } = this.props; doCopy({ id: this.state.currentReocrd.id, ...value }).then(() => { this.setState({ copyFormVisible: false }); }); }; handleNew = () => { const { ledgerStore: { initSlideData } } = this.props; initSlideData(); this.setState({ stepSlideVisible: true, currentStep: 0 }); }; render() { const { ledgerStore, taxAgentStore } = this.props; const { loading, saveLoading, dataSource, columns, pageObj, setPageObj, hasRight, form, condition, tableStore, showSearchAd, getTableDatas, doSearch, setShowSearchAd, baseInfoRequest } = ledgerStore; const { showOperateBtn } = taxAgentStore; const { canEdit } = baseInfoRequest; const { currentStep, selectedTab } = this.state; if (!hasRight && !loading) { // 无权限处理 return renderNoright(); } const rightMenu = [ // 右键菜单 // { // key: "BTN_COLUMN", // icon: , // content: "显示列定制", // onClick: this.showColumn // } ]; const collectParams = { // 收藏功能配置 favname: "薪资账套", favouritetype: 1, objid: 0, link: "wui/index.html#/ns_demo03/index", importantlevel: 1 }; const adBtn = [ // 高级搜索内部按钮 , , ]; const topTab = []; const renderRightOperation = () => { return (
{showOperateBtn && } { this.setState({ searchValue: value }); }} placeholder={"请输入薪资账套名称"} onSearch={value => { this.handleSearch(value); }} />
); }; const nextStep = () => { const { currentStep } = this.state; this.setState({ currentStep: currentStep + 1 }); }; const prevStep = () => { const { currentStep } = this.state; this.setState({ currentStep: currentStep - 1 }); }; const steps = [ "基础设置", "关联人员", "薪资项目", "调薪计薪规则" // "校验规则" ]; const handleStep1Save = () => { const { step1Request } = this.state; const { ledgerStore: { saveLedgerBasic, baseInfoRequest } } = this.props; saveLedgerBasic(baseInfoRequest).then(() => { nextStep(); }); }; const handleStep3Save = () => { const { ledgerStore: { saveAdjustmentRule } } = this.props; saveAdjustmentRule().then(() => { nextStep(); }); }; const handleStepSave = () => { const { currentStep } = this.state; const { ledgerStore: { saveLedgerBasic, saveLedgerItem, saveAdjustmentRule, baseInfoRequest } } = this.props; if (currentStep == 0) { saveLedgerBasic(baseInfoRequest).then(() => { nextStep(); }); // } else if (currentStep == 1 || currentStep == 3) { } else if (currentStep == 1) { nextStep(); } else if (currentStep == 2) { saveLedgerItem().then(() => { nextStep(); }); // } else if (currentStep == 4) { } else if (currentStep == 3) { saveAdjustmentRule().then(() => { this.setState({ stepSlideVisible: false }); }); } }; const pagination = { total: pageObj.total, showTotal: total => `共 ${total} 条`, showSizeChanger: true, pageSizeOptions: ["10", "20", "50", "100"], onShowSizeChange: (current, pageSize) => { setPageObj({ ...pageObj, current, pageSize }); getTableDatas({ current, pageSize, name: this.state.searchValue }); }, onChange: current => { setPageObj({ ...pageObj, current, pageSize: pageObj.pageSize }); getTableDatas({ current, pageSize: pageObj.pageSize, name: this.state.searchValue }); } }; const newColumns = _.map([...columns], item => { if (item.dataIndex === "name") { return { ...item, render: (text, record) =>
{ this.handleItemClick(record); }}> {text}
}; } else if (item.dataIndex === "disable") { return { ...item, render: (text, record) => { this.handleItemStatusChange(value, record); }} /> }; } else if (item.dataIndex === "operate" && showOperateBtn) { return { ...item, render: (text, record) =>
{ this.handleItemClick(record, 1); }}> 关联人员 this.onOperatesClick(record, item.key)}> 编辑 复制 {/*关联人员*/} 删除 }>
}; } else { return { ...item }; } }); return (
} // 左侧图标 iconBgcolor="#F14A2D" // 左侧图标背景色 showDropIcon={false} // 是否显示下拉按钮 dropMenuDatas={rightMenu} // 下拉菜单(和页面的右键菜单相同) dropMenuProps={{ collectParams }}> { }} /> it.dataIndex !== "operate") } dataSource={dataSource} pagination={pagination} loading={loading} scroll={{ x: 1300 }} /> {this.state.stepSlideVisible && { this.setState({ stepSlideVisible: false }); }} customOperate={ currentStep == 0 ? [ ] : currentStep == 1 ? [ , ] : currentStep == 2 ? [ , , ] : currentStep == 3 ? [ , ] : [] } title="新建账套" content={
{currentStep == 0 && } {currentStep == 1 && } {currentStep == 2 && } {currentStep == 3 && } {currentStep == 4 && }
} />} {this.state.editSlideVisible && this.handleEditSlideSave()} subItemChange={selectedTab => { this.setState({ selectedTab }); }} /> } content={
{selectedTab == 0 && } {selectedTab == 1 && } {selectedTab == 2 && } {selectedTab == 3 && } {selectedTab == 4 && }
} onClose={() => this.setState({ editSlideVisible: false }, () => { this.setState({ selectedTab: 0 }); })} showMask={true} closeMaskOnClick={() => this.setState({ editSlideVisible: false }, () => { this.setState({ selectedTab: 0 }); })} />}
{this.state.copyFormVisible && this.handleCopySave(value)} onCancel={() => { this.setState({ copyFormVisible: false }); }} />}
); } }