import React, { useEffect, useState } from 'react'; import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components'; import { Popconfirm, Space, Tag, message } from 'antd'; import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui'; import { PlusOutlined } from '@ant-design/icons'; import { ordersApi } from '@/services/orders'; import TourismForm, { TourismItem } from './components/TourismForm'; import { tenantApi } from '@/services/tenant'; const TourismPage: React.FC = () => { const [createOpen, setCreateOpen] = useState(false); const [editOpen, setEditOpen] = useState(false); const [current, setCurrent] = useState(undefined); const [params, setParams] = useState>({}); // 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据 useEffect(() => { (async () => { try { let tenantId: string | undefined; const cur: any = await tenantApi.getCurrentTenant(); tenantId = cur?.data?.tenantId ?? cur?.tenantId; if (!tenantId) { const stats: any = await tenantApi.getScopeStats(); tenantId = stats?.data?.currentTenantId ?? stats?.currentTenantId; } if (tenantId) setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren: true })); } catch { // 忽略错误,保留手动查询能力 } })(); }, []); const columns: any[] = [ { dataIndex: 'index', valueType: 'indexBorder', width: 48 }, { title: '旅游项目', dataIndex: 'tourismName' }, { title: '地址', dataIndex: 'tourismAddress' }, { title: '经度', dataIndex: 'longitude' }, { title: '纬度', dataIndex: 'latitude' }, { title: '首页展示', dataIndex: 'showInHomepage', render: (v: number) => {v === 1 ? '是' : '否'}, }, { title: '联系电话', dataIndex: 'tourismPhone' }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' }, { title: '状态', dataIndex: 'status', render: (v: number) => {v === 1 ? '启用' : '禁用'}, }, { title: '操作', key: 'action', render: (_: any, record: TourismItem) => ( { setCurrent(record); setEditOpen(true); }}>编辑 { const hide = message.loading('正在删除...'); try { await ordersApi.deleteTourism(record.id!); message.success('删除成功'); } catch { message.error('删除失败'); } finally { hide(); } }} > 删除 ), }, ]; return ( { setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren })); }} onFinish={async (values) => setParams(values)} > } onClick={() => setCreateOpen(true)}> 新增 } /> {params?.tenantId ? ( rowKey="id" params={params} request={(p) => ordersApi.tourism({ ...(p as any), ...params })} columns={columns} search={false} pagination={{ showSizeChanger: true, showQuickJumper: true }} toolBarRender={false} /> ) : null} { const hide = message.loading('保存中...'); try { await ordersApi.saveOrUpdateTourism(values); message.success('新增成功'); return true; } catch { message.error('新增失败'); return false; } finally { hide(); } }} /> { const hide = message.loading('保存中...'); try { await ordersApi.saveOrUpdateTourism({ ...(current as any), ...values }); message.success('修改成功'); return true; } catch { message.error('修改失败'); return false; } finally { hide(); } }} /> ); }; export default TourismPage;