/* * Author: 黎永顺 * name: 规则配置 * Description: * Date: 2022-09-19 18:15:32 */ import React, { Component } from "react"; import { WeaCheckbox, WeaFormItem, WeaLocaleProvider, WeaNewScroll, WeaSearchGroup, WeaSelect, WeaTop } from "ecCom"; import { message, Modal } from "antd"; import * as API from "../../apis/ruleconfig"; import "./index.less"; import ProgressModal from "../../components/progressModal"; const { getLabel } = WeaLocaleProvider; export default class Index extends Component { constructor(props) { super(props); this.state = { items: [], matchRuleOptions: [], orderOptions: [], ascOptions: [], employeeOptions: [], saveParams: { orderRule: "", ascOrDesc: "", rule: "", enctry: "1", operateTaxDeclaration: "1", matchRule: "", confValue: "0", withDrawTaxDeclaration: "0", extEmpsWitch: "0" }, showEncryptOperationButton: "", progressVisible: false, progress: 50 }; } async componentDidMount() { const { saveParams } = this.state; const [ matchRuleEnum, orderRuleEnum, ascOrDescEnum, matchEmployeeModeEnum, // orderRules, codeRule, appSettings, sysInfo ] = await Promise.all([ this.matchRuleEnum(), this.orderRuleEnum(), this.ascOrDescEnum(), this.matchEmployeeModeEnum(), // this.sysOrderRule(), this.sysConfCodeRule(), this.queryAppsetting(), this.sysinfo() ]); const matchRuleOptions = _.map(matchRuleEnum.data, it => ({ key: it.value, showname: it.defaultLabel })); const orderOptions = _.map(orderRuleEnum.data, it => ({ key: it.value, showname: it.defaultLabel })); const ascOptions = _.map(ascOrDescEnum.data, it => ({ key: it.value, showname: it.defaultLabel })); const employeeOptions = _.map(matchEmployeeModeEnum.data, it => ({ key: it.value, showname: it.defaultLabel })); const { data: { ascOrDesc = "", orderRule = "", showEncryptOperationButton, matchEmployeeMode: rule = "", taxDeclarationFunction: operateTaxDeclaration = "1", salaryArchiveDelete: confValue, salaryAcctEmployeeRule: matchRule, WITHDRAW_TAX_DECLARATION: withDrawTaxDeclaration = "0", OPEN_APPLICATION_ENCRYPT: enctry = "1", extEmpsWitch = "0" } } = sysInfo; // const { data: { ascOrDesc, orderRule } } = orderRules; // const { data: rule } = codeRule; // const { // data: { // showEncryptOperationButton, // isOpenEncrypt: enctry // isOpenTaxDeclaration: operateTaxDeclaration, // salaryAcctEmployeeRule: matchRule, // salaryArchiveDelete: confValue, // withDrawTaxDeclaration // } // } = appSettings; this.setState({ matchRuleOptions, orderOptions, ascOptions, employeeOptions, showEncryptOperationButton, saveParams: { ...saveParams, ascOrDesc, orderRule, rule, enctry, matchRule, confValue, withDrawTaxDeclaration, extEmpsWitch, operateTaxDeclaration: (operateTaxDeclaration && operateTaxDeclaration !== "0") ? "1" : "0" } }); } sysinfo = () => { return API.sysinfo(); }; sysOrderRule = () => { return API.sysOrderRule(); }; sysConfCodeRule = () => { return API.sysConfCodeRule({ code: "matchEmployeeMode" }); }; queryAppsetting = () => { return API.queryAppsetting(); }; matchRuleEnum = () => { const payload = { enumClass: "com.engine.salary.sys.enums.SalaryAcctEmployeeRuleEnum" }; return API.commonEnumList(payload); }; orderRuleEnum = () => { const payload = { enumClass: "com.engine.salary.sys.enums.OrderRuleEnum" }; return API.commonEnumList(payload); }; ascOrDescEnum = () => { const payload = { enumClass: "com.engine.salary.sys.enums.AscOrDescEnum" }; return API.commonEnumList(payload); }; matchEmployeeModeEnum = () => { const payload = { enumClass: "com.engine.salary.sys.enums.MatchEmployeeModeEnum" }; return API.commonEnumList(payload); }; updateOrderRule = () => { API.updateOrderRule(_.pick(this.state.saveParams, ["orderRule", "ascOrDesc"])) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; saveMatchEmployeeModeRule = () => { API.saveMatchEmployeeModeRule(_.pick(this.state.saveParams, ["rule"])).then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; saveSalaryAcctEmployeeRule = () => { API.saveSalaryAcctEmployeeRule({ rule: this.state.saveParams.matchRule }) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; operateTaxDeclarationFunction = () => { API.operateTaxDeclarationFunction(_.pick(this.state.saveParams, ["operateTaxDeclaration"])) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; saveEncryptSetting = () => { API.saveEncryptSetting({ isOpenEncrypt: this.state.saveParams.enctry }) .then(({ data, status, errormsg }) => { if (status) { const { isSuccess, progressId, msg } = data; if (!isSuccess) { message.error(errormsg || msg || getLabel(22620, "保存失败!")); return; } this.setState({ progressVisible: true, progress: 0 }, () => { let number = 1; this.timer && clearInterval(this.timer); this.timer = setInterval(() => { API.getEncryptProgress({ progressId }).then(({ status, data, errormsg }) => { const { progress_statue } = data; if (progress_statue === "success" && this.timer) { clearInterval(this.timer); this.timer = null; number = 1; this.setState({ progress: 100 }, () => { this.setState({ progressVisible: false }); }); message.success(getLabel(22619, "保存成功!")); } else if (progress_statue === "in_progress" && this.timer) { if (this.state.progress >= 90) { this.setState({ progress: this.state.progress + (0.001 * this.state.progress) }); } else { this.setState({ progress: 10 * number }, () => number++); } } else if (!status || (progress_statue === "fail" && this.timer)) { clearInterval(this.timer); this.timer = null; number = 1; this.setState({ progress: 100 }, () => { this.setState({ progressVisible: false }); }); message.error(errormsg || getLabel(22620, "保存失败!")); } }); }, 1000); }); } }); }; saveArchiveDelete = () => { API.saveArchiveDelete(_.pick(this.state.saveParams, ["confValue"])) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; saveSysOperate = (payload) => { API.saveSysOperate({ ...payload, confValue: this.state.saveParams.extEmpsWitch }) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; withDrawTaxDeclaration = () => { API.saveWithDrawTaxDeclaration({ confValue: _.pick(this.state.saveParams, ["withDrawTaxDeclaration"]).withDrawTaxDeclaration }) .then(({ status, errormsg }) => { if (status) { message.success(getLabel(22619, "保存成功!")); } else { message.error(errormsg || getLabel(22620, "保存失败!")); } }); }; handleChange = (key, val) => { const { saveParams } = this.state; Modal.confirm({ title: getLabel(131329, "信息确认"), content: (key === "operateTaxDeclaration" && val === "0") ? getLabel(111, "关闭之后,将无法开启,确认要保存吗?") : getLabel(111, "确认要保存吗?"), onOk: () => { this.setState({ saveParams: { ...saveParams, [key]: val } }, () => { switch (key) { case "orderRule": case "ascOrDesc": this.updateOrderRule(); break; case "rule": this.saveMatchEmployeeModeRule(); break; case "matchRule": this.saveSalaryAcctEmployeeRule(); break; case "operateTaxDeclaration": this.operateTaxDeclarationFunction(); break; case "enctry": this.saveEncryptSetting(); break; case "confValue": this.saveArchiveDelete(); break; case "withDrawTaxDeclaration": this.withDrawTaxDeclaration(); break; case "extEmpsWitch": this.saveSysOperate({ title: getLabel(111, "开启非系统人员"), module: "basic", confKey: key }); break; default: break; } }); }, onCancel: () => { this.setState({ saveParams: { ...saveParams, [key]: saveParams[key] } }); } }); }; render() { const { saveParams, matchRuleOptions, orderOptions, ascOptions, employeeOptions, showEncryptOperationButton } = this.state; const { orderRule, ascOrDesc, rule, enctry, operateTaxDeclaration, matchRule, confValue, withDrawTaxDeclaration, extEmpsWitch } = saveParams; return (