/* * Author: 黎永顺 * name:自定义导出-导出字段设置 * Description: * Date: 2024/3/28 */ import React, { Component } from "react"; import { WeaCheckbox, WeaDialog, WeaLocaleProvider, WeaSearchGroup } from "ecCom"; import { Button, Col, message, Row } from "antd"; import * as API from "../../../../../apis/calculate"; import TempDialog from "./tempDialog"; const getLabel = WeaLocaleProvider.getLabel; class Index extends Component { constructor(props) { super(props); this.state = { itemsCheckeds: [], itemsByGroup: [], tempDialog: { visible: false, salaryAcctRecordId: "", id: "", salaryItemIds: [] } }; } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && nextProps.visible) this.getExportField(nextProps); if (nextProps.visible !== this.props.visible && !nextProps.visible) this.setState({ itemsCheckeds: [], itemsByGroup: [] }); } getExportField = (props) => { const { salaryAcctRecordId, checkItems } = props; API.getExportField({ salaryAcctRecordId }).then(({ status, data }) => { if (status) { const { itemsByGroup } = data; this.setState({ itemsByGroup, itemsCheckeds: checkItems }); } }); }; handleSelectGroupAll = (groupId, checked) => { const { itemsCheckeds, itemsByGroup } = this.state; _.map(itemsByGroup, item => { if (item.salarySobItemGroupId === groupId) { if (!!Number(checked)) { this.setState({ itemsCheckeds: [...itemsCheckeds, ..._.map(item.salaryItems, child => String(child.salaryItemId))] }); } else { this.setState({ itemsCheckeds: _.differenceWith(itemsCheckeds, _.map(item.salaryItems, child => String(child.salaryItemId)), _.isEqual) }); } } }); }; save = () => { const { itemsCheckeds } = this.state; const { salaryAcctRecordId, tempId: id, templateName } = this.props; if (!id) { this.setState({ tempDialog: { visible: true, salaryAcctRecordId, id, salaryItemIds: itemsCheckeds } }); } else { API.saveExportTemplate({ templateName, salaryAcctRecordId, id, salaryItemIds: itemsCheckeds }) .then(({ status, errormsg }) => { this.setState({ loading: false }); if (status) { message.success(getLabel(111, "操作成功!")); this.props.onCancel(true); } else { message.error(errormsg); } }).catch(() => this.setState({ loading: false })); } }; render() { const { itemsCheckeds, itemsByGroup, tempDialog } = this.state; let dataSource = _.map(itemsByGroup, item => { return { ...item, salaryItems: _.map(item.salaryItems, child => { return { ...child, checked: itemsCheckeds.includes(String(child.salaryItemId)) }; }) }; }); return ( {getLabel(111, "保存")}]} > { _.map(dataSource, item => { const { salarySobItemGroupName, salaryItems, salarySobItemGroupId } = item; const value = _.every(salaryItems, it => !!it.checked) ? "1" : "0"; return this.handleSelectGroupAll(salarySobItemGroupId, val)} />}> { !_.isEmpty(salaryItems) ? _.map(salaryItems, it => { const { salaryItemId, salaryItemName, checked } = it; return this.setState({ itemsCheckeds: _.xorWith(itemsCheckeds, [String(salaryItemId)], _.isEqual) })} /> ; }) : {getLabel(83553, "暂无数据")} } ; }) } this.setState({ tempDialog: { ...tempDialog, visible: false } }, () => isRefresh && this.props.onCancel(true))}/> ); } } export default Index;