/* * Author: 黎永顺 * name: 工资单模板-薪资项目设置 * Description: * Date: 2023/2/2 */ import React, { Component } from "react"; import { toJS } from "mobx"; import { WeaFormItem, WeaInput, WeaSortable, WeaTransfer } from "ecCom"; import { Icon, Modal } from "antd"; import SalaryItemModal from "./salaryItemModal"; import { getAvailableSalaryGroupSet, getAvailableSalaryItemSet } from "../../../apis/payroll"; class SalaryItemSettings extends Component { constructor(props) { super(props); this.state = { dataList: [], itemShowNamesetting: [], //名称修改集合 checkedValue: "", modalPayload: { visible: false, title: "", groupId: "", groupName: "", options: [], salaryItemName: "", salaryItemId: "" } }; } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.dataSource !== this.props.dataSource) { this.setState({ dataList: _.map(toJS(nextProps.dataSource), item => { return { ...item, id: item.groupId }; }) }); } } /* * Author: 黎永顺 * Description:删除薪资项目大类 * Params: * Date: 2023/2/2 */ handleDeleteClick = (group) => { Modal.confirm({ title: "信息确认", content: "确认删除", onOk: () => { let resultSalaryItemSet = [...this.state.dataList]; resultSalaryItemSet.map((sourceGroup, index) => { if (sourceGroup.groupId === group.groupId) { resultSalaryItemSet.splice(index, 1); } }); this.setState({ dataList: resultSalaryItemSet }, () => { this.props.onChangeSalaryItem(resultSalaryItemSet); }); } }); }; /* * Author: 黎永顺 * Description: 删除薪资项目项 * Params: * Date: 2023/2/2 */ handleDeleteSalaryItem = (group, item) => { let resultSalaryItemSet = [...this.state.dataList]; resultSalaryItemSet.map(sourceGroup => { if (sourceGroup.groupId === group.groupId) { sourceGroup.items.map((sourceItem, index) => { if (sourceItem.id === item.id) { sourceGroup.items.splice(index, 1); } }); } }); this.setState({ dataList: resultSalaryItemSet, itemShowNamesetting: _.filter(this.state.itemShowNamesetting, it => it.salaryItemId !== item.id) }, () => { this.props.onChangeSalaryItem(resultSalaryItemSet); this.props.onChangeSalaryItemShowNamesetting(this.state.itemShowNamesetting); }); }; handleCloseModal = () => { const { modalPayload } = this.state; this.setState({ checkedValue: "", modalPayload: { ...modalPayload, visible: false, title: "", groupId: "", groupName: "", options: [], salaryItemName: "", salaryItemId: "" } }); }; handleOpenModal = (record, title, isItem) => { if (title === "分类名称编辑") { const { modalPayload } = this.state; this.setState({ modalPayload: { ...modalPayload, visible: true, title, groupId: record.groupId, groupName: record.groupName } }); } else { isItem ? this.getAvailableSalaryItemSet(record, title) : this.getAvailableSalaryGroupSet(record, title); } }; getAvailableSalaryItemSet = (record, title) => { const payload = { salaryTemplateId: this.props.salaryTemplateId, salarySobId: this.props.salarySobId, existSalaryItemIds: _.map(record.items, it => it.id), groupId: record.groupId, isReplenish: this.props.isReplenish }; getAvailableSalaryItemSet(payload).then(({ status, data }) => { if (status) { const { modalPayload } = this.state; this.setState({ modalPayload: { ...modalPayload, visible: true, title, groupId: record.groupId, options: _.map(data, it => ({ ...it, name: it.name, id: it.salaryItemId })) } }); } }); }; getAvailableSalaryGroupSet = (salarySobId, title) => { const { dataList } = this.state; const payload = { salarySobId, salaryTemplateId: this.props.salaryTemplateId, existSalaryGroupIds: _.map(dataList, it => it.groupId), isReplenish: this.props.isReplenish }; getAvailableSalaryGroupSet(payload).then(({ status, data }) => { if (status) { const { modalPayload } = this.state; this.setState({ modalPayload: { ...modalPayload, visible: true, title, options: _.map(data, it => ({ ...it, name: it.groupName, id: it.groupId })) } }); } }); }; handleChangeClassName = (groupName) => { const { modalPayload } = this.state; this.setState({ modalPayload: { ...modalPayload, groupName } }); }; /* * Author: 黎永顺 * Description:添加薪资项目项 * Params: * Date: 2023/2/2 */ handleConfirm = () => { const { modalPayload, checkedValue, dataList } = this.state; const { options = [], groupId, groupName } = modalPayload; if (groupName) { this.setState({ dataList: _.map(dataList, it => { if (it.groupId === groupId) { return { ...it, groupName }; } return { ...it }; }) }, () => { this.props.onChangeSalaryItem(this.state.dataList); this.handleCloseModal(); }); } else { this.setState({ dataList: groupId ? _.map(dataList, it => { if (it.groupId === groupId) { return { ...it, items: [...it.items, ..._.filter(options, child => checkedValue.split(",").includes(child.salaryItemId))] }; } return { ...it }; }) : [...dataList, ..._.filter(options, child => checkedValue.split(",").includes(child.groupId))] }, () => { this.props.onChangeSalaryItem(this.state.dataList); this.handleCloseModal(); }); } }; handleEditSalaryItemName = (item, field, viewAttr) => { const { groupId } = item, { salaryItemId } = field, { dataList } = this.state; if (groupId === "111111111111111111") return; this.setState({ dataList: _.map(dataList, item => { if (item.groupId === groupId) { return { ...item, items: _.map(item.items, child => { if (child.salaryItemId === salaryItemId) { return { ...child, viewAttr }; } return { ...child, viewAttr: 1 }; }) }; } return { ...item, items: _.map(item.items, child => { return { ...child, viewAttr: 1 }; }) }; }) }, () => document.getElementById("salaryItemInput") && document.getElementById("salaryItemInput").focus()); }; handleChangeSalaryItemShowName = (item, field, name) => { const { groupId } = item, { salaryItemId, originName } = field, { dataList, itemShowNamesetting } = this.state; this.setState({ dataList: _.map(dataList, item => { if (item.groupId === groupId) { return { ...item, items: _.map(item.items, child => { if (child.salaryItemId === salaryItemId) { return { ...child, salaryItemShowName: name, name: name ? name : child.originName }; } return { ...child }; }) }; } return { ...item }; }), itemShowNamesetting: _.unionBy([{ salaryItemId, salaryItemShowName: originName === name ? "" : name }], itemShowNamesetting, "salaryItemId") }, () => { const modifySalaryItemids = _.reduce(this.state.itemShowNamesetting, (pre, cur) => [...pre, cur.salaryItemId], []); const convertDataList = _.map(this.state.dataList, it => { if (it.groupId === "111111111111111111") return { ...it }; return { ...it, items: _.map(it.items, item => { if (modifySalaryItemids.includes(item.salaryItemId)) return { ...item }; return { ...item, name: item.salaryItemShowName }; }) }; }); this.props.onChangeSalaryItem(convertDataList); this.props.onChangeSalaryItemShowNamesetting(this.state.itemShowNamesetting); }); }; render() { const { onChangeSalaryItem, salaryBillItemNameSet } = this.props; const { dataList, modalPayload, checkedValue } = this.state; return (