feat: 增加后台业务提供项配置
This commit is contained in:
1 parent
8e46c2c293
commit
09841aed05
1 file changed
+123
-2
@@ -1,6 +1,18 @@
|
||||
import { Button, Card, Form, Input, Modal, Select, Space, Table, Tag, message } from "antd";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
message,
|
||||
Divider,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { PublicService } from "@personal-brand/api-client";
|
||||
import type { Offering, PublicService } from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
@@ -10,10 +22,30 @@ export function ServicesPage() {
|
||||
const [editing, setEditing] = useState<PublicService | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [offeringForm] = Form.useForm();
|
||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||
const query = useQuery({
|
||||
queryKey: ["admin-services"],
|
||||
queryFn: () => client.listAdminServices(),
|
||||
});
|
||||
const offerings = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
});
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) =>
|
||||
editingOffering
|
||||
? client.updateAdminOffering(editingOffering.id, values)
|
||||
: client.createAdminOffering(values as Omit<Offering, "id" | "brandId">),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已保存");
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const save = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) =>
|
||||
editing
|
||||
@@ -42,6 +74,11 @@ export function ServicesPage() {
|
||||
item ?? { categoryKey: "standard", bookingEnabled: true, isEnabled: true, sortOrder: 0 },
|
||||
);
|
||||
};
|
||||
const beginOffering = (item?: Offering) => {
|
||||
setEditingOffering(item ?? null);
|
||||
setOfferingOpen(true);
|
||||
offeringForm.setFieldsValue(item ?? { kind: "service", isEnabled: true, sortOrder: 0 });
|
||||
};
|
||||
return (
|
||||
<Card
|
||||
title="服务与合作"
|
||||
@@ -79,6 +116,90 @@ export function ServicesPage() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Divider orientation="left">通用业务提供项</Divider>
|
||||
<Card
|
||||
size="small"
|
||||
extra={
|
||||
<Button type="primary" onClick={() => beginOffering()}>
|
||||
新增提供项
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={offerings.isLoading}
|
||||
dataSource={offerings.data ?? []}
|
||||
columns={[
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{ title: "类型", dataIndex: "kind", render: (value) => <Tag>{value}</Tag> },
|
||||
{ title: "价格", dataIndex: "priceText" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isEnabled",
|
||||
render: (value) => (value ? "已启用" : "已停用"),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: Offering) => (
|
||||
<Button size="small" onClick={() => beginOffering(item)}>
|
||||
编辑详情
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
<Modal
|
||||
open={offeringOpen}
|
||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||
onCancel={() => {
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
}}
|
||||
onOk={() => offeringForm.submit()}
|
||||
confirmLoading={saveOffering.isPending}
|
||||
>
|
||||
<Form
|
||||
form={offeringForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveOffering.mutate(values)}
|
||||
>
|
||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "service", label: "服务" },
|
||||
{ value: "product", label: "定制产品" },
|
||||
{ value: "package", label: "套餐" },
|
||||
{ value: "subscription", label: "订阅" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="一句话说明">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="description" label="详细介绍">
|
||||
<Input.TextArea rows={5} />
|
||||
</Form.Item>
|
||||
<Form.Item name="priceText" label="价格展示">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="coverUrl" label="封面图片 URL">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="isEnabled" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "已启用" },
|
||||
{ value: false, label: "已停用" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<Modal
|
||||
open={open}
|
||||
title={editing ? "编辑服务" : "新增服务"}
|
||||
|
||||
Reference in new issue
Block a user