ERPTurbo_Client/packages/app-client/src/components/purchase/section/DeliveryFormSection.tsx
shenyifei fffb0c7269 feat(preview): 添加PC端预览页面和发货单预览功能
- 添加了PC端预览页面,支持多种设备模拟预览
- 在采购审核页面集成了发货单预览按钮
- 重构了发货表单组件,移除ref暴露机制
- 更新订单转换器以支持发货单数据转换
- 在发票上传页面添加供应商选择器组件
- 添加初始车次号相关字段到API类型定义
- 将发货表单中的Input组件替换为TextArea组件
- 修复了订单项ID匹配逻辑错误
2025-12-27 13:47:37 +08:00

121 lines
3.1 KiB
TypeScript

import { useEffect, useState } from "react";
import { DeliveryStep1Form, DeliveryStep2Preview, Icon } from "@/components";
import { convertOrderShipVOToExamplesFormat } from "@/utils";
import { business } from "@/services";
import { Button, Popup } from "@nutui/nutui-react-taro";
import { View } from "@tarojs/components";
export default function DeliveryFormSection(props: {
orderVO: BusinessAPI.OrderVO;
onChange?: (orderDealer: BusinessAPI.OrderVO) => void;
readOnly?: boolean;
}) {
const { orderVO, onChange, readOnly } = props;
const [template, setTemplate] = useState<any[]>([]);
const [previewVisible, setPreviewVisible] = useState(false);
const orderShip = orderVO.orderShipList[0];
const init = async (orderId: BusinessAPI.OrderVO["orderId"]) => {
const { data } = await business.dealer.showDealer({
dealerShowQry: {
dealerId: orderId,
},
});
if (data.data?.deliveryTemplate!) {
const template = JSON.parse(data.data?.deliveryTemplate!);
setTemplate(template);
}
};
// 将 orderShipVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据
const convertedData = convertOrderShipVOToExamplesFormat(orderVO);
// 更新模板配置
const updateTemplateConfig = (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;
};
useEffect(() => {
if (orderVO.orderDealer.dealerId) {
init(orderVO.orderDealer.dealerId);
}
}, [orderVO.orderDealer.dealerId]);
// 预览发货单操作
const handlePreview = () => {
setPreviewVisible(true);
};
if (!template) {
return;
}
const moduleList = updateTemplateConfig(template, convertedData);
console.log("moduleList", moduleList);
console.log("orderShip", orderShip);
return (
<>
<DeliveryStep1Form
readOnly={readOnly}
moduleList={moduleList}
orderShip={orderShip}
setOrderShip={(orderShip) => {
onChange?.({
...orderVO,
orderShipList: [orderShip],
});
}}
/>
{/* 预览发货单 */}
<View className={"flex-1"}>
<Button
icon={<Icon name="eye" size={18} />}
size={"large"}
type="primary"
fill="outline"
block
onClick={handlePreview}
>
</Button>
</View>
{/* 预览发货单 */}
<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>
</>
);
}