✨ 完善配载确认、承运商组织过滤司机与地址展示
配载草稿确认生成正式单并优化详情/列表地址市区展示;运单调度等按承运商联系人所属组织筛选司机车辆;统一地图搜索结果与登录默认账号清理。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
import { getDetail, getList as getCustomerList } from '@/api/vehicle/customer-archive';
|
||||
import { getList as getDriverList } from '@/api/transportCapacity/driver';
|
||||
import { getList as getVehicleList } from '@/api/transportCapacity/transport-vehicle';
|
||||
|
||||
const orgNameCache = new Map();
|
||||
|
||||
const extractRecords = res => {
|
||||
const data = res?.data?.data ?? res?.data ?? res;
|
||||
if (Array.isArray(data)) return data;
|
||||
if (Array.isArray(data?.records)) return data.records;
|
||||
if (Array.isArray(data?.data)) return data.data;
|
||||
return [];
|
||||
};
|
||||
|
||||
const normalizeOrgName = value => String(value || '').trim();
|
||||
|
||||
const uniqueOrgNames = (values = []) => {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
values.forEach(value => {
|
||||
const name = normalizeOrgName(value);
|
||||
if (!name || seen.has(name)) return;
|
||||
seen.add(name);
|
||||
result.push(name);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析承运商客商档案上联系人的所属组织(branchName),无联系人时回退客商所属组织。
|
||||
*/
|
||||
export const resolveCarrierOrganizationNames = async ({ carrierId, carrierName } = {}) => {
|
||||
const id = String(carrierId || '').trim();
|
||||
const name = normalizeOrgName(carrierName);
|
||||
const cacheKey = id || name;
|
||||
if (!cacheKey) return [];
|
||||
if (orgNameCache.has(cacheKey)) return orgNameCache.get(cacheKey);
|
||||
|
||||
let detail = null;
|
||||
if (id) {
|
||||
try {
|
||||
const res = await getDetail(id);
|
||||
detail = res?.data?.data || res?.data || null;
|
||||
} catch (error) {
|
||||
detail = null;
|
||||
}
|
||||
}
|
||||
if (!detail && name) {
|
||||
try {
|
||||
const res = await getCustomerList(1, 20, { fullName: name });
|
||||
const records = extractRecords(res);
|
||||
const matched =
|
||||
records.find(item => normalizeOrgName(item.fullName || item.customerName) === name) ||
|
||||
records[0];
|
||||
if (matched?.id) {
|
||||
const detailRes = await getDetail(matched.id);
|
||||
detail = detailRes?.data?.data || detailRes?.data || matched;
|
||||
}
|
||||
} catch (error) {
|
||||
detail = null;
|
||||
}
|
||||
}
|
||||
|
||||
const contacts = Array.isArray(detail?.contacts) ? detail.contacts : [];
|
||||
const orgNames = uniqueOrgNames([
|
||||
...contacts.map(item => item.branchName),
|
||||
detail?.deptName,
|
||||
detail?.organizationName,
|
||||
]);
|
||||
orgNameCache.set(cacheKey, orgNames);
|
||||
if (id && name) orgNameCache.set(name, orgNames);
|
||||
return orgNames;
|
||||
};
|
||||
|
||||
export const clearCarrierOrganizationCache = (carrier = {}) => {
|
||||
const id = String(carrier.carrierId || '').trim();
|
||||
const name = normalizeOrgName(carrier.carrierName);
|
||||
if (id) orgNameCache.delete(id);
|
||||
if (name) orgNameCache.delete(name);
|
||||
};
|
||||
|
||||
export const matchOrganizationName = (value, orgNames = []) => {
|
||||
const text = normalizeOrgName(value);
|
||||
if (!text || !orgNames.length) return false;
|
||||
return orgNames.some(org => text === org || text.includes(org) || org.includes(text));
|
||||
};
|
||||
|
||||
const filterByOrganizations = (records = [], orgNames = []) => {
|
||||
if (!orgNames.length) return [];
|
||||
return records.filter(item => matchOrganizationName(item.organizationName, orgNames));
|
||||
};
|
||||
|
||||
/**
|
||||
* 按承运商联系人所属组织筛选司机。
|
||||
* 未选择承运商时返回空列表(需先选承运商)。
|
||||
*/
|
||||
export const fetchDriversByCarrierOrganizations = async (
|
||||
query = {},
|
||||
{ carrierId, carrierName } = {}
|
||||
) => {
|
||||
if (!String(carrierId || '').trim() && !normalizeOrgName(carrierName)) {
|
||||
return [];
|
||||
}
|
||||
const orgNames = await resolveCarrierOrganizationNames({ carrierId, carrierName });
|
||||
if (!orgNames.length) return [];
|
||||
|
||||
const size = Math.max(Number(query.size) || 50, 50);
|
||||
const params = { ...query };
|
||||
delete params.size;
|
||||
// 单组织时用后端模糊条件缩小范围;多组织再前端精确过滤
|
||||
if (orgNames.length === 1) {
|
||||
params.organizationName = orgNames[0];
|
||||
}
|
||||
const res = await getDriverList(1, Math.min(size * 5, 200), params);
|
||||
return filterByOrganizations(extractRecords(res), orgNames).slice(0, size);
|
||||
};
|
||||
|
||||
/**
|
||||
* 按承运商联系人所属组织筛选车辆。
|
||||
* 未选择承运商时返回空列表。
|
||||
*/
|
||||
export const fetchVehiclesByCarrierOrganizations = async (
|
||||
query = {},
|
||||
{ carrierId, carrierName } = {}
|
||||
) => {
|
||||
if (!String(carrierId || '').trim() && !normalizeOrgName(carrierName)) {
|
||||
return [];
|
||||
}
|
||||
const orgNames = await resolveCarrierOrganizationNames({ carrierId, carrierName });
|
||||
if (!orgNames.length) return [];
|
||||
|
||||
const size = Math.max(Number(query.size) || 50, 50);
|
||||
const params = { ...query };
|
||||
delete params.size;
|
||||
if (orgNames.length === 1) {
|
||||
params.organizationName = orgNames[0];
|
||||
}
|
||||
const res = await getVehicleList(1, Math.min(size * 5, 200), params);
|
||||
return filterByOrganizations(extractRecords(res), orgNames).slice(0, size);
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 将高德 Geocoder 结果规范化为地图选址浮层列表数据。
|
||||
* @param {Array|Object} geocodesOrResult geocodes 数组,或含 geocodes/location 的结果对象
|
||||
* @param {string} keyword 搜索关键词兜底文案
|
||||
* @returns {Array<{id: string|number, name: string, address: string, location: any, photo: string}>}
|
||||
*/
|
||||
export function normalizeMapSearchResults(geocodesOrResult, keyword = '') {
|
||||
const fallback = String(keyword || '').trim();
|
||||
let list = [];
|
||||
if (Array.isArray(geocodesOrResult)) {
|
||||
list = geocodesOrResult;
|
||||
} else if (geocodesOrResult && typeof geocodesOrResult === 'object') {
|
||||
if (Array.isArray(geocodesOrResult.geocodes)) {
|
||||
list = geocodesOrResult.geocodes;
|
||||
} else if (geocodesOrResult.location) {
|
||||
list = [geocodesOrResult];
|
||||
}
|
||||
}
|
||||
|
||||
return list.map((item, index) => {
|
||||
const buildingName = pickNamedField(item?.building);
|
||||
const neighborhoodName = pickNamedField(item?.neighborhood);
|
||||
const address = item?.formattedAddress || item?.address || fallback || '-';
|
||||
return {
|
||||
id: item?.id || index,
|
||||
name: buildingName || neighborhoodName || address,
|
||||
address,
|
||||
location: item?.location,
|
||||
photo: item?.photo || item?.image || '',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function pickNamedField(value) {
|
||||
if (!value) return '';
|
||||
if (typeof value === 'string') return value.trim();
|
||||
if (typeof value === 'object' && value.name) return String(value.name).trim();
|
||||
return '';
|
||||
}
|
||||
Reference in New Issue
Block a user