iloom-flatten/.microcompact/mpo3ttpi/functions.Edit:40.txt

50 lines
1.9 KiB
Plaintext
Raw Normal View History

The file /home/project/src/components/warehouse/ProductForm.tsx has been updated. Made 1 replacement.
Here's the result of running `cat -n` on a snippet of the edited file:
246→ return `${prefix}1`;
247→ }
248→ };
249→
250→ // 从数据库查询已存在的最大色号数字,生成下一个
251→ const generateNextColorCode = async (
252→ companyId: string,
253→ productName: string,
254→ totalWeight: number | null
255→ ): Promise<string> => {
256→ try {
257→ // 查询该产品名称-克重组合下的所有色号(色号在产品名称-克重下连续递增)
258→ const { data, error } = await supabase
259→ .from('products')
260→ .select('color_code')
261→ .eq('company_id', companyId)
262→ .eq('product_name', productName)
263→ .eq('total_weight', totalWeight || 0);
264→
265→ if (error || !data || data.length === 0) {
266→ // 如果没有匹配的产品从01开始
267→ return '01';
268→ }
269→
270→ // 提取所有色号中的数字,找出最大值
271→ let maxNum = 0;
272→ data.forEach(item => {
273→ const code = item.color_code;
274→ const num = parseInt(code, 10);
275→ if (!isNaN(num) && num > maxNum) {
276→ maxNum = num;
277→ }
278→ });
279→
280→ // 返回最大数字 + 1保持两位数格式
281→ const nextNum = maxNum + 1;
282→ return nextNum < 10 ? `0${nextNum}` : String(nextNum);
283→ } catch (err) {
284→ console.error('生成色号失败:', err);
285→ return '01';
286→ }
287→ };
288→
289→ // 选择产品建议
290→ const selectProductSuggestion = async (suggestion: ProductSuggestion) => {
291→ // 获取该产品的纱线配比
292→ const ratios = productRatios[suggestion.id] || [];