- 将 shipOrderVO 相关命名统一调整为 orderShip,提升语义一致性 - 更新 DeliveryFormSection 组件支持预览功能,新增 Popup 弹窗展示 - 优化 PurchaseFormSection 中发货单数据结构引用逻辑 - 移除冗余的 console 日志输出,提高代码整洁度 - 调整 CostList 组件增加 key 属性避免渲染异常 - 升级 API 接口定义文件,完善 OrderShip 类型声明 - 替换旧有 shipOrder 模块为新的 orderShip 模块 - 修正 MarketPriceSection 中箱重计算方式调用链路 - 完善类型定义中 costItemIds 字段类型从 number[] 到 string[] - 更新 APP_VERSION 版本号至 v0.0.35
123 lines
3.2 KiB
TypeScript
123 lines
3.2 KiB
TypeScript
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
import { DeliveryStep1Form, DeliveryStep2Preview } from "@/components";
|
|
import {
|
|
convertPurchaseOrderToShipOrder,
|
|
convertShipOrderVOToExamplesFormat,
|
|
} from "@/utils";
|
|
import { business } from "@/services";
|
|
import { Popup } from "@nutui/nutui-react-taro";
|
|
import { View } from "@tarojs/components";
|
|
|
|
export interface DeliveryFormSectionRef {
|
|
handlePreview: () => void;
|
|
}
|
|
|
|
export default forwardRef<
|
|
DeliveryFormSectionRef,
|
|
{
|
|
purchaseOrderVO: BusinessAPI.PurchaseOrderVO;
|
|
onChange?: (orderDealer: BusinessAPI.PurchaseOrderVO) => void;
|
|
readOnly?: boolean;
|
|
}
|
|
>((props, ref) => {
|
|
const { purchaseOrderVO, onChange, readOnly } = props;
|
|
const [moduleList, setModuleList] = useState<any[]>([]);
|
|
|
|
const [previewVisible, setPreviewVisible] = useState(false);
|
|
|
|
const orderShip = convertPurchaseOrderToShipOrder(purchaseOrderVO);
|
|
|
|
const init = async (purchaseOrderVO: BusinessAPI.PurchaseOrderVO) => {
|
|
const { data } = await business.dealer.showDealer({
|
|
dealerShowQry: {
|
|
dealerId: purchaseOrderVO.orderDealer.dealerId,
|
|
},
|
|
});
|
|
|
|
if (data.data?.deliveryTemplate!) {
|
|
const template = JSON.parse(data.data?.deliveryTemplate!);
|
|
// 将 shipOrderVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据
|
|
const convertedData = convertShipOrderVOToExamplesFormat(
|
|
purchaseOrderVO,
|
|
orderShip,
|
|
);
|
|
const updatedTemplate = await updateTemplateConfig(
|
|
template,
|
|
convertedData,
|
|
);
|
|
setModuleList(updatedTemplate);
|
|
} else {
|
|
setModuleList([]);
|
|
}
|
|
};
|
|
|
|
// 更新模板配置
|
|
const updateTemplateConfig = async (template: any[], data: any) => {
|
|
let templateList: any[] = [];
|
|
template.map(async (module: any) => {
|
|
let newModule = { ...module };
|
|
if (data[module.type]) {
|
|
newModule.config = { ...module.config, ...data[module.type] };
|
|
}
|
|
templateList.push(newModule);
|
|
});
|
|
|
|
return templateList;
|
|
};
|
|
|
|
// 预览发货单操作
|
|
const handlePreview = () => {
|
|
setPreviewVisible(true);
|
|
};
|
|
|
|
useEffect(() => {
|
|
init(purchaseOrderVO);
|
|
}, [purchaseOrderVO.orderDealer.dealerId]);
|
|
|
|
// 暴露方法给父组件
|
|
useImperativeHandle(ref, () => ({
|
|
handlePreview,
|
|
}));
|
|
|
|
if (!orderShip) {
|
|
return;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<DeliveryStep1Form
|
|
readOnly={readOnly}
|
|
moduleList={moduleList}
|
|
orderShip={orderShip}
|
|
setOrderShip={(orderShip) => {
|
|
onChange?.({
|
|
...purchaseOrderVO,
|
|
orderShipList: [orderShip],
|
|
});
|
|
}}
|
|
/>
|
|
|
|
{/* 预览发货单 */}
|
|
<Popup
|
|
duration={150}
|
|
style={{
|
|
minHeight: "auto",
|
|
}}
|
|
className={"!bg-[#D1D5DB]"}
|
|
visible={previewVisible}
|
|
position="bottom"
|
|
onClose={() => {
|
|
setPreviewVisible(false);
|
|
}}
|
|
closeable
|
|
destroyOnClose
|
|
title={"预览发货单"}
|
|
>
|
|
<View className={"overflow-hidden p-2.5"}>
|
|
<DeliveryStep2Preview moduleList={moduleList} />
|
|
</View>
|
|
</Popup>
|
|
</>
|
|
);
|
|
});
|