1
This commit is contained in:
2025-10-22 16:19:28 +08:00
parent b0fab6bdde
commit afdd41d6a3

View File

@ -3,6 +3,7 @@ import { Button, Typography, List, Card, Space, Divider, Spin, Table, Select, Mo
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { addDays, format, isWeekend } from 'date-fns'; import { addDays, format, isWeekend } from 'date-fns';
import { zhCN } from 'date-fns/locale'; import { zhCN } from 'date-fns/locale';
import { executePricingQuery, executeSecondaryProcessQuery, executePricingDetailsQuery } from './services/apiService';
const { Title, Text } = Typography; const { Title, Text } = Typography;
@ -1869,82 +1870,48 @@ export default function App() {
const executeQuery = async (packId: string, packType: string) => { const executeQuery = async (packId: string, packType: string) => {
setQueryLoading(true); setQueryLoading(true);
try { try {
// 调用后端API // 使用 apiService 中的函数
const response = await fetch('http://localhost:3001/api/query/pricing', { const data = await executePricingQuery(packId, packType, selectedLabels);
method: 'POST', setQueryResults(data);
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId, packType })
});
if (!response.ok) { // 处理品类属性填充到标签8的逻辑保持不变
throw new Error(`HTTP error! status: ${response.status}`); if (data && data.length > 0) {
} const label8Options = labelOptions['标签8'] || [];
const matchingCategoryValues: string[] = [];
const result = await response.json(); data.forEach((record: any) => {
if (record. && record..trim() !== '') {
const categoryValue = record..trim();
const matchingOption = label8Options.find(option =>
option.value === categoryValue || option.label === categoryValue
);
if (result.success) { if (matchingOption && !matchingCategoryValues.includes(categoryValue)) {
setQueryResults(result.data); matchingCategoryValues.push(categoryValue);
// 处理品类属性填充到标签8
if (result.data && result.data.length > 0) {
// 收集所有匹配标签8选项的品类属性值
const label8Options = labelOptions['标签8'] || [];
const matchingCategoryValues: string[] = [];
result.data.forEach((record: any) => {
if (record. && record..trim() !== '') {
const categoryValue = record..trim();
const matchingOption = label8Options.find(option =>
option.value === categoryValue || option.label === categoryValue
);
// 如果找到匹配且不重复,则添加到数组中
if (matchingOption && !matchingCategoryValues.includes(categoryValue)) {
matchingCategoryValues.push(categoryValue);
}
}
});
if (matchingCategoryValues.length > 0) {
console.log('找到匹配的品类属性值:', matchingCategoryValues);
console.log('标签8的选项:', labelOptions['标签8']);
// 填充到标签8多选
setSelectedLabels(prev => ({
...prev,
'标签8': matchingCategoryValues
}));
console.log('已将品类属性填充到标签8:', matchingCategoryValues);
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: `已将 ${matchingCategoryValues.length} 个品类属性填充到标签8: ${matchingCategoryValues.join(', ')}`
});
}
} else {
console.log('所有品类属性值都不在标签8选项中');
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'info',
message: '查询结果中的品类属性值都不在标签8预设选项中未自动填充'
});
} }
} }
} });
if (bitable.ui.showToast) { if (matchingCategoryValues.length > 0) {
await bitable.ui.showToast({ setSelectedLabels(prev => ({
toastType: 'success', ...prev,
message: result.message '标签8': matchingCategoryValues
}); }));
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: `已将 ${matchingCategoryValues.length} 个品类属性填充到标签8: ${matchingCategoryValues.join(', ')}`
});
}
} }
} else { }
throw new Error(result.message || '查询失败');
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: '查询成功'
});
} }
} catch (error: any) { } catch (error: any) {
@ -1961,37 +1928,18 @@ export default function App() {
}; };
// 执行二次工艺查询 // 执行二次工艺查询
const executeSecondaryProcessQuery = async (packId: string, packType: string) => { const executeSecondaryProcessQueryLocal = async (packId: string, packType: string) => {
setSecondaryProcessLoading(true); setSecondaryProcessLoading(true);
try { try {
// 调用后端API const data = await executeSecondaryProcessQuery(packId, packType);
const response = await fetch('http://localhost:3001/api/query/secondary-process', { setSecondaryProcessResults(data);
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId, packType })
});
if (!response.ok) { if (bitable.ui.showToast) {
throw new Error(`HTTP error! status: ${response.status}`); await bitable.ui.showToast({
toastType: 'success',
message: '二次工艺查询成功'
});
} }
const result = await response.json();
if (result.success) {
setSecondaryProcessResults(result.data);
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: result.message
});
}
} else {
throw new Error(result.message || '二次工艺查询失败');
}
} catch (error: any) { } catch (error: any) {
console.error('二次工艺查询出错:', error); console.error('二次工艺查询出错:', error);
if (bitable.ui.showToast) { if (bitable.ui.showToast) {
@ -2006,37 +1954,18 @@ export default function App() {
}; };
// 执行定价详情查询 // 执行定价详情查询
const executePricingDetailsQuery = async (packId: string) => { const executePricingDetailsQueryLocal = async (packId: string) => {
setPricingDetailsLoading(true); setPricingDetailsLoading(true);
try { try {
// 调用后端API const data = await executePricingDetailsQuery(packId);
const response = await fetch('http://localhost:3001/api/query/pricing-details', { setPricingDetailsResults(data);
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId })
});
if (!response.ok) { if (bitable.ui.showToast) {
throw new Error(`HTTP error! status: ${response.status}`); await bitable.ui.showToast({
toastType: 'success',
message: '定价详情查询成功'
});
} }
const result = await response.json();
if (result.success) {
setPricingDetailsResults(result.data);
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: result.message
});
}
} else {
throw new Error(result.message || '定价详情查询失败');
}
} catch (error: any) { } catch (error: any) {
console.error('定价详情查询出错:', error); console.error('定价详情查询出错:', error);
if (bitable.ui.showToast) { if (bitable.ui.showToast) {
@ -2105,7 +2034,7 @@ export default function App() {
return; return;
} }
await executeSecondaryProcessQuery(packId, packType); await executeSecondaryProcessQueryLocal(packId, packType);
}; };
// 处理定价详情查询 // 处理定价详情查询
@ -2128,7 +2057,7 @@ export default function App() {
return; return;
} }
await executePricingDetailsQuery(packId); await executePricingDetailsQueryLocal(packId);
}; };