/* * @Author: your name * @Date: 2022-01-12 17:11:11 * @LastEditTime: 2022-07-07 16:26:50 * @LastEditors: code4eat awesomedema@gmail.com * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/userManage/modal.tsx */ import React, { useEffect, useRef, useState } from 'react'; import KCModal from '@/components/KCModal'; import KCProSelect from '@/components/KCProSelect'; import { hospManageModelState, Dispatch } from 'umi'; import { ProFormText, ProFormRadio, ProFormDependency, ProFormDigit } from '@ant-design/pro-form'; import type { ProColumns } from '@ant-design/pro-table'; import { EditableProTable } from '@ant-design/pro-table'; import { getHospList, getHospYoushuAccounts, getMainHosp, YoushuAccountsType } from '@/service/hospList'; import type { AddUsersDataType } from '@/service/user'; import { randomString } from '@/utils'; import { TableActType } from '..'; import { Form } from 'antd'; import MenuEditer from '@/pages/platform/components/menuEditer/menu'; import { getPlatformDictionary } from '@/service/dictionary'; interface ActModalProps extends hospManageModelState { dispatch: Dispatch | undefined; } type DataSourceType = YoushuAccountsType & { key: number }; const ActModal: React.FC = ({ dispatch, isShowModal, tableAct, currentEdit }) => { const [editableKeys, setEditableRowKeys] = useState([]); const [dataSource, setDataSource] = useState([]); const columns: ProColumns[] = [ { title: 'id', dataIndex: 'id', key: 'id', hideInTable: true, }, { title: '账号', dataIndex: 'account', key: 'account', }, { title: '密码', key: 'password', dataIndex: 'password', }, { title: '是否默认', dataIndex: 'isDefault', valueType: 'select', request: async () => [ { value: 1, label: '是', }, { value: 0, label: '否', }, ], }, { title: '操作', valueType: 'option', key: 'option', width: 120, render: (text, record, _, action) => [ { setDataSource(dataSource.filter((item) => item.key !== record.key)); }} > 删除 , ], }, ]; const onVisibleChangeHandle = (bool: boolean) => { if (!bool) { dispatch && dispatch({ type: 'hospManageModel/cancelTableAct', }); } }; const onFinishHandle = (data: any & AddUsersDataType) => { console.log({ data }); if (tableAct == TableActType.ADD) { dispatch && dispatch({ type: 'hospManageModel/postAddData', payload: data, }); } if ( tableAct == TableActType.EDIT || tableAct == TableActType.EDITMENU || tableAct == TableActType.BINDACCOUNT ) { dispatch && dispatch({ type: 'hospManageModel/postEditData', payload: data, }); } return true; }; const setModalTitle = () => { if (tableAct == TableActType.EDIT) { return '编辑院区'; } if (tableAct == TableActType.ADD) { return '新增院区'; } if (tableAct == TableActType.EDITMENU) { return '绑定菜单'; } if (tableAct == TableActType.BINDACCOUNT) { return '院区报告设置'; } }; const setInitialValues = () => { if (tableAct == TableActType.EDIT) { return { ...currentEdit, isDataShare: currentEdit?.dataShare == '是' ? 1 : 0, }; } if (tableAct == TableActType.ADD) { return { hospSign: randomString(16), isDataShare: 0 }; } if (tableAct == TableActType.EDITMENU) { return { ...currentEdit }; } if (tableAct == TableActType.BINDACCOUNT) { if (currentEdit?.reportId) { return { ...currentEdit, reportId: parseInt(currentEdit.reportId) }; } } }; useEffect(() => { //加装key字段 const fixedDataSource = currentEdit?.youshuUsers ? currentEdit.youshuUsers.map((t) => ({ ...t, key: Number((Math.random() * 1000000).toFixed(0)), })) : []; setDataSource(fixedDataSource); }, [currentEdit]); return ( onFinishHandle(tableAct == TableActType.BINDACCOUNT ? { ...data, dataSource } : data) } > {tableAct == TableActType.EDITMENU && ( )} {tableAct != TableActType.EDITMENU && tableAct != TableActType.BINDACCOUNT && ( <> {({ isHospital }) => { if (isHospital && isHospital == 1) { return ( { const hospList = await getHospList(); if (hospList) { return hospList.map((t) => ({ label: t.name, value: t.id, })); } return []; }} rules={[ { required: true, message: '请选择院区!', }, ]} /> ); } }} { const resp = await getPlatformDictionary('HOSPITAL_LEVEL'); if (resp) { return resp[0].dataVoList.map((t) => ({ label: t.code, value: t.value, })); } return []; }} rules={[ { required: true, message: '请选择!', }, ]} /> { const resp = await getPlatformDictionary('HOSPITAL_TYPE'); if (resp) { return resp[0].dataVoList.map((t) => ({ label: t.code, value: t.value, })); } return []; }} rules={[ { required: true, message: '请选择!', }, ]} /> { const resp = await getPlatformDictionary('HOSPITAL_NATURE'); if (resp) { return resp[0].dataVoList.map((t) => ({ label: t.code, value: t.value, })); } return []; }} rules={[ { required: true, message: '请选择!', }, ]} /> )} {tableAct == TableActType.BINDACCOUNT && ( <> rowKey="key" headerTitle="院区[有数]账号绑定" columns={columns} value={dataSource} recordCreatorProps={{ record: { key: Number((Math.random() * 1000000).toFixed(0)), id: -1, userName: '', account: '', password: '', isDefault: 0, }, }} onChange={setDataSource} editable={{ // type: 'multiple', deletePopconfirmMessage: '确定删除此行?', editableKeys, onChange: setEditableRowKeys, }} /> )} ); }; export default ActModal;