salary-management-front/pc4mobx/hrmSalary/pages/salary/components/taxAgentSlide.js

343 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Author: 黎永顺
* name: 新增/编辑个税扣缴义务人
* Description:
* Date: 2022/11/29
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { Button, message, Modal } from "antd";
import { WeaLocaleProvider, WeaSlideModal, WeaSteps } from "ecCom";
import SlideModalTitle from "../../../components/slideModalTitle";
import { decentralizationConditions, editConditions } from "../../taxAgent/editConditions";
import BaseSettings, { convertConditon } from "./baseSettings";
import PersonalScope from "./personalScope";
import TaxDeclarationInfo from "./taxDeclarationInfo";
import TaxFilingInfoDialofg from "./taxFillingInfoDialog";
import * as API from "../../../apis/taxAgent";
import { registrationCheck } from "../../../apis/taxAgent";
import "./index.less";
const { getLabel } = WeaLocaleProvider;
const Step = WeaSteps.Step;
@inject("taxAgentStore")
@observer
class TaxAgentSlide extends Component {
constructor(props) {
super(props);
this.state = {
current: 0, loading: false, verifyLoading: false, taxAgentId: "",
taxFilingInfoDialofg: {
visible: false, title: "", checkPayload: {},
isEdit: false, jumpAll: false, loading: false,
taxAgentTaxReturnCheckFormDTO: null
}
};
this.taxInfoRef = null;
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible || nextProps.decentralization !== this.props.decentralization) {
const { taxAgentStore: { salarytaxAgentForm }, decentralization, isChief } = nextProps;
decentralization === "0" ?
salarytaxAgentForm.setCondition(convertConditon(decentralizationConditions, !isChief), true) :
salarytaxAgentForm.setCondition(convertConditon(editConditions, !isChief), true);
this.setState({ current: nextProps.current, taxAgentId: nextProps.taxAgentId }, () => {
if (this.state.taxAgentId) this.getTaxAgentForm();
});
}
}
getTaxAgentForm = () => {
const { taxAgentId } = this.state;
const { taxAgentStore: { salarytaxAgentForm } } = this.props;
API.getTaxAgentForm({ id: taxAgentId }).then(({ status, data }) => {
if (status) {
const { name, description, adminUserIds, sortedIndex } = data;
salarytaxAgentForm.updateFields({
name: { value: name },
adminUserIds: {
value: _.map(adminUserIds, it => it.id.toString()).join(","),
valueSpan: _.map(adminUserIds, it => it.content).join(",")
},
sortedIndex: { value: sortedIndex },
description: { value: description }
});
}
});
};
/*
* Author: 黎永顺
* Description: 保存个税扣缴义务人
* Params:
* Date: 2022/12/1
*/
saveTaxAgent = (payload) => {
const { onOk, salaryOn } = this.props;
const { current } = this.state;
this.setState({ loading: true });
API.saveTaxAgent(payload).then(({ status, data, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(22619, "保存成功"));
this.setState({
current: !salaryOn ? current + 2 : current + 1,
taxAgentId: data
}, () => onOk());
} else {
message.error(errormsg || getLabel(22620, "保存失败"));
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description: 编辑个税扣缴义务人
* Params:
* Date: 2022/12/1
*/
updateTaxAgent = (payload) => {
const { onCancel } = this.props;
this.setState({ loading: true });
API.updateTaxAgent(payload).then(({ status, data, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(31439, "更新成功"));
onCancel(true);
} else {
message.error(errormsg || getLabel(31825, "更新失败"));
}
}).catch(() => this.setState({ loading: false }));
};
handleSave = () => {
const { taxAgentStore: { salarytaxAgentForm } } = this.props;
const { taxAgentId } = this.state;
salarytaxAgentForm.validateForm().then((f) => {
if (f.isValid) {
const formData = salarytaxAgentForm.getFormParams();
const payload = {
...formData,
adminUserIds: formData.adminUserIds ? formData.adminUserIds.split(",") : []
};
taxAgentId ? this.updateTaxAgent({ ...payload, id: taxAgentId }) : this.saveTaxAgent(payload);
} else {
f.showErrors();
}
});
};
handleSaveAndVerify = (jumpAll = false) => {
const { isEdit } = this.props, { taxAgentId, taxFilingInfoDialofg } = this.state;
const { fieldForm, fieldItem } = this.taxInfoRef.state;
const { city: cityStr, cityVal = [], netPassword, realNamePassword, ...extra } = fieldForm;
const boolean = _.every(_.filter(fieldItem, item => item.viewAttr === 3), it => fieldForm[it.key]);
if (!boolean) {
Modal.warning({
title: getLabel(131329, "信息确认"),
content: getLabel(518702, "必要信息不完整,红色*为必填项!")
});
return;
}
const [nation, province, city] = cityStr ? cityStr.split("-") : [];
const proBool = _.every(cityStr ? cityStr.split("-") : [], it => it !== "undefined");
if (!proBool) {
Modal.warning({
title: getLabel(131329, "信息确认"),
content: getLabel(111, "请展开选择报税所属区域!")
});
return;
}
// requestType: 1:保存并验证 2保存
const payload = {
...extra, nation, province, city,
taxAgentId, requestType: 1, password: netPassword || realNamePassword,
cityname: !_.isEmpty(cityVal) ? _.head(cityVal).name : ""
};
this.setState({ verifyLoading: true });
API.saveAndCheck(_.omitBy(payload, val => _.isNil(val))).then(({ status, data, errormsg }) => {
this.setState({ verifyLoading: false });
if (status) {
message.success(getLabel(22619, "保存成功!"));
this.setState({
taxFilingInfoDialofg: {
...taxFilingInfoDialofg, visible: true,
isEdit, jumpAll, title: fieldForm.name, checkPayload: payload,
taxAgentTaxReturnCheckFormDTO: data.TaxAgentTaxReturnCheckFormDTO || data.table.list
}
});
} else {
message.error(errormsg || getLabel(22620, "保存失败!"));
}
}).catch(() => this.setState({ verifyLoading: false }));
};
renderChildren = () => {
const { current, taxAgentId } = this.state;
const { decentralization, isChief } = this.props;
let CurrentDom = null;
switch (current) {
case 0:
CurrentDom = <BaseSettings decentralization={decentralization} isChief={isChief}/>;
break;
case 1:
CurrentDom = <TaxDeclarationInfo ref={dom => this.taxInfoRef = dom} taxAgentId={taxAgentId} isChief={isChief}/>;
break;
case 2:
CurrentDom = <PersonalScope taxAgentId={taxAgentId}/>;
break;
default:
CurrentDom = null;
break;
}
return CurrentDom;
};
renderCustomOperate = () => {
const { isChief, isEdit, salaryOn } = this.props;
const { current, loading, verifyLoading } = this.state;
let CurrentDom = [];
//总管理员权限
if (isChief) {
switch (current) {
case 0:
CurrentDom = [
<Button type="primary" onClick={this.handleSave}
loading={loading}>{isEdit ? getLabel(537558, "保存") : getLabel(33199, "保存并进入下一步")}</Button>
];
break;
case 1:
const tmpV = [<Button type="primary" loading={verifyLoading}
onClick={() => this.handleSaveAndVerify(false)}>{getLabel(544343, "保存并验证")}</Button>];
const tmpJ = [
<Button type="ghost" loading={verifyLoading}
onClick={() => this.handleSaveAndVerify(true)}>{getLabel(543470, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current + 1 })}>{getLabel(1402, "下一步")}</Button>
];
CurrentDom = isEdit ? tmpV : [...tmpV, ...tmpJ];
break;
case 2:
CurrentDom = (!isEdit && salaryOn) ?
[<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(1876, "上一步")}</Button>]
: [];
break;
default:
break;
}
}
return CurrentDom;
};
handleChangeSlideTab = (current) => {
this.setState({ current: Number(current) });
};
handleSubmit = (selectKey) => {
const { taxFilingInfoDialofg, taxAgentId } = this.state;
const { fieldForm } = this.taxInfoRef.state;
const { city: cityStr, cityVal = [], netPassword, realNamePassword, ...extra } = fieldForm;
const [nation, province, city] = cityStr ? cityStr.split("-") : [];
const { taxAgentTaxReturnCheckFormDTO } = taxFilingInfoDialofg;
this.setState({
taxFilingInfoDialofg: { ...taxFilingInfoDialofg, loading: true }
});
registrationCheck({
...extra, nation, province, city,
taxAgentId, password: netPassword || realNamePassword,
cityname: !_.isEmpty(cityVal) ? _.head(cityVal).name : "",
..._.find(taxAgentTaxReturnCheckFormDTO, it => it.index === selectKey)
}).then(({ status, data, errormsg }) => {
this.setState({
taxFilingInfoDialofg: { ...taxFilingInfoDialofg, loading: false }
});
if (status) {
message.success(getLabel(22619, "保存成功!"));
this.setState({
taxFilingInfoDialofg: {
...taxFilingInfoDialofg,
taxAgentTaxReturnCheckFormDTO: data.TaxAgentTaxReturnCheckFormDTO
}
});
} else {
message.error(errormsg || getLabel(22620, "保存失败!"));
}
}).catch(() => {
this.setState({
taxFilingInfoDialofg: { ...taxFilingInfoDialofg, loading: false }
});
});
};
render() {
const tabs = [
{ key: 0, title: getLabel(82751, "基础设置") },
{ key: 1, title: getLabel(544342, "报税信息") },
{ key: 2, title: getLabel(124810, "人员范围") }
];
const { isEdit, title, visible, onCancel, salaryOn, taxAgentStore: { showOperateBtn } } = this.props;
const { current, taxAgentId, taxFilingInfoDialofg } = this.state;
const tabData = !salaryOn ? _.filter(tabs, it => it.key !== 1) : tabs;
return (
<WeaSlideModal
className="slideOuterWrapper"
visible={visible}
top={0}
width={65}
height={100}
direction="right"
measure="%"
title={
<SlideModalTitle
subtitle={title}
tabs={isEdit ? tabData : []}
loading={false}
showOperateBtn={showOperateBtn}
editable={false}
onSave={() => {
}}
selectedTab={current}
customOperate={this.renderCustomOperate()}
subItemChange={this.handleChangeSlideTab}
/>
}
content={
<div className="taxAgentSlideContent">
{
!isEdit &&
<WeaSteps current={current} style={{ margin: "20px 0" }}>
{
_.map(tabData, item => {
const { key, title } = item;
return <Step description={title} key={key}/>;
})
}
</WeaSteps>
}
{
this.renderChildren()
}
<TaxFilingInfoDialofg
{...taxFilingInfoDialofg}
onSubmit={this.handleSubmit}
onCancel={(isRefresh) => {
const { jumpAll } = taxFilingInfoDialofg;
this.setState({
current: jumpAll ? this.state.current + 1 : this.state.current,
taxFilingInfoDialofg: {
...taxFilingInfoDialofg, visible: false,
taxAgentTaxReturnCheckFormDTO: null
}
}, () => {
isRefresh && this.taxInfoRef.taxReturnGetForm();
jumpAll && this.props.onCancel(true);
});
}}
/>
</div>
}
onClose={() => onCancel()}
/>
);
}
}
export default TaxAgentSlide;