All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m56s
官网换 GradientWaves/TextType 并做性能减负;模块指南拆开发/运营;含营销指南、轨迹单与 H5 价格等改动。 Co-authored-by: Cursor <cursoragent@cursor.com>
162 lines
6.7 KiB
TypeScript
162 lines
6.7 KiB
TypeScript
import { ref, computed } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { $baseMessage } from '@/utils';
|
||
import { postGetTrackOrderList } from '@/api/TrackOrder/trackOrder';
|
||
import { convertToTime } from '../utils';
|
||
import { toServerSearchValue } from '@/components/HandsontablePro/filterValue';
|
||
import { adaptTrackOrderDateRange } from '@/utils/headerFilterAdapter';
|
||
import {
|
||
MAX_HEADER_BATCH_VALUES,
|
||
clampBatchValues,
|
||
} from '@/utils/headerFilterLimits';
|
||
|
||
export function useTrackOrderData(options: {
|
||
userStore: any;
|
||
searchInfo: any;
|
||
searchParams: any;
|
||
activeTab: any;
|
||
}) {
|
||
const { t } = useI18n();
|
||
const { userStore, searchInfo, searchParams, activeTab } = options;
|
||
|
||
const tableData = ref<any[]>([]);
|
||
const totalCount = ref(0);
|
||
const currentPage = ref(1);
|
||
const pageSize = ref(50);
|
||
const loading = ref(false);
|
||
|
||
// 加载表格数据
|
||
async function loadTableData() {
|
||
try {
|
||
loading.value = true;
|
||
|
||
// 根据当前 activeTab 确定 trackOrderType(完全由 tab 决定)
|
||
let trackOrderType: number;
|
||
if (activeTab.value === 'small') {
|
||
trackOrderType = 1;
|
||
} else if (activeTab.value === 'package') {
|
||
trackOrderType = 2;
|
||
} else {
|
||
trackOrderType = 4;
|
||
}
|
||
|
||
// 合并searchInfo和searchParams,优先使用searchParams中的值
|
||
// 处理客户单号:如果是逗号分隔的字符串,转换为数组
|
||
let orderNos: string[] = [];
|
||
const orderNumberPlain = toServerSearchValue(searchParams.orderNumber || '');
|
||
if (orderNumberPlain) {
|
||
const { values, truncated, originalCount } = clampBatchValues(
|
||
orderNumberPlain.split(',').map((v: string) => v.trim()).filter(Boolean),
|
||
);
|
||
orderNos = values;
|
||
if (truncated) {
|
||
$baseMessage(
|
||
`单号最多 ${MAX_HEADER_BATCH_VALUES} 个,已保留前 ${values.length} 个(原 ${originalCount} 个)`,
|
||
'warning',
|
||
);
|
||
}
|
||
} else if ((searchInfo as any).orderNos && Array.isArray((searchInfo as any).orderNos)) {
|
||
const { values, truncated, originalCount } = clampBatchValues(
|
||
(searchInfo as any).orderNos.map(String),
|
||
);
|
||
orderNos = values;
|
||
if (truncated) {
|
||
$baseMessage(
|
||
`单号最多 ${MAX_HEADER_BATCH_VALUES} 个,已保留前 ${values.length} 个(原 ${originalCount} 个)`,
|
||
'warning',
|
||
);
|
||
}
|
||
}
|
||
|
||
const dateRange = adaptTrackOrderDateRange(searchParams, {
|
||
createTimeStart: (searchInfo as any).createTimeStart || '',
|
||
createTimeEnd: (searchInfo as any).createTimeEnd || '',
|
||
});
|
||
|
||
const newestTrackTimeZoneRaw = toServerSearchValue(searchParams.newestTrackTimeZone || '');
|
||
const destinationTimeZoneRaw = toServerSearchValue(searchParams.destinationTimeZone || '');
|
||
const newestTrackTimeZone = newestTrackTimeZoneRaw !== '' && !Number.isNaN(Number(newestTrackTimeZoneRaw))
|
||
? Number(newestTrackTimeZoneRaw)
|
||
: undefined;
|
||
const destinationTimeZone = destinationTimeZoneRaw !== '' && !Number.isNaN(Number(destinationTimeZoneRaw))
|
||
? Number(destinationTimeZoneRaw)
|
||
: undefined;
|
||
|
||
let isFinish: boolean | undefined;
|
||
if (searchParams.isFinish === true || searchParams.isFinish === 'true') isFinish = true;
|
||
else if (searchParams.isFinish === false || searchParams.isFinish === 'false') isFinish = false;
|
||
|
||
const requestParams: any = {
|
||
pageIndex: currentPage.value - 1,
|
||
pageSize: pageSize.value,
|
||
appKey: userStore.appKey,
|
||
// 优先使用表头搜索的客户单号(已转换为数组),否则使用表单的客户单号
|
||
orderNos: orderNos,
|
||
trackOrderType: trackOrderType,
|
||
customer: toServerSearchValue(searchParams.customer || ''),
|
||
// 表头筛选字段(尾程/其他单号支持逗号分隔多值)
|
||
trackNo: toServerSearchValue(searchParams.trackNo || ''),
|
||
otherNo: toServerSearchValue(searchParams.otherNo || ''),
|
||
product: toServerSearchValue(searchParams.product || ''),
|
||
channel: toServerSearchValue(searchParams.channel || ''),
|
||
apiCode: toServerSearchValue(searchParams.apiCode || ''),
|
||
countryCode: toServerSearchValue(searchParams.countryCode || ''),
|
||
province: toServerSearchValue(searchParams.province || ''),
|
||
city: toServerSearchValue(searchParams.city || ''),
|
||
postcode: toServerSearchValue(searchParams.postcode || ''),
|
||
email: toServerSearchValue(searchParams.email || ''),
|
||
newestTrackStatus: toServerSearchValue(searchParams.newestTrackStatus || ''),
|
||
newestTrackContent: toServerSearchValue(searchParams.newestTrackContent || ''),
|
||
newestTrackEnContent: toServerSearchValue(searchParams.newestTrackEnContent || ''),
|
||
newestTrackPlace: toServerSearchValue(searchParams.newestTrackPlace || ''),
|
||
newestTrackTimeStart: dateRange.newestTrackTimeStart || '',
|
||
newestTrackTimeEnd: dateRange.newestTrackTimeEnd || '',
|
||
newestTrackTimeZone,
|
||
isFinish,
|
||
estimatedDeliveryDateStart: dateRange.estimatedDeliveryDateStart || '',
|
||
estimatedDeliveryDateEnd: dateRange.estimatedDeliveryDateEnd || '',
|
||
destinationTimeZone,
|
||
createTimeStart: dateRange.createTimeStart || '',
|
||
createTimeEnd: dateRange.createTimeEnd || '',
|
||
};
|
||
|
||
const response: any = await postGetTrackOrderList(requestParams as API.GetPageTrackOrderInput);
|
||
|
||
// 更新分页总数和数据
|
||
const result = response?.data || response;
|
||
// 确保 totalCount 是数字类型
|
||
totalCount.value = Number(result?.totalCount) || 0;
|
||
tableData.value = result?.items || [];
|
||
|
||
// 数据已更新,HandsontablePro 组件会自动响应
|
||
} catch (error) {
|
||
$baseMessage('加载数据失败', 'error');
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
// 处理数据映射(时区转换,isFinish 不转换,因为 customCellRenderer 需要原始值)
|
||
const processedTableData = computed(() => {
|
||
return tableData.value.map((row) => ({
|
||
...row,
|
||
newestTrackTimeZone: row.newestTrackTimeZone !== undefined && row.newestTrackTimeZone !== null
|
||
? (row.newestTrackTimeZone === 0 ? convertToTime(row.newestTrackTimeZone) : convertToTime(row.newestTrackTimeZone))
|
||
: '--',
|
||
destinationTimeZone: row.destinationTimeZone !== undefined && row.destinationTimeZone !== null
|
||
? (row.destinationTimeZone === 0 ? convertToTime(row.destinationTimeZone) : convertToTime(row.destinationTimeZone))
|
||
: '--',
|
||
}));
|
||
});
|
||
|
||
return {
|
||
tableData,
|
||
totalCount,
|
||
currentPage,
|
||
pageSize,
|
||
loading,
|
||
loadTableData,
|
||
processedTableData,
|
||
};
|
||
}
|