salary-management-front/pc4mobx/hrmSalary/pages/roleManagement/components/addRoleDialog/index.js

89 lines
2.8 KiB
JavaScript

/*
* 角色新增
*
* @Author: 黎永顺
* @Date: 2024/8/5
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaDialog, WeaLocaleProvider } from "ecCom";
import { Button, message } from "antd";
import { getSearchs } from "../../../../util";
import { roleConditions } from "../conditions";
import * as API from "../../../../apis/taxAgent";
import "../index.less";
const getLabel = WeaLocaleProvider.getLabel;
@inject("taxAgentStore")
@observer
class Index extends Component {
constructor(props) {
super(props);
this.state = {
conditions: [], loading: false
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) {
this.setState({
conditions: _.map(roleConditions, item => ({
...item, items: _.map(item.items, o => ({ ...o, label: getLabel(o.lanId, o.label) }))
}))
}, () => nextProps.taxAgentStore.roleForm.initFormFields(this.state.conditions));
}
if (nextProps.visible !== this.props.visible && !nextProps.visible) nextProps.taxAgentStore.initRoleForm();
}
save = (isSetting) => {
const { taxAgentStore: { roleForm }, taxAgentId } = this.props;
roleForm.validateForm().then(f => {
if (f.isValid) {
const payload = roleForm.getFormParams();
console.log(payload,roleForm.getFormDatas())
return
this.setState({ loading: true });
API.saveAuthRole({ ...payload, taxAgentId }).then(({ status, data, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(111, "操作成功!"));
this.props.onCancel(() => this.props.onSearch());
isSetting && this.props.showRoleSetDialog({ id: data, name: payload.name });
} else {
message.error(errormsg);
}
});
} else {
f.showErrors();
}
});
};
handleFormChange=(val)=>{
console.log(val)
}
render() {
const { conditions, loading, roleSetDialog } = this.state;
const { taxAgentStore: { roleForm } } = this.props;
return (
<WeaDialog
{...this.props} style={{ width: 520 }} initLoadCss title={getLabel(111, "添加角色")}
buttons={[
<Button type="primary" loading={loading} onClick={() => this.save()}>{getLabel(111, "保存")}</Button>,
<Button type="primary" loading={loading}
onClick={() => this.save(true)}>{getLabel(111, "保存并进入详细设置")}</Button>
]}
>
<div className="form-dialog-layout">{getSearchs(roleForm, conditions, 1, false, this.handleFormChange)}</div>
</WeaDialog>
);
}
}
export default Index;