Files
aida_front/src/views/SellerDashboard/MyListings/EditDetail/api.ts
2026-05-07 13:15:21 +08:00

63 lines
1.8 KiB
TypeScript

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