import { axiosInstance } from '@/api/rbac' import { assertBusinessOk, omsUrl, parseListPayload } from '@/api/oms/common' export interface NoticeDto { id?: number noticeType?: 'notice' | 'message' noticeTypeName?: string title?: string content?: string isPopup?: 0 | 1 receiverType?: 'user' | 'customer' receiverTypeName?: string receiverIds?: Array receiverSelectionIds?: Array readCount?: number receiverCount?: number createTime?: string updateTime?: string } export async function getNoticeList(params: { page?: number pageSize?: number noticeType?: string receiverType?: string keyword?: string }) { const res = await axiosInstance.get(omsUrl('/system/notice/list'), { params }) return parseListPayload(res.data) } export async function createNotice(body: Omit) { const res = await axiosInstance.post(omsUrl('/system/notice/create'), body) assertBusinessOk(res.data) } export async function updateNotice( body: Omit & { id: number | string } ) { const res = await axiosInstance.post(omsUrl('/system/notice/update'), body) assertBusinessOk(res.data) } export async function deleteNotice(id: number | string) { const res = await axiosInstance.post(omsUrl('/system/notice/delete'), { id }) assertBusinessOk(res.data) } export async function confirmNoticeRead(id: number | string) { const res = await axiosInstance.post(omsUrl('/system/notice/read-confirm'), { id }) assertBusinessOk(res.data) } export interface NoticeReceiverOption { value: number label: string extra?: string } export async function getNoticeReceiverOptions(params: { receiverType: 'user' | 'customer' keyword?: string page?: number pageSize?: number }) { const res = await axiosInstance.get(omsUrl('/system/notice/receiver-options'), { params }) const payload = res.data?.data ?? res.data?.Data ?? res.data ?? {} const itemsRaw = payload.items ?? payload.Items ?? [] const total = Number(payload.total ?? payload.Total ?? 0) const items = (Array.isArray(itemsRaw) ? itemsRaw : []).map((item: Record) => ({ value: Number(item.value ?? item.Value ?? 0), label: String(item.label ?? item.Label ?? ''), extra: item.extra != null || item.Extra != null ? String(item.extra ?? item.Extra ?? '') : undefined, })).filter((item) => item.value > 0) return { items, total } }