"use client"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Separator } from "@/components/ui/separator"
import { Textarea } from "@/components/ui/textarea"
import { addShopAnnouncement, deleteShopAnnouncement, updateShop } from "@/lib/api"
import { toApiError } from "@/lib/errors"
import { useMyShop } from "@/lib/hooks/use-my-shop"
import { notifyInfo, notifySuccess } from "@/lib/toast"
import type { Shop } from "@/lib/types"
import { DollarSign, Edit, ExternalLink, ListOrdered, Star, Users } from "lucide-react"
import Link from "next/link"
import { useState } from "react"
export default function ShopManagementPage() {
const { shop, setShop, loading, error, refreshShop } = useMyShop()
if (loading) {
return
加载中...
}
if (error) {
return {error}
}
if (!shop) {
return 当前账号没有可管理的店铺
}
return (
)
}
function ShopManagementContent({
shop,
setShop,
refreshShop,
}: {
shop: Shop
setShop: (shop: Shop | null) => void
refreshShop: () => Promise
}) {
const [name, setName] = useState(shop.name)
const [description, setDescription] = useState(shop.description)
const [saving, setSaving] = useState(false)
const handleSave = async () => {
setSaving(true)
try {
const nextShop = await updateShop(shop.id, {
name,
description,
commissionType: shop.commissionType,
commissionValue: shop.commissionValue,
allowMultiShop: shop.allowMultiShop,
allowIndependentOrders: shop.allowIndependentOrders,
dispatchMode: shop.dispatchMode,
})
setShop(nextShop)
notifySuccess("店铺信息已保存")
} catch (error) {
notifyInfo(toApiError(error).msg)
} finally {
setSaving(false)
}
}
const handleAddAnnouncement = async () => {
const next = window.prompt("", "")
if (next === null) return
const value = next.trim()
if (!value) return
setSaving(true)
try {
await addShopAnnouncement(shop.id, value)
await refreshShop()
notifySuccess("公告已添加")
} catch (error) {
notifyInfo(toApiError(error).msg)
} finally {
setSaving(false)
}
}
const handleDeleteAnnouncement = async (index: number) => {
setSaving(true)
try {
await deleteShopAnnouncement(shop.id, index)
await refreshShop()
notifySuccess("公告已删除")
} catch (error) {
notifyInfo(toApiError(error).msg)
} finally {
setSaving(false)
}
}
return (
店铺管理
总订单
{shop.totalOrders}
评分
{shop.rating}
签约打手
{shop.playerCount}
抽成比例
{shop.commissionType === "percentage"
? `${shop.commissionValue}%`
: `¥${shop.commissionValue}`}
基本信息
setName(event.target.value)} />
公告管理
{shop.announcements.map((announcement, index) => (
{announcement}
))}
运营设置
派单模式
{shop.dispatchMode === "manual" ? "手动派单" : "自动派单"}
允许多店挂靠
{shop.allowMultiShop ? "是" : "否"}
允许独立接单
{shop.allowIndependentOrders ? "是" : "否"}
)
}