|
|
|
|
@ -825,8 +825,27 @@ const prepareInventoryChartData = () => {
|
|
|
|
|
console.log('开始处理销售数据');
|
|
|
|
|
console.log('第一条销售数据示例:', salesData.value[0]);
|
|
|
|
|
|
|
|
|
|
const salesSeriesData = salesData.value.map((item, index) => {
|
|
|
|
|
console.log(`处理销售第${index}条数据:`, item);
|
|
|
|
|
// 按日期分组销售数据
|
|
|
|
|
const salesByDate = new Map();
|
|
|
|
|
salesData.value.forEach((item, index) => {
|
|
|
|
|
const timeField = item.date || item.create_time || item.createTime || item.time || item.timestamp;
|
|
|
|
|
if (timeField) {
|
|
|
|
|
const dateKey = new Date(timeField).toISOString().split('T')[0]; // YYYY-MM-DD格式
|
|
|
|
|
if (!salesByDate.has(dateKey)) {
|
|
|
|
|
salesByDate.set(dateKey, []);
|
|
|
|
|
}
|
|
|
|
|
salesByDate.get(dateKey).push(item);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const salesSeriesData = [];
|
|
|
|
|
|
|
|
|
|
// 处理每个日期的销售记录
|
|
|
|
|
salesByDate.forEach((items, dateKey) => {
|
|
|
|
|
console.log(`处理日期 ${dateKey} 的 ${items.length} 条销售记录`);
|
|
|
|
|
|
|
|
|
|
items.forEach((item, dayIndex) => {
|
|
|
|
|
console.log(`处理销售第${dayIndex + 1}条数据:`, item);
|
|
|
|
|
|
|
|
|
|
// 销售数据字段映射
|
|
|
|
|
const timeField = item.date || item.create_time || item.createTime || item.time || item.timestamp;
|
|
|
|
|
@ -840,11 +859,17 @@ const prepareInventoryChartData = () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!timeField) {
|
|
|
|
|
console.warn(`销售第${index}条数据缺少时间字段`);
|
|
|
|
|
return null;
|
|
|
|
|
console.warn(`销售第${dayIndex + 1}条数据缺少时间字段`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const time = new Date(timeField).getTime();
|
|
|
|
|
// 基础时间戳
|
|
|
|
|
const baseTime = new Date(timeField).getTime();
|
|
|
|
|
|
|
|
|
|
// 为同一天的多个记录分配不同的时间点(间隔30分钟)
|
|
|
|
|
const timeOffset = dayIndex * 30 * 60 * 1000; // 30分钟间隔
|
|
|
|
|
const adjustedTime = baseTime + timeOffset;
|
|
|
|
|
|
|
|
|
|
let value;
|
|
|
|
|
|
|
|
|
|
if (chartUnit.value === 'box') {
|
|
|
|
|
@ -853,15 +878,16 @@ const prepareInventoryChartData = () => {
|
|
|
|
|
value = weightField || 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`销售时间戳: ${time}, 值: ${value}`);
|
|
|
|
|
console.log(`销售时间戳: ${adjustedTime}, 值: ${value}`);
|
|
|
|
|
|
|
|
|
|
if (isNaN(time) || time <= 0) {
|
|
|
|
|
console.warn(`销售第${index}条数据时间格式无效:`, timeField);
|
|
|
|
|
return null;
|
|
|
|
|
if (isNaN(adjustedTime) || adjustedTime <= 0) {
|
|
|
|
|
console.warn(`销售第${dayIndex + 1}条数据时间格式无效:`, timeField);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [time, value];
|
|
|
|
|
}).filter(item => item !== null); // 过滤掉无效数据
|
|
|
|
|
salesSeriesData.push([adjustedTime, value]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log('销售转换后的图表数据:', salesSeriesData);
|
|
|
|
|
console.log('销售有效数据点数量:', salesSeriesData.length);
|
|
|
|
|
|