/* * 角色详情设置弹窗 * * @Author: 黎永顺 * @Date: 2024/8/5 * @Wechat: * @Email: 971387674@qq.com * @description: */ import React, { Component } from "react"; import { inject, observer } from "mobx-react"; import { WeaBrowser, WeaDialog, WeaFormItem, WeaInputNumber, WeaLocaleProvider, WeaScope, WeaSelect, WeaTab, WeaTable, WeaTextarea, WeaTools } from "ecCom"; import { commonEnumList } from "../../../../apis/archive"; import EditRoleDialog from "./editRoleDialog"; import DetailDialog from "./detailDialog"; import AuthTree from "./authTree"; import * as API from "../../../../apis/taxAgent"; import { Button, Col, message, Modal, Row } from "antd"; import "../index.less"; import CustomBrowser from "../../../../components/CustomBrowser"; import { roleConditions } from "../conditions"; import { getSearchs } from "../../../../util"; const getLabel = WeaLocaleProvider.getLabel; const getKey = WeaTools.getKey; const APIFOX = { "auth.MemberTargetTypeEnum": API.authMemberList, "save.auth.MemberTargetTypeEnum": API.saveAuthMember, "delete.auth.MemberTargetTypeEnum": API.deleteAuthMember, "sync.auth.MemberTargetTypeEnum": API.syncAuthMember, "auth.DataTargetTypeEnum": API.authDataList, "save.auth.DataTargetTypeEnum": API.saveAuthData, "delete.auth.DataTargetTypeEnum": API.deleteAuthData, "sync.auth.DataTargetTypeEnum": API.syncAuthData }; @inject("taxAgentStore") @observer class Index extends Component { constructor(props) { super(props); this.state = { selectedKey: "baseinfo", name: "", options: [], enumType: "", selectedRowKeys: [], replaceDatas: [], loading: { set: false, query: false, async: false, delete: false }, columns: [], dataSource: [], pageInfo: { current: 1, pageSize: 10, total: 0 }, editOperatorDialog: { visible: false, linkOptions: [], record: {} }, detailDialog: { visible: false, roleId: "", selectedKey: "" }, dataTargetSettings: { link: "OR", sortedIndex: null }, conditions: [], formData: { taxAgentIds: [], sobIds: [] } }; } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && nextProps.visible) { this.setState({ name: nextProps.name, selectedKey: nextProps.selectedKey || "baseinfo", detailDialog: { ...this.state.detailDialog, roleId: nextProps.roleId, selectedKey: nextProps.selectedKey || "baseinfo" } }, () => { !["auth.AuthTargetTypeEnum", "baseinfo"].includes(this.state.selectedKey) && this.getEnumList(); !["auth.AuthTargetTypeEnum", "baseinfo"].includes(this.state.selectedKey) && this.getSettingRoler(nextProps.roleId); this.state.selectedKey === "baseinfo" && this.getRole(nextProps.roleId); this.state.selectedKey === "auth.DataTargetTypeEnum" && this.getConnectSymbol(); }); } else { this.setState({ selectedRowKeys: [], replaceDatas: [], pageInfo: { current: 1, pageSize: 10, total: 0 }, dataTargetSettings: { link: "OR", sortedIndex: "" } }); } } getRole = (id) => { API.getRole({ id }).then(({ status, data }) => { if (status) { this.setState({ conditions: _.map(roleConditions, item => ({ ...item, items: _.map(item.items, o => { if (getKey(o) === "taxAgentIds" || getKey(o) === "sobIds") { return { ...o, label: getLabel(o.lanId, o.label), value: _.map(data[getKey(o)], i => String(i.id)).join(","), browserConditionParam: { ...o.browserConditionParam, replaceDatas: _.map(data[getKey(o)], i => ({ id: String(i.id), name: i.name })) } }; } return { ...o, label: getLabel(o.lanId, o.label) }; }) })), formData: { taxAgentIds: _.map(data["taxAgentIds"], i => ({ id: String(i.id), name: i.name })), sobIds: _.map(data["sobIds"], i => ({ id: String(i.id), name: i.name })) } }, () => { this.props.taxAgentStore.roleForm.initFormFields(this.state.conditions); this.props.taxAgentStore.roleForm.updateFields({ name: { value: data.name }, description: { value: data.description } }); }); } }); }; getEnumList = () => { const payload = { enumClass: `com.engine.salary.enums.${this.state.selectedKey}` }; commonEnumList(payload).then(({ status, data }) => { if (status) this.setState({ options: _.map(data, o => ({ key: o.enum, showname: o.defaultLabel })), enumType: _.head(data).enum || "" }); if (!status) this.setState({ options: [], enumType: "" }); }); }; getSettingRoler = (roleId) => { const { selectedKey, pageInfo } = this.state; this.setState({ loading: { ...this.state.loading, query: true } }); APIFOX[selectedKey]({ roleId, ...pageInfo }).then(({ status, data }) => { this.setState({ loading: { ...this.state.loading, query: false } }); if (status) { const { columns, list: dataSource, pageNum: current, pageSize, total } = data; this.setState({ dataSource, pageInfo: { ...pageInfo, current, pageSize, total }, columns: [ ...columns, { dataIndex: "opt", title: getLabel(111, "操作"), width: 120, render: (__, record) => ( this.handleEditOperator(record)}>{getLabel(111, "编辑")}) } ] }); } }); }; handleEditOperator = (record) => { this.setState({ editOperatorDialog: { ...this.state.editOperatorDialog, visible: true, record } }); }; getConnectSymbol = async () => { const payload = { enumClass: `com.engine.salary.enums.auth.DataLinkEnum` }; const { data } = await commonEnumList(payload); const linkOptions = _.map(data, o => ({ key: o.enum, showname: o.defaultLabel })); this.setState({ editOperatorDialog: { ...this.state.editOperatorDialog, linkOptions } }); }; addOperatorSettings = () => { const { roleId } = this.props; const { selectedKey, enumType: targetType, replaceDatas, dataTargetSettings } = this.state; if (_.isEmpty(replaceDatas)) { Modal.warning({ title: getLabel(111, "系统提示"), content: getLabel(111, "请先选择操作对象的值!") }); return; } const payload = _.map(replaceDatas, o => ({ roleId, target: o.id || "", id: o.editId || "", targetType: o.targetType || targetType, targetName: o.name || "", link: o.link || dataTargetSettings.link, sortedIndex: o.sortedIndex || dataTargetSettings.sortedIndex })); this.setState({ loading: { ...this.state.loading, set: true } }); APIFOX[`save.${selectedKey}`](payload).then(({ status, errormsg }) => { this.setState({ loading: { ...this.state.loading, set: false } }); if (status) { message.success(getLabel(111, "操作成功!")); this.setState({ replaceDatas: [] }, () => this.getSettingRoler(roleId)); } else { message.error(errormsg); } }); }; deleteOperatorSettings = () => { const { roleId } = this.props; const { selectedKey, selectedRowKeys } = this.state; if (_.isEmpty(selectedRowKeys)) { Modal.warning({ title: getLabel(111, "信息确认"), content: getLabel(111, "确定要删除所选批次吗?") }); return; } this.setState({ loading: { ...this.state.loading, delete: true } }); APIFOX[`delete.${selectedKey}`](selectedRowKeys).then(({ status, errormsg }) => { this.setState({ loading: { ...this.state.loading, delete: false } }); if (status) { message.success(getLabel(111, "操作成功!")); this.setState({ selectedRowKeys: [] }, () => this.getSettingRoler(roleId)); } else { message.error(errormsg); } }); }; saveAuthOpt = () => { const { roleId } = this.props, { selectedKey } = this.state; if (selectedKey === "baseinfo") { this.saveBaseInfo(); return; } const { state: { checkedKeys } } = this.authTreeRef; const payload = { roleId, opts: _.reduce(checkedKeys, (pre, cur) => { if (cur.indexOf("query") !== -1 || cur.indexOf("admin") !== -1) { const [page, opt] = cur.split("-"); return [...pre, { page, opt }]; } return pre; }, []) }; this.setState({ loading: { ...this.state.loading, set: true } }); API.saveAuthOpt(payload).then(({ status, errormsg }) => { this.setState({ loading: { ...this.state.loading, set: false } }); if (status) { message.success(getLabel(111, "操作成功!")); this.props.onSearch && this.props.onSearch(); } else { message.error(errormsg); } }); }; saveBaseInfo = () => { const { taxAgentStore: { roleForm }, roleId } = this.props; const { formData } = this.state; roleForm.validateForm().then(f => { if (f.isValid) { const payload = roleForm.getFormParams(); this.setState({ loading: { ...this.state.loading, set: true } }); API.saveAuthRole({ id: roleId, ...payload, ...formData }).then(({ status, errormsg }) => { this.setState({ loading: { ...this.state.loading, set: false } }); if (status) { message.success(getLabel(111, "操作成功!")); this.props.onSearch && this.props.onSearch(); } else { message.error(errormsg); } }); } else { f.showErrors(); } }); }; syncAuthData = () => { const { roleId } = this.props, { selectedKey } = this.state; this.setState({ async: true }); APIFOX[`sync.${selectedKey}`]({ roleId }).then(({ status, errormsg }) => { this.setState({ async: false }); if (status) { message.success(getLabel(111, "操作成功!")); this.props.onSearch && this.props.onSearch(); } else { message.error(errormsg); } }); }; getOperatorSetting = () => { const { roleId, taxAgentStore: { roleForm } } = this.props; const { selectedKey, enumType, replaceDatas, conditions } = this.state; if (!["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey)) { let browserType = {}; switch (enumType) { case "EMP": browserType = { ...browserType, type: 17, title: getLabel(82246, "人员选择") }; break; case "DEPARTMENT": browserType = { ...browserType, type: 57, title: getLabel(111, "部门选择") }; break; case "JOB": browserType = { ...browserType, type: 278, title: getLabel(111, "岗位选择") }; break; case "SUB_COMPANY": browserType = { ...browserType, type: 164, title: getLabel(111, "分部选择") }; break; case "ROLE": browserType = { ...browserType, type: 65, title: getLabel(111, "角色选择") }; break; case "SQL": return ( this.setState({ replaceDatas: [{ id: v, name: v }] })}/> ); case "LEVEL": return ( cur.id.split("-"), [])} onChange={v => this.setState({ replaceDatas: [{ id: v.join("-"), name: v.join("-") }] })}/> ); case "SOB": return ( (o.id))} onCustomChange={replaceDatas => this.setState({ replaceDatas: _.map(_.values(replaceDatas), o => ({ id: o.id, name: o.name })) })} /> ); case "TAX": return ( (o.id))} onCustomChange={replaceDatas => this.setState({ replaceDatas: _.map(_.values(replaceDatas), o => ({ id: o.id, name: o.name })) })} /> ); default: return (); } return ( this.setState({ replaceDatas })}/> ); } else if (selectedKey === "auth.AuthTargetTypeEnum") { return ( this.authTreeRef = dom}/>); } return getSearchs(roleForm, conditions, 1, false, this.handleFormChange); }; handleFormChange = (val) => { const key = _.keys(val)[0]; if (key === "taxAgentIds" || key === "sobIds") { this.setState({ formData: { ...this.state.formData, ...val } }); } }; render() { const { roleId, taxAgentStore, counts } = this.props; const { selectedKey, name, options, enumType, pageInfo, columns, dataSource, loading, selectedRowKeys, editOperatorDialog, dataTargetSettings, detailDialog } = this.state; const { linkOptions } = editOperatorDialog; const tabs = [ { title: getLabel(111, "基础信息"), viewcondition: "baseinfo", showcount: true, count: "resources" }, { title: getLabel(111, "成员设置"), viewcondition: "auth.MemberTargetTypeEnum", showcount: true, count: "members" }, { title: getLabel(111, "功能权限"), viewcondition: "auth.AuthTargetTypeEnum", showcount: true, count: "opts" }, { title: getLabel(111, "数据范围"), viewcondition: "auth.DataTargetTypeEnum", showcount: true, count: "datas" } ]; const pagination = { ...pageInfo, showTotal: total => `${getLabel(18609, "共")} ${total} ${getLabel(18256, "条")}`, showQuickJumper: true, showSizeChanger: true, pageSizeOptions: ["10", "20", "50", "100"], onShowSizeChange: (current, pageSize) => { this.setState({ pageInfo: { ...pageInfo, current, pageSize } }, () => this.getSettingRoler(roleId)); }, onChange: current => { this.setState({ pageInfo: { ...pageInfo, current } }, () => this.getSettingRoler(roleId)); } }; const rowSelection = { selectedRowKeys, onChange: (selectedRowKeys) => this.setState({ selectedRowKeys }) }; const buttons = [ , ]; ["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && buttons.shift(); !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && buttons.pop(); !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && buttons.unshift( ); return (
this.setState({ selectedKey: v, replaceDatas: [], selectedRowKeys: [], detailDialog: { ...detailDialog, selectedKey: v } }, () => { taxAgentStore.roleForm.resetForm(); const { selectedKey } = this.state; !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && this.getEnumList(); !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && this.getSettingRoler(roleId); selectedKey === "auth.DataTargetTypeEnum" && this.getConnectSymbol(); selectedKey === "baseinfo" && this.getRole(roleId); })}/> { !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && this.setState({ enumType: v, replaceDatas: [] })}/> } {this.getOperatorSetting()} { !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) && { this.state.selectedKey === "auth.DataTargetTypeEnum" && this.setState({ dataTargetSettings: { ...dataTargetSettings, link } })}/> this.setState({ dataTargetSettings: { ...dataTargetSettings, sortedIndex } })}/> } }
{/*表格*/} { !["auth.AuthTargetTypeEnum", "baseinfo"].includes(selectedKey) &&
{getLabel(111, "已设操作者")}
{/* 编辑操作者*/} this.setState({ replaceDatas }, () => this.addOperatorSettings())} onCancel={callback => this.setState({ editOperatorDialog: { ...editOperatorDialog, visible: false, record: {} } }, () => callback && callback())}/> {/*成员、数据明细查看*/} this.setState({ detailDialog: { ...detailDialog, visible: false } })}/>
}
); } } export default Index;