Commit 232a718a authored by XieZhiXiong's avatar XieZhiXiong

fix: 修复分页之后点击确认无法拿到上一页填写的数据问题

parent d20c3a2e
...@@ -96,6 +96,11 @@ type MaterialsListItem = Omit<GetContractManagePagePurchaseMaterielListResponseD ...@@ -96,6 +96,11 @@ type MaterialsListItem = Omit<GetContractManagePagePurchaseMaterielListResponseD
children: RequisitionListItem[], children: RequisitionListItem[],
} }
export type FetchReponseType = {
data: MaterialsListItem[],
totalCount: number,
}
const normalizeMaterialsList = (dataSource: GetContractManagePagePurchaseMaterielListResponseDetail[]): MaterialsListItem[] => { const normalizeMaterialsList = (dataSource: GetContractManagePagePurchaseMaterielListResponseDetail[]): MaterialsListItem[] => {
const ret: MaterialsListItem[] = []; const ret: MaterialsListItem[] = [];
dataSource.forEach(({ requisitionList, ...rest }) => { dataSource.forEach(({ requisitionList, ...rest }) => {
...@@ -127,6 +132,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -127,6 +132,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
const keyEntities = useRef<any>({}); const keyEntities = useRef<any>({});
const requisitionListValue = useRef<OrderMaterialsSubmitValue['materials']['requisitionList']>({});
const [form] = Form.useForm(); const [form] = Form.useForm();
const intl = useIntl(); const intl = useIntl();
...@@ -222,7 +229,7 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -222,7 +229,7 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
const { levelMap, maxLevel } = getLevelEntities(keyEntities.current); const { levelMap, maxLevel } = getLevelEntities(keyEntities.current);
if (selected) { if (selected) {
const keys = [...checkedKeysState, ...selectedRows.map((item) => item.key)]; const keys = [...checkedKeysState, ...selectedRows.filter(Boolean).map((item) => item.key)];
const { halfCheckedKeys, checkedKeys } = fillConductCheck(keys, levelMap, maxLevel); const { halfCheckedKeys, checkedKeys } = fillConductCheck(keys, levelMap, maxLevel);
setCheckedKeysState(checkedKeys); setCheckedKeysState(checkedKeys);
setHalfCheckedState(halfCheckedKeys); setHalfCheckedState(halfCheckedKeys);
...@@ -323,7 +330,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -323,7 +330,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
const { materials } = res; const { materials } = res;
const ret: OrderMaterialsConfirmValue = []; const ret: OrderMaterialsConfirmValue = [];
const checkedKeys = Object.keys(materials.requisitionList); // const checkedKeys = Object.keys(materials.requisitionList);
const checkedKeys = Object.keys(requisitionListValue.current);
for (let i = 0; i < checkedKeys.length; i++) { for (let i = 0; i < checkedKeys.length; i++) {
const checked = checkedKeys[i]; const checked = checkedKeys[i];
const { parentNode } = keyEntities.current[checked]; const { parentNode } = keyEntities.current[checked];
...@@ -338,7 +346,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -338,7 +346,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
...restParent, ...restParent,
requisitionList: children.map((item) => ({ requisitionList: children.map((item) => ({
...item, ...item,
orderQuantity: +materials.requisitionList[checked], // orderQuantity: +materials.requisitionList[checked],
orderQuantity: +requisitionListValue.current[checked],
})), })),
}; };
ret.push(material); ret.push(material);
...@@ -350,7 +359,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -350,7 +359,8 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
...(ret[index]).requisitionList, ...(ret[index]).requisitionList,
...children.map((item) => ({ ...children.map((item) => ({
...item, ...item,
orderQuantity: +materials.requisitionList[checked], // orderQuantity: +materials.requisitionList[checked],
orderQuantity: +requisitionListValue.current[checked],
})), })),
], ],
})); }));
...@@ -377,6 +387,23 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -377,6 +387,23 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
// }); // });
}; };
const handleBeforePaginationChange = async () => {
try {
await form.validateFields()
return true;
} catch (error) {
return false;
}
};
const handleFormValuesChange = (_, allValues: OrderMaterialsSubmitValue) => {
const { materials } = allValues;
requisitionListValue.current = {
...requisitionListValue.current,
...(materials.requisitionList || {}),
};
};
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
deleteItem: handleDelete, deleteItem: handleDelete,
})); }));
...@@ -415,7 +442,7 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -415,7 +442,7 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
onSelect: handleSelectRow, onSelect: handleSelectRow,
onSelectAll: handlehandleSelectAll, onSelectAll: handlehandleSelectAll,
}} }}
defaultPageSize={20} defaultPageSize={10}
expandable={isPurchaseOrderContract ? { expandable={isPurchaseOrderContract ? {
expandedRowRender, expandedRowRender,
expandIcon: ({ expanded, onExpand, record }) => ( expandIcon: ({ expanded, onExpand, record }) => (
...@@ -442,11 +469,12 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR ...@@ -442,11 +469,12 @@ const OrderMaterialsDrawer: React.ForwardRefRenderFunction<OrderMaterialsDrawerR
ref={polymericRef} ref={polymericRef}
components={{ components={{
table: ({ children }) => ( table: ({ children }) => (
<Form form={form}> <Form form={form} onValuesChange={handleFormValuesChange}>
<table>{children}</table> <table>{children}</table>
</Form> </Form>
), ),
}} }}
beforePaginationChange={handleBeforePaginationChange}
defaultExpandAllRows defaultExpandAllRows
full full
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment