207 lines
6.5 KiB
TypeScript
207 lines
6.5 KiB
TypeScript
import { axios } from "timi-web-api";
|
|
import type {
|
|
Product,
|
|
ProductCategory,
|
|
ProductCategoryPage,
|
|
ProductPage,
|
|
ProductPageResult,
|
|
ProductSku,
|
|
FulfillmentProductSku,
|
|
ProductSpec,
|
|
ProductSpecValue,
|
|
ProductStock,
|
|
ProductStockBatchRequest,
|
|
ProductStockProduct,
|
|
ProductStockChangeRequest,
|
|
ProductStockManualInBatchRequest,
|
|
ProductStockManualRevokeRequest,
|
|
ProductStockPage,
|
|
StockRecord,
|
|
StockRecordPage,
|
|
StockRecordPageResult
|
|
} from "@/types/Product";
|
|
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
|
|
|
|
const PRODUCT_URI = "/gao/product";
|
|
const STOCK_URI = "/gao/product/stock";
|
|
|
|
async function categoryList(page: ProductCategoryPage): Promise<ProductPageResult<ProductCategory>> {
|
|
return await axios.post(`${PRODUCT_URI}/category/list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function categoryCreate(category: ProductCategory): Promise<string> {
|
|
return await axios.post(`${PRODUCT_URI}/category/create`, withCurrentStoreId(category));
|
|
}
|
|
|
|
async function categoryUpdate(category: ProductCategory): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/category/update`, withCurrentStoreId(category));
|
|
}
|
|
|
|
async function categorySort(idList: string[]): Promise<void> {
|
|
return await axios.post(`${PRODUCT_URI}/category/sort`, idList);
|
|
}
|
|
|
|
async function categoryDisable(id: string): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/category/disable`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function list(page: ProductPage): Promise<ProductPageResult<Product>> {
|
|
return await axios.post(`${PRODUCT_URI}/list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function detail(id: string): Promise<Product> {
|
|
return await axios.post(`${PRODUCT_URI}/detail`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function create(product: Product): Promise<string> {
|
|
return await axios.post(`${PRODUCT_URI}/create`, withCurrentStoreId(product));
|
|
}
|
|
|
|
async function update(product: Product): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/update`, withCurrentStoreId(product));
|
|
}
|
|
|
|
async function disable(id: string): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/disable`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function remove(id: string): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/delete`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function skuDetail(id: string): Promise<ProductSku> {
|
|
return await axios.post(`${PRODUCT_URI}/sku/detail`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function fulfillmentSkuList(idList: string[]): Promise<FulfillmentProductSku[]> {
|
|
return await axios.post(`${PRODUCT_URI}/sku/fulfillment-list`, idList);
|
|
}
|
|
|
|
async function skuCreate(sku: ProductSku): Promise<string> {
|
|
return await axios.post(`${PRODUCT_URI}/sku/create`, withCurrentStoreId(sku));
|
|
}
|
|
|
|
async function skuUpdate(sku: ProductSku): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/sku/update`, withCurrentStoreId(sku));
|
|
}
|
|
|
|
async function skuDisable(id: string): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/sku/disable`, undefined, { params: { id } });
|
|
}
|
|
|
|
async function specList(productId: string): Promise<ProductSpec[]> {
|
|
return await axios.post(`${PRODUCT_URI}/spec/list`, undefined, { params: { productId } });
|
|
}
|
|
|
|
async function specCreate(spec: ProductSpec): Promise<string> {
|
|
return await axios.post(`${PRODUCT_URI}/spec/create`, spec);
|
|
}
|
|
|
|
async function specUpdate(spec: ProductSpec): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/spec/update`, spec);
|
|
}
|
|
|
|
async function specValueCreate(value: ProductSpecValue): Promise<string> {
|
|
return await axios.post(`${PRODUCT_URI}/spec/value/create`, value);
|
|
}
|
|
|
|
async function specValueUpdate(value: ProductSpecValue): Promise<void> {
|
|
await axios.post(`${PRODUCT_URI}/spec/value/update`, value);
|
|
}
|
|
|
|
async function sellableList(page: ProductPage): Promise<Product[]> {
|
|
return await axios.post(`${PRODUCT_URI}/sellable/list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function stockList(page: ProductStockPage): Promise<ProductPageResult<ProductStock>> {
|
|
return await axios.post(`${STOCK_URI}/list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function stockProductList(page: ProductStockPage): Promise<ProductPageResult<ProductStockProduct>> {
|
|
return await axios.post(`${STOCK_URI}/product-list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function stockDetail(skuId: string, storeId?: string): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/detail`, undefined, {
|
|
params: { skuId, storeId: storeId || getCurrentStoreId() }
|
|
});
|
|
}
|
|
|
|
async function stockBatchDetail(request: ProductStockBatchRequest): Promise<ProductStock[]> {
|
|
return await axios.post(`${STOCK_URI}/batch-detail`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function initialIn(request: ProductStockChangeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/initial-in`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function manualIn(request: ProductStockChangeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/manual-in`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function manualInBatch(request: ProductStockManualInBatchRequest): Promise<ProductStock[]> {
|
|
return await axios.post(`${STOCK_URI}/manual-in/batch`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function manualOut(request: ProductStockChangeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/manual-out`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function manualRevoke(request: ProductStockManualRevokeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/manual-revoke`, request);
|
|
}
|
|
|
|
async function stocktakeGain(request: ProductStockChangeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/stocktake-gain`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function stocktakeLoss(request: ProductStockChangeRequest): Promise<ProductStock> {
|
|
return await axios.post(`${STOCK_URI}/stocktake-loss`, withCurrentStoreId(request));
|
|
}
|
|
|
|
async function recordList(page: StockRecordPage): Promise<StockRecordPageResult> {
|
|
return await axios.post(`${STOCK_URI}/record/list`, withCurrentStoreId(page));
|
|
}
|
|
|
|
async function recordDetail(id: string): Promise<StockRecord> {
|
|
return await axios.post(`${STOCK_URI}/record/detail`, undefined, { params: { id } });
|
|
}
|
|
|
|
export default {
|
|
categoryList,
|
|
categoryCreate,
|
|
categoryUpdate,
|
|
categorySort,
|
|
categoryDisable,
|
|
list,
|
|
detail,
|
|
create,
|
|
update,
|
|
disable,
|
|
remove,
|
|
skuDetail,
|
|
fulfillmentSkuList,
|
|
skuCreate,
|
|
skuUpdate,
|
|
skuDisable,
|
|
specList,
|
|
specCreate,
|
|
specUpdate,
|
|
specValueCreate,
|
|
specValueUpdate,
|
|
sellableList,
|
|
stockList,
|
|
stockProductList,
|
|
stockDetail,
|
|
stockBatchDetail,
|
|
initialIn,
|
|
manualIn,
|
|
manualInBatch,
|
|
manualOut,
|
|
manualRevoke,
|
|
stocktakeGain,
|
|
stocktakeLoss,
|
|
recordList,
|
|
recordDetail
|
|
};
|