合伙人端登录接口优化

This commit is contained in:
2026-07-07 15:22:55 +08:00
parent 7dd8a6662b
commit 2c74f6a08c
4 changed files with 133 additions and 51 deletions
@@ -1,6 +1,6 @@
import { useState } from 'react';
import {
Button, Descriptions, Drawer, Form, Input, Modal, Select, Space, Table, Tabs, Tag, Typography, message,
Button, Drawer, Form, Input, Modal, Select, Space, Table, Tabs, Tag, Typography, message,
} from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { request, type Paginated } from '../lib/api';
@@ -28,6 +28,7 @@ type Detail = Row & { bills?: BillRow[]; orders?: OrderRow[] };
export default function PartnerAccountsPage() {
const [form] = Form.useForm();
const [editForm] = Form.useForm();
const [createForm] = Form.useForm();
const [filters, setFilters] = useState<Record<string, string>>({});
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
@@ -50,6 +51,22 @@ export default function PartnerAccountsPage() {
setPartners(res.items);
}
async function openAccount(id: string) {
const d = await request<Detail>(`/admin/partner-accounts/${id}`);
setDetail(d);
editForm.setFieldsValue({ name: d.name, phone: d.phone, status: d.status });
setDrawerOpen(true);
}
async function saveAccount() {
if (!detail) return;
const v = await editForm.validateFields();
await request(`/admin/partner-accounts/${detail.id}`, { method: 'PUT', body: JSON.stringify(v) });
message.success('已保存');
setDrawerOpen(false);
void reload();
}
const columns: ColumnsType<Row> = [
{ title: '姓名', dataIndex: 'name', width: 100 },
{ title: '手机', dataIndex: 'phone', width: 120 },
@@ -58,12 +75,12 @@ export default function PartnerAccountsPage() {
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => <Tag>{ACCOUNT_STATUS_LABELS[s] || s}</Tag> },
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
{
title: '操作', width: 80,
title: '操作', width: 120,
render: (_, row) => (
<Button type="link" size="small" onClick={async () => {
setDetail(await request<Detail>(`/admin/partner-accounts/${row.id}`));
setDrawerOpen(true);
}}></Button>
<Space>
<Button type="link" size="small" onClick={() => void openAccount(row.id)}></Button>
<Button type="link" size="small" onClick={() => void openAccount(row.id)}></Button>
</Space>
),
},
];
@@ -100,27 +117,41 @@ export default function PartnerAccountsPage() {
</Form>
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 900 }}
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
<Drawer title="开城合伙人账户" width={720} open={drawerOpen} onClose={() => setDrawerOpen(false)}
extra={detail && (
<Select defaultValue={detail.status} style={{ width: 100 }}
options={Object.entries(ACCOUNT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
onChange={async (status) => {
await request(`/admin/partner-accounts/${detail.id}`, { method: 'PUT', body: JSON.stringify({ status }) });
message.success('已更新');
void reload();
}} />
)}>
<Drawer
title="编辑开城合伙人账户"
width={720}
open={drawerOpen}
onClose={() => setDrawerOpen(false)}
extra={<Button type="primary" onClick={() => void saveAccount()}></Button>}
>
{detail && (
<Tabs items={[
{
key: 'info',
label: '基本信息',
children: (
<Descriptions column={1} bordered size="small">
<Descriptions.Item label="姓名">{detail.name}</Descriptions.Item>
<Descriptions.Item label="手机">{detail.phone}</Descriptions.Item>
<Descriptions.Item label="开城合伙人">{detail.partner?.companyName}</Descriptions.Item>
</Descriptions>
<Form form={editForm} layout="vertical">
<Form.Item label="开城合伙人">
<Input value={detail.partner?.companyName} disabled />
</Form.Item>
<Form.Item name="name" label="姓名" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item
name="phone"
label="登录手机"
rules={[
{ required: true },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' },
]}
>
<Input maxLength={11} />
</Form.Item>
<Form.Item name="status" label="状态" rules={[{ required: true }]}>
<Select options={Object.entries(ACCOUNT_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
</Form.Item>
<Typography.Text type="secondary">
H5 使
</Typography.Text>
</Form>
),
},
{
@@ -155,7 +186,16 @@ export default function PartnerAccountsPage() {
<Select showSearch optionFilterProp="label" options={partners.map((p) => ({ value: p.id, label: p.companyName }))} />
</Form.Item>
<Form.Item name="name" label="姓名" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item name="phone" label="手机" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item
name="phone"
label="登录手机"
rules={[
{ required: true },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' },
]}
>
<Input maxLength={11} />
</Form.Item>
</Form>
</Modal>
</div>