Files
aida_front/src/views/SellerDashboard/MyListings/EditDetail/api.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-04-27 09:40:00 +08:00
import { Https } from "@/tool/https"
2026-05-07 13:15:21 +08:00
import type { ListingImageCategory, SketchDetailResponse } from "./types"
2026-04-27 09:40:00 +08:00
2026-04-27 14:39:59 +08:00
// 编辑时根据ID获取信息
export const fetchListingDetailById = (id) => {
return Https.axiosGet("/seller/listing/detail", { params: { id } })
}
2026-05-07 10:21:08 +08:00
type SketchIDs = Array<number | string>
2026-04-27 14:39:59 +08:00
// 获取designItemId对应的产品图
2026-05-07 10:21:08 +08:00
export const fetchSketchDetail = (data: SketchIDs): Promise<SketchDetailResponse[]> => {
2026-04-27 09:40:00 +08:00
let params = "?"
data.forEach((id, index) => {
if (index === data.length - 1) {
params += `designItemIds=${id}`
} else {
params += `designItemIds=${id}&`
}
})
2026-04-29 09:56:11 +08:00
return Https.axiosGet(`/aida/api/seller/sketchDetail${params}`)
2026-04-27 09:40:00 +08:00
}
2026-04-27 14:39:59 +08:00
interface ImageObj {
2026-05-07 13:15:21 +08:00
id?: number // 图片id,有值会更新,没有会自动新增
category: ListingImageCategory // 图片类型
imageUrl?: string | null
isSelected?: number
sortOrder?: number
2026-04-27 14:39:59 +08:00
}
interface DetailData {
id: number | string // 商品Id
title: string // 商品名
description: string // 商品描述
2026-05-07 13:15:21 +08:00
price: number | string // 价格
2026-04-27 14:39:59 +08:00
stock?: number // 库存
viewCount?: number // 浏览量
status: 0 | 1 | 2 // 0草稿 1发布 2删除
images: ImageObj[]
designFor: "male" | "female"
2026-05-07 13:15:21 +08:00
productCategory: string[] | null
2026-04-27 14:39:59 +08:00
}
// 保存/更新表单
2026-05-07 13:15:21 +08:00
export const fetchUpdateListing = (data: DetailData[]) => {
2026-04-27 14:39:59 +08:00
return Https.axiosPost("/seller/listing/batch", data)
}
interface StatusData {
id: number | string
status: 0 | 1 | 2 // 0草稿 1发布 2删除
}
// 设置商品状态
export const fetchChangeStatus = (data: StatusData) => {
return Https.axiosPut("/seller/listing/status", data)
}
2026-04-27 09:40:00 +08:00
export const uploadFile = (file) => {
const formData = new FormData()
formData.append("file", file)
2026-04-27 14:39:59 +08:00
return Https.axiosPost("/seller/file/upload", formData, {
2026-04-27 09:40:00 +08:00
headers: { "Content-Type": "multipart/form-data", Accept: "*/*" }
})
}