update get data priceslot

This commit is contained in:
thanawat saiyota 2026-06-16 11:30:23 +07:00
parent cd88d5aed9
commit 6a2f4e5945
5 changed files with 912 additions and 337 deletions

View file

@ -7,8 +7,12 @@ import {
markSheetPriceAsSent,
sheetPriceLoading,
streamingRawData,
setPendingProductCodesCountry
setPendingProductCodesCountry,
setPendingPriceSlotsCountry,
priceSlotsLoading,
resetPriceSlotsCountry
} from '../stores/sheetStore';
import type { PriceSlot } from '../stores/sheetStore';
import { setGenLayoutGenerating } from '../stores/genLayoutStore';
export function requestCatalogs(country: string): boolean {
@ -19,21 +23,38 @@ export function requestCatalogs(country: string): boolean {
}
export function requestPriceSlots(country: string): boolean {
return sendCommandRequest('sheet', {
setPendingPriceSlotsCountry(country);
resetPriceSlotsCountry(country);
const request_id = crypto.randomUUID();
streamingRawData.update((data) => ({
...data,
priceslot: {
request_id,
country,
chunks: [],
rawParts: []
}
}));
priceSlotsLoading.set(true);
const values = {
country: country,
param: 'priceslot'
});
param: 'price',
option: 'PriceSlot',
stream: true,
request_id
};
console.log('[sheetService] Sending PriceSlot request:', values);
const sent = sendCommandRequest('sheet', values);
console.log('[sheetService] PriceSlot request sent:', sent);
if (!sent) {
priceSlotsLoading.set(false);
}
return sent;
}
export function updatePriceSlot(
country: string,
content: {
slot: number;
name: string;
description: string;
products: { product_code: string; price: number | null; row_index?: number }[];
}
): boolean {
export function updatePriceSlot(country: string, content: PriceSlot): boolean {
return sendCommandRequest('sheet', {
country: country,
content: content,
@ -210,7 +231,14 @@ export function requestSheetPrice(country: string, productCodes: string[]): bool
// Convert to array of objects (backend expects objects, not strings)
const content = productCodes.map((code) => ({ product_code: code }));
console.log('[sheetService] Sending sheet price request for country:', country, 'codes:', productCodes.length, 'request_id:', request_id);
console.log(
'[sheetService] Sending sheet price request for country:',
country,
'codes:',
productCodes.length,
'request_id:',
request_id
);
const sent = sendCommandRequest('sheet', {
country: country,
@ -242,7 +270,12 @@ export function updateSheetPrice(
return false;
}
console.log('[sheetService] Updating sheet price for country:', country, 'items:', content.length);
console.log(
'[sheetService] Updating sheet price for country:',
country,
'items:',
content.length
);
return sendCommandRequest('sheet', {
country: country,
@ -255,16 +288,19 @@ export function updateSheetPrice(
* Add new price rows to sheet (for product codes that don't exist in price sheet)
* content: [{ cells: [product_code, name_en, name_th, ..., price, ...] }]
*/
export function addSheetPrice(
country: string,
content: { cells: string[] }[]
): boolean {
export function addSheetPrice(country: string, content: { cells: string[] }[]): boolean {
if (!content || content.length === 0) {
console.warn('[sheetService] No content to add');
return false;
}
console.log('[sheetService] Adding price rows for country:', country, 'items:', content.length, content);
console.log(
'[sheetService] Adding price rows for country:',
country,
'items:',
content.length,
content
);
return sendCommandRequest('sheet', {
country: country,