/* * Author: 黎永顺 * name: 薪资核算-列表数据 * Description: * Date: 2023/9/14 */ import React, { Component } from "react"; import { WeaLocaleProvider } from "ecCom"; import { message, Modal, Spin } from "antd"; import { inject, observer } from "mobx-react"; import { acctResultList, updateLockStatus } from "../../../../../apis/calculate"; import ProgressModal from "../../../../../components/progressModal"; const getLabel = WeaLocaleProvider.getLabel; @inject("calculateStore") @observer class EditCalcTable extends Component { constructor(props) { super(props); this.state = { loading: false, pageInfo: { current: 1, pageSize: 10, total: 0 }, selectedRowKeys: [], progressVisible: false, progress: 0 }; this.timerLock = null; } componentDidMount() { window.addEventListener("message", this.handleReceive, false); } handleReceive = async ({ data }) => { const { type, payload: { id, params } = {} } = data; if (type === "init") { this.queryCalcResultList(); } else if (type === "turn") { switch (id) { case "PAGEINFO": const { size: pageSize, pageNum: current } = params; this.setState({ pageInfo: { ...this.state.pageInfo, current, pageSize } }, () => this.queryCalcResultList()); break; case "CHECKBOX": const { selectedRowKeys } = params; this.setState({ selectedRowKeys }); break; case "FORMULA": const { dataIndex } = params; this.props.onShowFormulaTd(dataIndex); break; case "LOCKING": const { salaryItemId, lockType: lockStatus } = params; this.updateLockStatus({ lockStatus, salaryItemId }); break; default: break; } } }; updateLockStatus = (payload) => { const { lockStatus } = payload; Modal.confirm({ title: getLabel(131329, "信息确认"), content:
{lockStatus === "LOCK" ? getLabel(543554, "确定要批量锁定项目值吗?") : getLabel(543556, "确定要批量解锁项目值吗?")}
{lockStatus === "LOCK" ? getLabel(543555, "确定后,则项目输入值锁定,项目公式失效;点击核算将按锁定的输入值重新核算!") : getLabel(543557, "确定后,则项目公式生效,页面仍显示手动修改的项目值;点击核算将按公式重新核算,不再显示解锁标识!")}
, onOk: () => { this.setState({ progressVisible: true }, () => { this.timerLock = setInterval(() => { if (this.state.progress !== 100) { this.setState({ progress: this.state.progress + 1 }); } else { clearInterval(this.timerLock); this.setState({ progressVisible: false, progress: 0 }); } }, 500); }); const { routeParams: { salaryAcctRecordId } } = this.props; updateLockStatus({ ...payload, salaryAcctRecordId }).then(({ status, errormsg }) => { if (status) { clearInterval(this.timerLock); this.setState({ progressVisible: false, progress: 0 }, () => this.queryCalcResultList()); } else { message.error(errormsg); } }); } }); }; componentWillUnmount() { window.removeEventListener("message", this.handleReceive, false); } postMessageToChild = (payload = {}) => { const i18n = { "操作": getLabel(30585, "操作"), "编辑": getLabel(501169, "编辑"), "点击锁定所有解锁的项目值": getLabel(543649, "点击锁定所有解锁的项目值"), "点击解锁所有锁定的项目值": getLabel(543648, "点击解锁所有锁定的项目值"), "锁定的项目值": getLabel(543647, "锁定的项目值"), "当前状态锁定,点击解锁": getLabel(111, "当前状态锁定,点击解锁"), "当前状态未锁定,点击锁定": getLabel(111, "当前状态未锁定,点击锁定"), "共": getLabel(18609, "共"), "条": getLabel(18256, "条"), "总计": getLabel(523, "总计") }; const childFrameObj = document.getElementById("atdTable"); childFrameObj.contentWindow.postMessage(JSON.stringify({ ...payload, i18n }), "*"); }; queryCalcResultList = () => { const { pageInfo } = this.state; const { calculateStore: { ECSearchForm }, routeParams: { salaryAcctRecordId } } = this.props; const { subcompanyIds, departmentIds, positionIds, statuses, ...extra } = ECSearchForm.getFormParams(); const payload = { salaryAcctRecordId, ...pageInfo, ...extra, departmentIds: !_.isEmpty(departmentIds) ? departmentIds.split(",") : [], positionIds: !_.isEmpty(positionIds) ? positionIds.split(",") : [], subcompanyIds: !_.isEmpty(subcompanyIds) ? subcompanyIds.split(",") : [], statuses: !_.isEmpty(statuses) ? statuses.split(",") : [] }; this.setState({ loading: true }); acctResultList(payload).then(({ status, data }) => { this.setState({ loading: false }); if (status) { const { columns, pageInfo: list } = data; const { list: dataSource, pageNum: current, pageSize, total } = list; this.setState({ pageInfo: { ...pageInfo, current, pageSize, total } }, () => { const { pageInfo, selectedRowKeys } = this.state; const sumRowlistUrl = this.props.showTotalCell ? "/api/bs/hrmsalary/salaryacct/acctresult/sum" : ""; this.postMessageToChild({ dataSource, pageInfo, selectedRowKeys, showTotalCell: this.props.showTotalCell, sumRowlistUrl, payload, columns: _.map(traverse(columns), (it, idx) => ({ ...it, fixed: idx < 2 ? "left" : false })) }); }); } }).catch(() => this.setState({ loading: false })); }; render() { const { loading, progressVisible, progress } = this.state; return (