更新 src/App.tsx
This commit is contained in:
155
src/App.tsx
155
src/App.tsx
@ -232,6 +232,10 @@ export default function App() {
|
|||||||
const [batchCurrentRowInfo, setBatchCurrentRowInfo] = useState<{ index: number; foreignId: string; style: string; color: string } | null>(null);
|
const [batchCurrentRowInfo, setBatchCurrentRowInfo] = useState<{ index: number; foreignId: string; style: string; color: string } | null>(null);
|
||||||
const batchAbortRef = useRef<boolean>(false);
|
const batchAbortRef = useRef<boolean>(false);
|
||||||
const lastBufferDeficitRef = useRef<number>(0);
|
const lastBufferDeficitRef = useRef<number>(0);
|
||||||
|
const [omsVersionModalVisible, setOmsVersionModalVisible] = useState(false);
|
||||||
|
const [omsVersionLoading, setOmsVersionLoading] = useState(false);
|
||||||
|
const [omsVersionList, setOmsVersionList] = useState<any[]>([]);
|
||||||
|
const [omsPlanText, setOmsPlanText] = useState<string>('');
|
||||||
// 删除未使用的 deliveryRecords 状态
|
// 删除未使用的 deliveryRecords 状态
|
||||||
const [selectedDeliveryRecordId, setSelectedDeliveryRecordId] = useState<string>('');
|
const [selectedDeliveryRecordId, setSelectedDeliveryRecordId] = useState<string>('');
|
||||||
// 从货期记录读取到的record_ids(用于保存回写)
|
// 从货期记录读取到的record_ids(用于保存回写)
|
||||||
@ -2439,6 +2443,85 @@ export default function App() {
|
|||||||
return text ? text : null;
|
return text ? text : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractUserNames = (val: any): string => {
|
||||||
|
if (!val) return '';
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
const names = val.map(item => {
|
||||||
|
if (!item) return '';
|
||||||
|
if (typeof item === 'string') return item.trim();
|
||||||
|
if (typeof item === 'object') {
|
||||||
|
const name = item.name || item.text || item.value || item.id || '';
|
||||||
|
return String(name || '').trim();
|
||||||
|
}
|
||||||
|
return String(item).trim();
|
||||||
|
}).filter(Boolean);
|
||||||
|
return names.join(',');
|
||||||
|
}
|
||||||
|
if (typeof val === 'string') return val.trim();
|
||||||
|
if (typeof val === 'object') {
|
||||||
|
const name = (val as any).name || (val as any).text || (val as any).value || (val as any).id;
|
||||||
|
return name ? String(name).trim() : '';
|
||||||
|
}
|
||||||
|
return String(val || '').trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseTimestampFromField = (val: any): number | null => {
|
||||||
|
if (typeof val === 'number' && Number.isFinite(val)) return val;
|
||||||
|
if (Array.isArray(val) && val.length > 0 && typeof val[0] === 'number') return val[0];
|
||||||
|
const raw = extractText(val);
|
||||||
|
if (!raw) return null;
|
||||||
|
const parsed = new Date(raw);
|
||||||
|
if (!isNaN(parsed.getTime())) return parsed.getTime();
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseVersionLabel = (raw: any): string => {
|
||||||
|
if (typeof raw === 'number' && Number.isFinite(raw)) return `V${raw}`;
|
||||||
|
const text = extractText(raw);
|
||||||
|
if (!text) return '';
|
||||||
|
if (/^v\d+/i.test(text.trim())) return text.trim();
|
||||||
|
const m = text.match(/\d+(?:\.\d+)?/);
|
||||||
|
return m ? `V${m[0]}` : text.trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchOmsDeliveryVersions = async (omsRecordId: string): Promise<any[]> => {
|
||||||
|
if (!omsRecordId) return [];
|
||||||
|
const omsTable = await bitable.base.getTable(OMS_BOARD_TABLE_ID);
|
||||||
|
const omsRecord = await omsTable.getRecordById(omsRecordId);
|
||||||
|
const planText = extractText(omsRecord?.fields?.[OMS_PLAN_TEXT_FIELD_ID])?.trim();
|
||||||
|
if (!planText) {
|
||||||
|
if (bitable.ui.showToast) {
|
||||||
|
await bitable.ui.showToast({ toastType: ToastType.warning, message: 'OMS看板记录缺少货期计划' });
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
setOmsPlanText(planText);
|
||||||
|
const deliveryTable = await bitable.base.getTable(DELIVERY_RECORD_TABLE_ID);
|
||||||
|
const filter: any = {
|
||||||
|
conjunction: 'and',
|
||||||
|
conditions: [{ fieldId: DELIVERY_RECORD_IDS_FIELD_ID, operator: 'is', value: planText }]
|
||||||
|
};
|
||||||
|
const sort = DELIVERY_CREATE_TIME_FIELD_ID
|
||||||
|
? [{ fieldId: DELIVERY_CREATE_TIME_FIELD_ID, desc: true }]
|
||||||
|
: undefined;
|
||||||
|
const recs = await fetchAllRecordsByPage(deliveryTable, { filter, sort });
|
||||||
|
return recs.map((r: any) => {
|
||||||
|
const fields = r?.fields || {};
|
||||||
|
const expectedTs = parseTimestampFromField(fields?.[DELIVERY_EXPECTED_DATE_FIELD_ID]);
|
||||||
|
const createdTs = parseTimestampFromField(fields?.[DELIVERY_CREATE_TIME_FIELD_ID]);
|
||||||
|
const expectedDate = expectedTs ? formatDate(new Date(expectedTs), 'DISPLAY_DATE_ONLY') : (extractText(fields?.[DELIVERY_EXPECTED_DATE_FIELD_ID]) || '');
|
||||||
|
const createdAt = createdTs ? formatDate(new Date(createdTs)) : (extractText(fields?.[DELIVERY_CREATE_TIME_FIELD_ID]) || '');
|
||||||
|
return {
|
||||||
|
recordId: r?.recordId || r?.id || '',
|
||||||
|
po: extractText(fields?.[DELIVERY_PO_FIELD_ID]) || '',
|
||||||
|
expectedDate,
|
||||||
|
version: parseVersionLabel(fields?.[DELIVERY_VERSION_FIELD_ID]),
|
||||||
|
creator: extractUserNames(fields?.[DELIVERY_CREATOR_FIELD_ID]),
|
||||||
|
createdAt
|
||||||
|
};
|
||||||
|
}).filter((row: any) => row.recordId);
|
||||||
|
};
|
||||||
|
|
||||||
// 初始化起始时间:从货期记录表获取,新记录则使用当前时间
|
// 初始化起始时间:从货期记录表获取,新记录则使用当前时间
|
||||||
const initializeStartTime = async () => {
|
const initializeStartTime = async () => {
|
||||||
try {
|
try {
|
||||||
@ -6151,6 +6234,37 @@ export default function App() {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const omsVersionColumns = [
|
||||||
|
{ title: 'PO', dataIndex: 'po', key: 'po', width: 180 },
|
||||||
|
{ title: '预计交付日期', dataIndex: 'expectedDate', key: 'expectedDate', width: 140 },
|
||||||
|
{ title: '版本号', dataIndex: 'version', key: 'version', width: 110 },
|
||||||
|
{ title: '创建人', dataIndex: 'creator', key: 'creator', width: 160 },
|
||||||
|
{ title: '生成时间', dataIndex: 'createdAt', key: 'createdAt', width: 170 },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
render: (_: any, row: any) => (
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
theme="solid"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
const recordId = row?.recordId;
|
||||||
|
if (!recordId) return;
|
||||||
|
setOmsVersionModalVisible(false);
|
||||||
|
setOmsVersionList([]);
|
||||||
|
setSelectedDeliveryRecordId(recordId);
|
||||||
|
await loadProcessDataFromDeliveryRecord(recordId);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
选择
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: '20px' }}>
|
<div style={{ padding: '20px' }}>
|
||||||
{/* 入口选择弹窗 */}
|
{/* 入口选择弹窗 */}
|
||||||
@ -6276,6 +6390,27 @@ export default function App() {
|
|||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={`请选择版本${omsPlanText ? `(${omsPlanText})` : ''}`}
|
||||||
|
visible={omsVersionModalVisible}
|
||||||
|
onCancel={() => { setOmsVersionModalVisible(false); setOmsVersionList([]); }}
|
||||||
|
footer={
|
||||||
|
<Space>
|
||||||
|
<Button onClick={() => { setOmsVersionModalVisible(false); setOmsVersionList([]); }}>关闭</Button>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
maskClosable={false}
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
loading={omsVersionLoading}
|
||||||
|
columns={omsVersionColumns}
|
||||||
|
dataSource={omsVersionList}
|
||||||
|
rowKey="recordId"
|
||||||
|
pagination={false}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
{mode === 'generate' && (
|
{mode === 'generate' && (
|
||||||
<div style={{ marginBottom: '24px' }}>
|
<div style={{ marginBottom: '24px' }}>
|
||||||
<Title heading={2} style={{
|
<Title heading={2} style={{
|
||||||
@ -6337,15 +6472,21 @@ export default function App() {
|
|||||||
setSelectedDeliveryRecordId(recordId);
|
setSelectedDeliveryRecordId(recordId);
|
||||||
await loadProcessDataFromDeliveryRecord(recordId);
|
await loadProcessDataFromDeliveryRecord(recordId);
|
||||||
} else if (tableId === OMS_BOARD_TABLE_ID) {
|
} else if (tableId === OMS_BOARD_TABLE_ID) {
|
||||||
const matchedDeliveryRecordId = await getDeliveryRecordIdFromOmsRecord(recordId);
|
try {
|
||||||
if (!matchedDeliveryRecordId) {
|
setOmsVersionLoading(true);
|
||||||
if (bitable.ui.showToast) {
|
setOmsVersionList([]);
|
||||||
await bitable.ui.showToast({ toastType: ToastType.warning, message: 'OMS看板记录缺少货期记录ID(fldjEIP9yC)' });
|
const list = await fetchOmsDeliveryVersions(recordId);
|
||||||
|
if (list.length === 0) {
|
||||||
|
if (bitable.ui.showToast) {
|
||||||
|
await bitable.ui.showToast({ toastType: ToastType.warning, message: '未找到可用的版本记录' });
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
setOmsVersionList(list);
|
||||||
|
setOmsVersionModalVisible(true);
|
||||||
|
} finally {
|
||||||
|
setOmsVersionLoading(false);
|
||||||
}
|
}
|
||||||
setSelectedDeliveryRecordId(matchedDeliveryRecordId);
|
|
||||||
await loadProcessDataFromDeliveryRecord(matchedDeliveryRecordId);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// 原始逻辑:从OMS看板用“货期计划 + 计划版本”匹配货期记录(已停用)
|
// 原始逻辑:从OMS看板用“货期计划 + 计划版本”匹配货期记录(已停用)
|
||||||
|
|||||||
Reference in New Issue
Block a user