/* * @Author: cclue * @Date: 2022-04-28 10:47:35 * @LastEditTime: 2024-12-16 10:57:06 * @LastEditors: cclu 1106109051@qq.com * @Description: 经营业态管理页面 * @FilePath: \cloud-platform\src\pages\basicManage\BusinessTrade\index.tsx */ import ProTable from '@ant-design/pro-table'; import React, { useState, useRef } from 'react'; import { PageContainer } from '@ant-design/pro-layout'; import ProDescriptions from '@ant-design/pro-descriptions'; import { PlusOutlined } from '@ant-design/icons'; import { Button, message, TreeSelect, Form, Drawer, Popconfirm, Row, Col, Avatar, Switch } from 'antd'; import { ModalForm, ProFormText, ProFormDigit, ProFormTextArea, ProFormSelect } from '@ant-design/pro-form'; import type { FormInstance } from 'antd'; import type { BusinessTradeModel } from './data'; import type { ProColumns, ActionType } from '@ant-design/pro-table'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import { getList, delBusinessTrade, updateBusinessTrade } from './service' import PageTitleBox from '@/components/PageTitleBox'; import { CurrentUser } from 'umi'; /** * @en-US Add node * @zh-CN 添加经营业态 * @param fields */ const handleAddUpdate = async (fields: any) => { const hide = message.loading('正在提交...'); try { const result: any = await updateBusinessTrade({ ...fields }) hide(); if (result.Result_Code !== 100) { message.error(`${result.Result_Desc}` || `${result.Result_Code}:提交失败`) return false } message.success(fields.AUTOSTATISTICS_ID ? "更新成功!" : "新建成功!") return true } catch (error) { hide(); message.error("提交失败") return false } } /** * @en-US delete node * @zh-CN 删除 经营业态 * @param fields */ const handleDelete = async (nodeId: number) => { const hide = message.loading('正在删除...'); try { const result = await delBusinessTrade(nodeId) hide(); if (result.Result_Code !== 100) { message.error(`${result.Result_Code}:删除失败`) return false } message.success("删除成功!") return true } catch (error) { hide(); message.error("删除失败") return false } } /** * @description: 经营业态组件 * @param {*} * @return {*} 组件dom */ // const BusinessTradeModelTable: React.FC = () => { const BusinessTradeModelTable: React.FC<{ currentUser: CurrentUser }> = (props) => { const { currentUser } = props const actionRef = useRef(); const formRef = useRef(); const [createModalVisible, handleModalVisible] = useState(false); // 新建窗口的弹窗 const [showDetail, setShowDetail] = useState(); // 显示详情抽屉 const [currentRow, setCurrentRow] = useState();// 当前选中行数据 const [treeSelectOption, setTreeSelectOption] = useState(); // 可选择项 const columns: ProColumns[] = [ { dataIndex: 'AUTOSTATISTICS_ICO', width: 90, hideInDescriptions: true, render: (_, record) => { return {record.AUTOSTATISTICS_NAME.substring(0, 1)} } }, { title: '业态名称', dataIndex: 'AUTOSTATISTICS_NAME', hideInDescriptions: true, hideInSearch: true, render: (dom, entity) => { return ( { setCurrentRow(entity); setShowDetail(true); }} > {dom} ); }, }, { title: '业态状态', dataIndex: 'AUTOSTATISTICS_STATE', valueType: 'select', valueEnum: { 0: { text: '无效', status: 'error' }, 1: { text: '有效', status: 'success' }, 2: { text: '不可选', status: 'default' } }, onFilter: true, filters: true }, { title: '索引', dataIndex: 'AUTOSTATISTICS_INDEX', hideInSearch: true, sorter: (a, b) => b.AUTOSTATISTICS_INDEX - a.AUTOSTATISTICS_INDEX }, { title: '所属业主', dataIndex: 'OWNERUNIT_NAME', sorter: true, hideInSearch: true, }, { title: '说明', dataIndex: 'AUTOSTATISTICS_DESC', hideInSearch: true, }, { title: '操作', dataIndex: 'option', valueType: 'option', hideInDescriptions: true, render: (_, record) => [ { setCurrentRow(record); handleModalVisible(true); }} > 编辑 , { const sucesse = await handleDelete(record.AUTOSTATISTICS_ID) if (sucesse && actionRef.current) { actionRef.current.reload() } }}> 删除 ] } ] return ( headerTitle={} rowKey="AUTOSTATISTICS_ID" search={false} actionRef={actionRef} request={async (params) => { const data: any = await getList({ BusinessTradeModelPID: -1, ...params }) setTreeSelectOption([{ AUTOSTATISTICS_NAME: '默认', AUTOSTATISTICS_ID: -1, children: [...data.data] }]) console.log('data', data); return data }} columns={columns} toolbar={{ actions: [ ] }} /> { /* 更新 信息弹出框 */} layout={'horizontal'} wrapperCol={{ span: 16 }} labelCol={{ span: 6 }} width={600} title={currentRow ? '更新经营业态' : '新建经营业态'} visible={createModalVisible} formRef={formRef} onVisibleChange={(value) => { handleModalVisible(value) if (!value) { formRef.current?.resetFields(); setCurrentRow(undefined); } else { formRef.current?.setFieldsValue(currentRow || { AUTOSTATISTICS_TYPE: 2000 }) } }} onFinish={async (values) => { let newValue: any = { ...values } if (currentRow) { // 编辑数据 newValue = { ...currentRow, ...newValue } } newValue.AUTOSTATISTICS_STATE = values.AUTOSTATISTICS_STATE ? 1 : 0 newValue.AUTOSTATISTICS_TYPE = currentRow?.AUTOSTATISTICS_TYPE || 2000 const success = await handleAddUpdate(newValue); if (success) { if (actionRef.current) { actionRef.current.reload(); } return true } return false }} > {/* 当前依赖包动画过渡有问题 临时采用 Form.Item 方式进行Switch交互 */} {/* */} {/* 详情抽屉 */} { setCurrentRow(undefined); setShowDetail(false); }} closable={false} > {currentRow?.AUTOSTATISTICS_NAME && ( column={2} title={currentRow?.AUTOSTATISTICS_NAME} request={async () => ({ data: currentRow || {}, })} params={{ id: currentRow?.AUTOSTATISTICS_NAME, }} columns={columns as ProDescriptionsItemProps[]} /> )} ) } export default BusinessTradeModelTable;