|
|
@@ -42,6 +42,7 @@ import {
|
|
|
getWorkStatusLabel,
|
|
|
} from "@d8d/allin-enums";
|
|
|
import { orderClientManager } from "../api/orderClient";
|
|
|
+import { salaryClientManager } from "@d8d/allin-salary-management-ui";
|
|
|
import { DisabledPersonSelector } from "@d8d/allin-disability-person-management-ui";
|
|
|
import OrderPersonAssetAssociation from "./OrderPersonAssetAssociation";
|
|
|
import type { DisabledPersonData } from "@d8d/allin-disability-person-management-ui";
|
|
|
@@ -72,10 +73,13 @@ interface OrderPerson {
|
|
|
leaveDate?: string;
|
|
|
workStatus?: number;
|
|
|
salaryDetail?: number;
|
|
|
- personName?: string;
|
|
|
- gender?: string;
|
|
|
- disabilityType?: string;
|
|
|
- phone?: string;
|
|
|
+ person?: {
|
|
|
+ id: number;
|
|
|
+ name: string;
|
|
|
+ gender: string;
|
|
|
+ disabilityType: string;
|
|
|
+ phone: string;
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
@@ -120,10 +124,13 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
// 暂时使用基本信息
|
|
|
const personsWithDetails = order.orderPersons.map(person => ({
|
|
|
...person,
|
|
|
- personName: `人员${person.personId}`, // 实际应该从API获取姓名
|
|
|
- gender: '未知', // 实际应该从API获取
|
|
|
- disabilityType: '未知', // 实际应该从API获取
|
|
|
- phone: '未知', // 实际应该从API获取
|
|
|
+ person: {
|
|
|
+ id: person.personId,
|
|
|
+ name: `人员${person.personId}`, // 实际应该从API获取姓名
|
|
|
+ gender: '未知', // 实际应该从API获取
|
|
|
+ disabilityType: '未知', // 实际应该从API获取
|
|
|
+ phone: '未知', // 实际应该从API获取
|
|
|
+ }
|
|
|
}));
|
|
|
setOrderPersons(personsWithDetails);
|
|
|
} else {
|
|
|
@@ -241,32 +248,55 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
|
|
|
// 模拟薪资查询功能(根据省、市信息查询默认薪资)
|
|
|
// 支持字符串(原系统格式)和数字ID两种格式
|
|
|
- const getSalaryByLocation = (province?: string | number, city?: string | number): number => {
|
|
|
- // 模拟逻辑:根据地区返回默认薪资
|
|
|
- // 实际应该调用API查询薪资配置
|
|
|
-
|
|
|
- // 处理字符串格式(原系统使用汉字)
|
|
|
- if (typeof province === 'string') {
|
|
|
- if (province === "北京" || province === "上海" || province === "广州" || province === "深圳") {
|
|
|
- return 8000;
|
|
|
- }
|
|
|
- if (province === "江苏" || province === "浙江" || province === "广东") {
|
|
|
- return 6000;
|
|
|
+ const getSalaryByLocation = async (province?: string | number, city?: string | number): Promise<number> => {
|
|
|
+ try {
|
|
|
+ // 获取薪资客户端
|
|
|
+ const salaryClient = salaryClientManager.get();
|
|
|
+
|
|
|
+ // 如果province是字符串(汉字),需要转换为ID
|
|
|
+ // 这里简化处理,实际应该调用地区服务查询ID
|
|
|
+ let provinceId: number | undefined;
|
|
|
+ let cityId: number | undefined;
|
|
|
+
|
|
|
+ if (typeof province === 'string') {
|
|
|
+ // 简单映射:北京->1, 上海->2, 广州->3, 深圳->4
|
|
|
+ const provinceMap: Record<string, number> = {
|
|
|
+ '北京': 1, '上海': 2, '广州': 3, '深圳': 4,
|
|
|
+ '江苏': 5, '浙江': 6, '广东': 7
|
|
|
+ };
|
|
|
+ provinceId = provinceMap[province];
|
|
|
+ } else if (typeof province === 'number') {
|
|
|
+ provinceId = province;
|
|
|
}
|
|
|
- return 5000;
|
|
|
- }
|
|
|
|
|
|
- // 处理数字ID格式
|
|
|
- if (typeof province === 'number') {
|
|
|
- if (province === 1 || province === 2 || province === 3 || province === 4) {
|
|
|
- return 8000; // 一线城市
|
|
|
+ if (typeof city === 'string') {
|
|
|
+ // 简单映射:北京市->2, 上海市->2, 广州市->3, 深圳市->4
|
|
|
+ const cityMap: Record<string, number> = {
|
|
|
+ '北京市': 2, '上海市': 2, '广州市': 3, '深圳市': 4
|
|
|
+ };
|
|
|
+ cityId = cityMap[city];
|
|
|
+ } else if (typeof city === 'number') {
|
|
|
+ cityId = city;
|
|
|
}
|
|
|
- if (province === 5 || province === 6 || province === 7) {
|
|
|
- return 6000; // 二线城市
|
|
|
+
|
|
|
+ // 如果有省份ID和城市ID,调用API查询薪资
|
|
|
+ if (provinceId && cityId) {
|
|
|
+ const response = await salaryClient.byProvinceCity.$get({
|
|
|
+ query: { provinceId, cityId }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ const salaryData = await response.json();
|
|
|
+ return salaryData.salary || 5000; // 返回查询到的薪资
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return 5000; // 默认薪资
|
|
|
+ // API调用失败或没有ID,使用默认值
|
|
|
+ return 5000;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('查询薪资失败:', error);
|
|
|
+ return 5000; // 出错时返回默认值
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// 处理添加人员
|
|
|
@@ -276,8 +306,8 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
};
|
|
|
|
|
|
// 处理残疾人选择 - 将选择的人员添加到待添加列表
|
|
|
- const handlePersonSelect = (persons: DisabledPersonData | DisabledPersonData[]) => {
|
|
|
- console.log('OrderDetailModal: handlePersonSelect被调用,人员数据:', persons);
|
|
|
+ const handlePersonSelect = async (persons: DisabledPersonData | DisabledPersonData[]) => {
|
|
|
+ console.log('OrderDetailModal: handlePersonSelect开始执行,人员数据:', persons);
|
|
|
const personsArray = Array.isArray(persons) ? persons : [persons];
|
|
|
|
|
|
// 获取已绑定人员的ID列表
|
|
|
@@ -287,18 +317,19 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
|
|
|
const newPendingPersons: PendingPerson[] = [];
|
|
|
|
|
|
- personsArray.forEach(person => {
|
|
|
+ // 使用Promise.all并行查询所有人员的薪资
|
|
|
+ const salaryPromises = personsArray.map(async person => {
|
|
|
// 检查是否已在订单中或已在待添加列表中
|
|
|
if (existingPersonIds.includes(person.id) || pendingPersonIds.includes(person.id)) {
|
|
|
- toast.warning(`人员 ${person.name} 已存在,跳过添加`);
|
|
|
- return;
|
|
|
+ // toast.warning(`人员 ${person.name} 已存在,跳过添加`);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
// 根据省、市信息查询默认薪资
|
|
|
// 注意:原系统使用字符串存储省市信息
|
|
|
- const defaultSalary = getSalaryByLocation(person.province, person.city);
|
|
|
+ const defaultSalary = await getSalaryByLocation(person.province, person.city);
|
|
|
|
|
|
- newPendingPersons.push({
|
|
|
+ return {
|
|
|
personId: person.id,
|
|
|
name: person.name,
|
|
|
gender: person.gender,
|
|
|
@@ -307,20 +338,27 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
salaryDetail: defaultSalary,
|
|
|
province: person.province,
|
|
|
city: person.city,
|
|
|
- });
|
|
|
+ };
|
|
|
});
|
|
|
|
|
|
- if (newPendingPersons.length > 0) {
|
|
|
- console.log('OrderDetailModal: 设置pendingPersons,新人员:', newPendingPersons);
|
|
|
+ // 等待所有薪资查询完成
|
|
|
+ const pendingPersonResults = await Promise.all(salaryPromises);
|
|
|
+
|
|
|
+ // 过滤掉null(已存在的人员)
|
|
|
+ const validPendingPersons = pendingPersonResults.filter((p): p is PendingPerson => p !== null);
|
|
|
+
|
|
|
+ if (validPendingPersons.length > 0) {
|
|
|
+ console.log('OrderDetailModal: 设置pendingPersons,新人员:', validPendingPersons);
|
|
|
setPendingPersons(prev => {
|
|
|
- const newState = [...prev, ...newPendingPersons];
|
|
|
+ const newState = [...prev, ...validPendingPersons];
|
|
|
console.log('OrderDetailModal: pendingPersons新状态:', newState);
|
|
|
return newState;
|
|
|
});
|
|
|
- toast.success(`已添加 ${newPendingPersons.length} 名人员到待添加列表`);
|
|
|
+ toast.success(`已添加 ${validPendingPersons.length} 名人员到待添加列表`);
|
|
|
} else {
|
|
|
console.log('OrderDetailModal: 没有新人员可添加');
|
|
|
}
|
|
|
+ console.log('OrderDetailModal: handlePersonSelect执行完成');
|
|
|
};
|
|
|
|
|
|
// 处理添加资产
|
|
|
@@ -426,10 +464,10 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
// 人员列表表格列
|
|
|
const personColumns = [
|
|
|
{ key: "personId", label: "ID", width: "60px" },
|
|
|
- { key: "personName", label: "姓名" },
|
|
|
- { key: "gender", label: "性别", width: "80px" },
|
|
|
- { key: "disabilityType", label: "残疾类型" },
|
|
|
- { key: "phone", label: "联系电话" },
|
|
|
+ { key: "person.name", label: "姓名" },
|
|
|
+ { key: "person.gender", label: "性别", width: "80px" },
|
|
|
+ { key: "person.disabilityType", label: "残疾类型" },
|
|
|
+ { key: "person.phone", label: "联系电话" },
|
|
|
{ key: "joinDate", label: "入职日期", width: "120px" },
|
|
|
{ key: "leaveDate", label: "离职日期", width: "120px" },
|
|
|
{ key: "workStatus", label: "工作状态", width: "120px" },
|
|
|
@@ -563,6 +601,10 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
</Card>
|
|
|
|
|
|
{/* 待添加人员列表 */}
|
|
|
+ <div data-testid="pending-persons-debug" style={{ display: 'none' }}>
|
|
|
+ {JSON.stringify({ length: pendingPersons.length, persons: pendingPersons })}
|
|
|
+ </div>
|
|
|
+ {console.log('OrderDetailModal: 条件渲染前,pendingPersons.length:', pendingPersons.length) || true}
|
|
|
{pendingPersons.length > 0 ? (
|
|
|
<Card data-testid="pending-persons-card">
|
|
|
<CardHeader>
|
|
|
@@ -685,10 +727,10 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
data-testid={`order-detail-person-${person.personId}`}
|
|
|
>
|
|
|
<TableCell>{person.personId}</TableCell>
|
|
|
- <TableCell>{person.personName}</TableCell>
|
|
|
- <TableCell>{person.gender}</TableCell>
|
|
|
- <TableCell>{person.disabilityType}</TableCell>
|
|
|
- <TableCell>{person.phone}</TableCell>
|
|
|
+ <TableCell>{person.person?.name || `人员${person.personId}`}</TableCell>
|
|
|
+ <TableCell>{person.person?.gender || '未知'}</TableCell>
|
|
|
+ <TableCell>{person.person?.disabilityType || '未知'}</TableCell>
|
|
|
+ <TableCell>{person.person?.phone || '未知'}</TableCell>
|
|
|
<TableCell>
|
|
|
{formatDate(person.joinDate)}
|
|
|
</TableCell>
|
|
|
@@ -843,6 +885,12 @@ const OrderDetailModal: React.FC<OrderDetailModalProps> = ({
|
|
|
}}
|
|
|
/>
|
|
|
)}
|
|
|
+
|
|
|
+ {/* 监控pendingPersons变化 */}
|
|
|
+ {(() => {
|
|
|
+ console.log('OrderDetailModal: 组件渲染,pendingPersons长度:', pendingPersons.length);
|
|
|
+ return null;
|
|
|
+ })()}
|
|
|
</>
|
|
|
);
|
|
|
};
|