first
This commit is contained in:
175
user-app/src/api/appraisal.ts
Normal file
175
user-app/src/api/appraisal.ts
Normal file
@@ -0,0 +1,175 @@
|
||||
import { parseUploadResponse, request } from "../utils/request";
|
||||
import { buildAuthHeaders } from "../utils/auth";
|
||||
import { resolveApiBaseUrl } from "../utils/env";
|
||||
import { resolveOrderSourceChannel } from "../utils/order-source";
|
||||
|
||||
export interface CatalogOption {
|
||||
brand_id?: number;
|
||||
brand_name?: string;
|
||||
}
|
||||
|
||||
export interface CategoryOption {
|
||||
category_id: number;
|
||||
category_name: string;
|
||||
category_code: string;
|
||||
}
|
||||
|
||||
export interface UploadItem {
|
||||
item_code: string;
|
||||
item_name: string;
|
||||
guide_text: string;
|
||||
sample_image_url: string;
|
||||
is_required: boolean;
|
||||
quality_status: string;
|
||||
quality_message: string;
|
||||
files?: UploadFileAsset[];
|
||||
}
|
||||
|
||||
export interface UploadFileAsset {
|
||||
file_id: string;
|
||||
file_url: string;
|
||||
thumbnail_url: string;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface DraftDetail {
|
||||
draft_id: number;
|
||||
service_provider: string;
|
||||
service_mode: string;
|
||||
current_step: number;
|
||||
product_info: Record<string, any>;
|
||||
extra_info: Record<string, any>;
|
||||
upload_info?: {
|
||||
items: UploadItem[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface PreviewData {
|
||||
service_summary: {
|
||||
service_provider: string;
|
||||
service_provider_text: string;
|
||||
};
|
||||
product_summary: {
|
||||
product_name: string;
|
||||
category_name: string;
|
||||
brand_name: string;
|
||||
price: number;
|
||||
};
|
||||
upload_summary: {
|
||||
uploaded_count: number;
|
||||
};
|
||||
fee_detail: {
|
||||
service_fee: number;
|
||||
discount_fee: number;
|
||||
pay_amount: number;
|
||||
};
|
||||
agreements: Array<{
|
||||
code: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
target_url: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface SubmitResult {
|
||||
order_id: number;
|
||||
order_no: string;
|
||||
appraisal_no: string;
|
||||
pay_amount: number;
|
||||
next_status: string;
|
||||
}
|
||||
|
||||
export const appraisalApi = {
|
||||
createDraft(serviceProvider: string) {
|
||||
return request<{ draft_id: number; service_provider: string; service_mode: string }>(
|
||||
"/api/app/appraisal/draft/create",
|
||||
{
|
||||
method: "POST",
|
||||
data: {
|
||||
service_provider: serviceProvider,
|
||||
service_mode: "physical",
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
getDraft(draftId: number) {
|
||||
return request<DraftDetail>("/api/app/appraisal/draft", {
|
||||
params: { draft_id: draftId },
|
||||
});
|
||||
},
|
||||
saveDraft(payload: Record<string, unknown>) {
|
||||
return request<{ draft_id: number; current_step: number }>("/api/app/appraisal/draft/save", {
|
||||
method: "POST",
|
||||
data: payload,
|
||||
});
|
||||
},
|
||||
getBrands(categoryId: number) {
|
||||
return request<{ list: CatalogOption[] }>("/api/app/catalog/brands", {
|
||||
params: { category_id: categoryId },
|
||||
});
|
||||
},
|
||||
getCategories() {
|
||||
return request<{ list: CategoryOption[] }>("/api/app/catalog/categories");
|
||||
},
|
||||
getUploadTemplate(categoryId: number, serviceProvider: string) {
|
||||
return request<{ template_id: number; required_items: UploadItem[]; optional_items: UploadItem[] }>(
|
||||
"/api/app/appraisal/upload-template",
|
||||
{
|
||||
params: { category_id: categoryId, service_provider: serviceProvider },
|
||||
},
|
||||
);
|
||||
},
|
||||
preview(draftId: number) {
|
||||
return request<PreviewData>("/api/app/appraisal/preview", {
|
||||
method: "POST",
|
||||
data: { draft_id: draftId },
|
||||
});
|
||||
},
|
||||
submit(draftId: number, returnAddressId?: number) {
|
||||
return request<SubmitResult>("/api/app/appraisal/submit", {
|
||||
method: "POST",
|
||||
data: {
|
||||
draft_id: draftId,
|
||||
return_address_id: returnAddressId,
|
||||
source_channel: resolveOrderSourceChannel(),
|
||||
},
|
||||
});
|
||||
},
|
||||
uploadFile(payload: {
|
||||
draftId: number;
|
||||
itemCode: string;
|
||||
itemName: string;
|
||||
filePath: string;
|
||||
}) {
|
||||
const baseUrl = resolveApiBaseUrl().replace(/\/$/, "");
|
||||
return new Promise<UploadFileAsset>((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${baseUrl}/api/app/appraisal/file/upload`,
|
||||
filePath: payload.filePath,
|
||||
name: "file",
|
||||
header: buildAuthHeaders(),
|
||||
formData: {
|
||||
draft_id: payload.draftId,
|
||||
item_code: payload.itemCode,
|
||||
item_name: payload.itemName,
|
||||
},
|
||||
success: (response) => {
|
||||
try {
|
||||
resolve(parseUploadResponse<UploadFileAsset>(response, "图片上传失败"));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
fail: (error) => reject(error),
|
||||
});
|
||||
});
|
||||
},
|
||||
deleteFile(fileUrl: string) {
|
||||
return request<{ file_url: string }>("/api/app/appraisal/file/delete", {
|
||||
method: "POST",
|
||||
data: {
|
||||
file_url: fileUrl,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user