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 { addDays, format, isWeekend } from 'date-fns';
import { zhCN } from 'date-fns/locale';
import { executePricingQuery, executeSecondaryProcessQuery, executePricingDetailsQuery } from './services/apiService';
const { Title, Text } = Typography;
@ -1869,38 +1870,22 @@ export default function App() {
const executeQuery = async (packId: string, packType: string) => {
setQueryLoading(true);
try {
// 调用后端API
const response = await fetch('http://localhost:3001/api/query/pricing', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId, packType })
});
// 使用 apiService 中的函数
const data = await executePricingQuery(packId, packType, selectedLabels);
setQueryResults(data);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
setQueryResults(result.data);
// 处理品类属性填充到标签8
if (result.data && result.data.length > 0) {
// 收集所有匹配标签8选项的品类属性值
// 处理品类属性填充到标签8的逻辑保持不变
if (data && data.length > 0) {
const label8Options = labelOptions['标签8'] || [];
const matchingCategoryValues: string[] = [];
result.data.forEach((record: any) => {
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);
}
@ -1908,44 +1893,26 @@ export default function App() {
});
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) {
await bitable.ui.showToast({
toastType: 'success',
message: result.message
message: '查询成功'
});
}
} else {
throw new Error(result.message || '查询失败');
}
} catch (error: any) {
console.error('数据库查询出错:', error);
@ -1961,37 +1928,18 @@ export default function App() {
};
// 执行二次工艺查询
const executeSecondaryProcessQuery = async (packId: string, packType: string) => {
const executeSecondaryProcessQueryLocal = async (packId: string, packType: string) => {
setSecondaryProcessLoading(true);
try {
// 调用后端API
const response = await fetch('http://localhost:3001/api/query/secondary-process', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId, packType })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
setSecondaryProcessResults(result.data);
const data = await executeSecondaryProcessQuery(packId, packType);
setSecondaryProcessResults(data);
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: result.message
message: '二次工艺查询成功'
});
}
} else {
throw new Error(result.message || '二次工艺查询失败');
}
} catch (error: any) {
console.error('二次工艺查询出错:', error);
if (bitable.ui.showToast) {
@ -2006,37 +1954,18 @@ export default function App() {
};
// 执行定价详情查询
const executePricingDetailsQuery = async (packId: string) => {
const executePricingDetailsQueryLocal = async (packId: string) => {
setPricingDetailsLoading(true);
try {
// 调用后端API
const response = await fetch('http://localhost:3001/api/query/pricing-details', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ packId })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
setPricingDetailsResults(result.data);
const data = await executePricingDetailsQuery(packId);
setPricingDetailsResults(data);
if (bitable.ui.showToast) {
await bitable.ui.showToast({
toastType: 'success',
message: result.message
message: '定价详情查询成功'
});
}
} else {
throw new Error(result.message || '定价详情查询失败');
}
} catch (error: any) {
console.error('定价详情查询出错:', error);
if (bitable.ui.showToast) {
@ -2105,7 +2034,7 @@ export default function App() {
return;
}
await executeSecondaryProcessQuery(packId, packType);
await executeSecondaryProcessQueryLocal(packId, packType);
};
// 处理定价详情查询
@ -2128,7 +2057,7 @@ export default function App() {
return;
}
await executePricingDetailsQuery(packId);
await executePricingDetailsQueryLocal(packId);
};