refactor(delivery): 重构发货单相关逻辑以适配新接口

- 修改了发货单字段引用,将 shipOrderId 更新为 orderShipId
- 调整了发货单接口调用方法和参数结构
- 替换了 convertPurchaseOrderToShipOrder 工具函数为 convertPurchaseOrderToOrderShip
- 优化了采购表单中 orderShip 数据的初始化逻辑
- 在多个组件中更新了 OrderShipVO 类型的使用
- 调整了发货单文档生成相关的数据结构和接口调用
- 增加了对 orderShipList 为空时的默认值处理
- 修复了采购成本计算中重复添加运费的问题
- 补充了供应商定价方式的判断逻辑
- 增加了包纸箱状态的显示逻辑
- 添加了必要的控制台日志以便调试
- 升级了应用版本号至 v0.0.36
This commit is contained in:
shenyifei 2025-12-15 18:42:08 +08:00
parent e6573b43e8
commit b98ad2fb40
14 changed files with 100 additions and 66 deletions

View File

@ -103,5 +103,5 @@ export default defineAppConfig({
navigationBarBackgroundColor: "#fff", navigationBarBackgroundColor: "#fff",
navigationBarTitleText: "WeChat", navigationBarTitleText: "WeChat",
navigationBarTextStyle: "black", navigationBarTextStyle: "black",
} },
}); });

View File

@ -378,8 +378,8 @@ const Step1Form = forwardRef<Step1FormRef, Step1FormProps>((props, ref) => {
setOrderShip({ setOrderShip({
...orderShip!, ...orderShip!,
shipOrderItemList: orderShipItemList:
orderShip?.shipOrderItemList?.map( orderShip?.orderShipItemList?.map(
(item: any) => { (item: any) => {
if (item.itemId === shipOrderItem.itemId) { if (item.itemId === shipOrderItem.itemId) {
return { return {
@ -523,13 +523,13 @@ const Step1Form = forwardRef<Step1FormRef, Step1FormProps>((props, ref) => {
module.config.showGrade module.config.showGrade
) { ) {
console.log( console.log(
"orderShip?.shipOrderItemList", "orderShip?.orderShipItemList",
orderShip?.shipOrderItemList, orderShip?.orderShipItemList,
); );
if (orderShip?.shipOrderItemList) { if (orderShip?.orderShipItemList) {
const itemGradesErrors: { [key: string]: boolean } = {}; const itemGradesErrors: { [key: string]: boolean } = {};
for (let i = 0; i < orderShip.shipOrderItemList.length; i++) { for (let i = 0; i < orderShip.orderShipItemList.length; i++) {
const item = orderShip.shipOrderItemList[i]; const item = orderShip.orderShipItemList[i];
if (!item.watermelonGrade) { if (!item.watermelonGrade) {
itemGradesErrors[item.itemId] = true; itemGradesErrors[item.itemId] = true;
hasErrors = true; hasErrors = true;

View File

@ -22,18 +22,21 @@ export default function CostSummarySection(props: {
let costWithoutFreight: number; let costWithoutFreight: number;
let costWithFreight: number; let costWithFreight: number;
// 判断采购成本是否包含运费 // 判断采购成本是否包含运费,包含运费说明已经加过一次了
if (calculator.getRules().shouldIncludeFreightCost()) { if (calculator.getRules().shouldIncludeFreightCost()) {
costWithoutFreight = totalPurchaseCost - freightCost; costWithFreight = totalPurchaseCost - freightCost;
costWithFreight = totalPurchaseCost; costWithoutFreight = costWithFreight - freightCost;
} else { } else {
costWithoutFreight = totalPurchaseCost; costWithoutFreight = totalPurchaseCost;
costWithFreight = totalPurchaseCost + freightCost; costWithFreight = totalPurchaseCost + freightCost;
} }
console.log("采购成本", costWithoutFreight);
console.log("采购成本(含运费)", costWithFreight);
// 计算单斤成本(不含运费) // 计算单斤成本(不含运费)
const unitCostWithoutFreight = const unitCostWithoutFreight =
totalNetWeight > 0 ? totalPurchaseCost / totalNetWeight : 0; totalNetWeight > 0 ? costWithoutFreight / totalNetWeight : 0;
// 计算单斤成本(含运费) // 计算单斤成本(含运费)
const unitCostWithFreight = const unitCostWithFreight =

View File

@ -1,9 +1,6 @@
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { DeliveryStep1Form, DeliveryStep2Preview } from "@/components"; import { DeliveryStep1Form, DeliveryStep2Preview } from "@/components";
import { import { convertShipOrderVOToExamplesFormat } from "@/utils";
convertPurchaseOrderToShipOrder,
convertShipOrderVOToExamplesFormat,
} from "@/utils";
import { business } from "@/services"; import { business } from "@/services";
import { Popup } from "@nutui/nutui-react-taro"; import { Popup } from "@nutui/nutui-react-taro";
import { View } from "@tarojs/components"; import { View } from "@tarojs/components";
@ -25,7 +22,7 @@ export default forwardRef<
const [previewVisible, setPreviewVisible] = useState(false); const [previewVisible, setPreviewVisible] = useState(false);
const orderShip = convertPurchaseOrderToShipOrder(purchaseOrderVO); const orderShip = purchaseOrderVO.orderShipList[0];
const init = async (purchaseOrderVO: BusinessAPI.PurchaseOrderVO) => { const init = async (purchaseOrderVO: BusinessAPI.PurchaseOrderVO) => {
const { data } = await business.dealer.showDealer({ const { data } = await business.dealer.showDealer({
@ -39,7 +36,7 @@ export default forwardRef<
// 将 shipOrderVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据 // 将 shipOrderVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据
const convertedData = convertShipOrderVOToExamplesFormat( const convertedData = convertShipOrderVOToExamplesFormat(
purchaseOrderVO, purchaseOrderVO,
orderShip, orderShip!,
); );
const updatedTemplate = await updateTemplateConfig( const updatedTemplate = await updateTemplateConfig(
template, template,
@ -71,8 +68,10 @@ export default forwardRef<
}; };
useEffect(() => { useEffect(() => {
if (orderShip) {
init(purchaseOrderVO); init(purchaseOrderVO);
}, [purchaseOrderVO.orderDealer.dealerId]); }
}, [purchaseOrderVO.orderDealer.dealerId, orderShip]);
// 暴露方法给父组件 // 暴露方法给父组件
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({

View File

@ -230,6 +230,15 @@ export default function MarketPriceSection(props: {
</Text> </Text>
</View> </View>
{/* 是否包纸箱 */}
<View className="flex items-center justify-between">
<Text className="text-sm text-gray-500"></Text>
<Text className="text-sm font-medium">
{supplier.pricingMethod === "BY_GROSS_WEIGHT"
? "包"
: "不包"}
</Text>
</View>
<View className="flex items-center justify-between"> <View className="flex items-center justify-between">
<Text className="text-sm text-gray-500"></Text> <Text className="text-sm text-gray-500"></Text>
<Text className="text-sm font-medium"> <Text className="text-sm font-medium">

View File

@ -1,6 +1,6 @@
import { View } from "@tarojs/components"; import { View } from "@tarojs/components";
import { Icon, PurchaseStep1Form } from "@/components"; import { Icon, PurchaseStep1Form } from "@/components";
import { convertPurchaseOrderToShipOrder } from "@/utils"; import { convertPurchaseOrderToOrderShip } from "@/utils";
export default function PurchaseFormSection(props: { export default function PurchaseFormSection(props: {
purchaseOrderVO: BusinessAPI.PurchaseOrderVO; purchaseOrderVO: BusinessAPI.PurchaseOrderVO;
@ -12,7 +12,7 @@ export default function PurchaseFormSection(props: {
const shipOrderVO = const shipOrderVO =
purchaseOrderVO.orderShipList && purchaseOrderVO.orderShipList.length > 0 purchaseOrderVO.orderShipList && purchaseOrderVO.orderShipList.length > 0
? purchaseOrderVO.orderShipList[0] ? purchaseOrderVO.orderShipList[0]
: convertPurchaseOrderToShipOrder(purchaseOrderVO); : convertPurchaseOrderToOrderShip(purchaseOrderVO);
if (!shipOrderVO) { if (!shipOrderVO) {
return; return;

View File

@ -1,2 +1,2 @@
// App 相关常量 // App 相关常量
export const APP_VERSION = "v0.0.35"; export const APP_VERSION = "v0.0.36";

View File

@ -71,7 +71,7 @@ const updateOtherFeesModule = async (
export default hocAuth(function Page(props: CommonComponent) { export default hocAuth(function Page(props: CommonComponent) {
const { router, setLoading } = props; const { router, setLoading } = props;
const shipOrderId = router.params const shipOrderId = router.params
.shipOrderId as BusinessAPI.OrderShipVO["shipOrderId"]; .shipOrderId as BusinessAPI.OrderShipVO["orderShipId"];
const [step, setStep] = useState(1); const [step, setStep] = useState(1);
const [moduleList, setModuleList] = useState<any[]>([]); const [moduleList, setModuleList] = useState<any[]>([]);
@ -82,11 +82,11 @@ export default hocAuth(function Page(props: CommonComponent) {
const step1FormRef = useRef<DeliveryStep1FormRef>(null); const step1FormRef = useRef<DeliveryStep1FormRef>(null);
const init = async (shipOrderId: BusinessAPI.OrderShipVO["shipOrderId"]) => { const init = async (orderShipId: BusinessAPI.OrderShipVO["orderShipId"]) => {
setLoading(true); setLoading(true);
const { data } = await business.shipOrder.showShipOrder({ const { data } = await business.orderShip.showOrderShip({
shipOrderShowQry: { orderShipShowQry: {
shipOrderId, orderShipId,
}, },
}); });
const shipOrderVO = data.data; const shipOrderVO = data.data;
@ -141,7 +141,7 @@ export default hocAuth(function Page(props: CommonComponent) {
const updateTemplateConfig = async ( const updateTemplateConfig = async (
template: any[], template: any[],
data: any, data: any,
shipOrderVO: BusinessAPI.ShipOrderVO, shipOrderVO: BusinessAPI.OrderShipVO,
) => { ) => {
let templateList: any[] = []; let templateList: any[] = [];
template.map(async (module: any) => { template.map(async (module: any) => {
@ -226,8 +226,8 @@ export default hocAuth(function Page(props: CommonComponent) {
// 存储 至 shipOrder previewUrl // 存储 至 shipOrder previewUrl
if (shipOrderVO) { if (shipOrderVO) {
let formData: BusinessAPI.ShipOrderGenerateDocumentCmd = { let formData: BusinessAPI.OrderShipGenerateDocumentCmd = {
shipOrderId: shipOrderVO?.shipOrderId, orderShipId: shipOrderVO?.orderShipId,
document: data?.data?.path, document: data?.data?.path,
}; };
// 检查各模块中的必填字段是否已填写 // 检查各模块中的必填字段是否已填写
@ -263,11 +263,11 @@ export default hocAuth(function Page(props: CommonComponent) {
} }
// 检查品级字段是否开启且已填写 // 检查品级字段是否开启且已填写
else if (column.dataIndex === "requiredGrade") { else if (column.dataIndex === "requiredGrade") {
formData.shipOrderItemList = shipOrderVO?.shipOrderItemList; formData.orderShipItemList = shipOrderVO?.orderShipItemList;
} }
} }
} }
business.shipOrder.generateDocumentShipOrder(formData).then(); business.orderShip.generateDocumentOrderShip(formData).then();
} }
if (data && data?.data?.path) { if (data && data?.data?.path) {

View File

@ -24,11 +24,11 @@ export default hocAuth(function Page(props: CommonComponent) {
const [step, setStep] = useState(1); const [step, setStep] = useState(1);
const [moduleList, setModuleList] = useState<any[]>([]); const [moduleList, setModuleList] = useState<any[]>([]);
const [document, setDocument] = const [document, setDocument] =
useState<BusinessAPI.ShipOrderVO["document"]>(); useState<BusinessAPI.OrderShipVO["document"]>();
const [height, setHeight] = useState<number>(); const [height, setHeight] = useState<number>();
const [purchaseOrderVO, setPurchaseOrderVO] = const [purchaseOrderVO, setPurchaseOrderVO] =
useState<BusinessAPI.PurchaseOrderVO>(); useState<BusinessAPI.PurchaseOrderVO>();
const [shipOrderVO, setShipOrderVO] = useState<BusinessAPI.ShipOrderVO>(); const [shipOrderVO, setShipOrderVO] = useState<BusinessAPI.OrderShipVO>();
const step1FormRef = useRef<PurchaseStep1FormRef>(null); const step1FormRef = useRef<PurchaseStep1FormRef>(null);
@ -118,8 +118,8 @@ export default hocAuth(function Page(props: CommonComponent) {
// 存储 至 shipOrder previewUrl // 存储 至 shipOrder previewUrl
if (shipOrderVO) { if (shipOrderVO) {
let formData: BusinessAPI.ShipOrderGenerateDocumentCmd = { let formData: BusinessAPI.OrderShipGenerateDocumentCmd = {
shipOrderId: shipOrderVO?.shipOrderId, orderShipId: shipOrderVO?.orderShipId,
document: data?.data?.path, document: data?.data?.path,
}; };
// 检查各模块中的必填字段是否已填写 // 检查各模块中的必填字段是否已填写
@ -155,11 +155,11 @@ export default hocAuth(function Page(props: CommonComponent) {
} }
// 检查品级字段是否开启且已填写 // 检查品级字段是否开启且已填写
else if (column.dataIndex === "requiredGrade") { else if (column.dataIndex === "requiredGrade") {
formData.shipOrderItemList = shipOrderVO?.shipOrderItemList; formData.orderShipItemList = shipOrderVO?.orderShipItemList;
} }
} }
} }
business.shipOrder.generateDocumentShipOrder(formData).then(); business.orderShip.generateDocumentOrderShip(formData).then();
} }
if (data && data?.data?.path) { if (data && data?.data?.path) {

View File

@ -42,6 +42,7 @@ import {
import { type DeliveryFormSectionRef } from "@/components/purchase/section/DeliveryFormSection"; import { type DeliveryFormSectionRef } from "@/components/purchase/section/DeliveryFormSection";
import { import {
buildUrl, buildUrl,
convertPurchaseOrderToOrderShip,
formatCurrency, formatCurrency,
generateShortId, generateShortId,
PurchaseOrderCalculator, PurchaseOrderCalculator,
@ -524,9 +525,24 @@ export default hocAuth(function Page(props: CommonComponent) {
}); });
if (success && purchaseOrderVO) { if (success && purchaseOrderVO) {
if (
!purchaseOrderVO.orderShipList ||
purchaseOrderVO.orderShipList.length === 0
) {
purchaseOrderVO.orderShipList = [
convertPurchaseOrderToOrderShip(purchaseOrderVO),
];
}
console.log(
"purchaseOrderVO.orderShipList",
purchaseOrderVO.orderShipList,
);
await initDealer(purchaseOrderVO?.orderDealer?.dealerId!); await initDealer(purchaseOrderVO?.orderDealer?.dealerId!);
purchaseOrderVO.orderCostList.map((item) => { purchaseOrderVO.orderCostList.map((item) => {
if (!item.price) {
item.price = purchaseOrderVO.orderCostItemList item.price = purchaseOrderVO.orderCostItemList
.filter((orderCost) => .filter((orderCost) =>
item.costItemIds?.includes(orderCost.costItemId!), item.costItemIds?.includes(orderCost.costItemId!),
@ -539,17 +555,11 @@ export default hocAuth(function Page(props: CommonComponent) {
), ),
0, 0,
); );
}
console.log("item", item);
return item; return item;
}); });
console.log(
"purchaseOrderVO.orderCostList",
purchaseOrderVO.orderCostList,
);
// 计提费 // 计提费
const orderCost = purchaseOrderVO?.orderCostList.find( const orderCost = purchaseOrderVO?.orderCostList.find(
(item) => item.name === "计提费" && item.type === "OTHER_TYPE", (item) => item.name === "计提费" && item.type === "OTHER_TYPE",
@ -596,8 +606,11 @@ export default hocAuth(function Page(props: CommonComponent) {
} }
} }
const cost1 = costList?.find(
(cost) => cost.name === "运费" && cost.type === "OTHER_TYPE",
);
// 加运费 // 加运费
if (purchaseOrderVO.orderVehicle.price) { if (purchaseOrderVO.orderVehicle.price && !cost1) {
purchaseOrderVO.orderCostList.push({ purchaseOrderVO.orderCostList.push({
orderCostId: generateShortId(), orderCostId: generateShortId(),
costId: "", costId: "",
@ -612,8 +625,11 @@ export default hocAuth(function Page(props: CommonComponent) {
}); });
} }
const cost2 = costList?.find(
(cost) => cost.name === "草帘费" && cost.type === "OTHER_TYPE",
);
// 加草帘 // 加草帘
if (purchaseOrderVO.orderVehicle.openStrawCurtain) { if (purchaseOrderVO.orderVehicle.openStrawCurtain && !cost2) {
purchaseOrderVO.orderCostList.push({ purchaseOrderVO.orderCostList.push({
orderCostId: generateShortId(), orderCostId: generateShortId(),
costId: "", costId: "",

View File

@ -82,15 +82,15 @@ export class PurchaseOrderRules {
/** /**
* *
*/ */
getPricingMethod(): "BY_GROSS_WEIGHT" | "BY_NET_WEIGHT" { getPricingMethod(supplier: BusinessAPI.OrderSupplier): "BY_GROSS_WEIGHT" | "BY_NET_WEIGHT" {
return this.order.pricingMethod!; return supplier.pricingMethod!;
} }
/** /**
* *
*/ */
getWeightByPricingMethod(supplier: BusinessAPI.OrderSupplier): number { getWeightByPricingMethod(supplier: BusinessAPI.OrderSupplier): number {
return this.getPricingMethod() === "BY_GROSS_WEIGHT" return this.getPricingMethod(supplier) === "BY_GROSS_WEIGHT"
? supplier.grossWeight || 0 ? supplier.grossWeight || 0
: supplier.netWeight || 0; : supplier.netWeight || 0;
} }

View File

@ -99,6 +99,12 @@ export class CostCalculator {
const taxProvision = this.calculateTaxProvision(); const taxProvision = this.calculateTaxProvision();
const costDifference = this.getCostDifference(); const costDifference = this.getCostDifference();
console.log("melonCost", melonCost);
console.log("otherCosts", otherCosts);
console.log("taxSubsidy", taxSubsidy);
console.log("taxProvision", taxProvision);
console.log("costDifference", costDifference);
return DecimalUtils.add( return DecimalUtils.add(
melonCost, melonCost,
otherCosts, otherCosts,
@ -132,6 +138,7 @@ export class CostCalculator {
private shouldIncludeCost(cost: BusinessAPI.OrderCost): boolean { private shouldIncludeCost(cost: BusinessAPI.OrderCost): boolean {
// 运费需要特殊判断 // 运费需要特殊判断
if (cost.name === "运费") { if (cost.name === "运费") {
console.log("this.rules.shouldIncludeFreightCost()", this.rules.shouldIncludeFreightCost())
return this.rules.shouldIncludeFreightCost(); return this.rules.shouldIncludeFreightCost();
} }

View File

@ -10,5 +10,5 @@ export {
convertOrderPackagesToBoxBrands convertOrderPackagesToBoxBrands
} from './boxBrandConverter' } from './boxBrandConverter'
export { convertPurchaseOrderToShipOrder } from './purchaseOrderConverter' export { convertPurchaseOrderToOrderShip } from './purchaseOrderConverter'
export { convertShipOrderVOToExamplesFormat } from './shipOrderConverter' export { convertShipOrderVOToExamplesFormat } from './shipOrderConverter'

View File

@ -7,7 +7,7 @@ import { DecimalUtils } from "@/utils/classes/calculators/core/DecimalUtils";
* @param purchaseOrderVO * @param purchaseOrderVO
* @returns * @returns
*/ */
export const convertPurchaseOrderToShipOrder = ( export const convertPurchaseOrderToOrderShip = (
purchaseOrderVO: BusinessAPI.PurchaseOrderVO purchaseOrderVO: BusinessAPI.PurchaseOrderVO
): BusinessAPI.OrderShip => { ): BusinessAPI.OrderShip => {
// 添加一个辅助函数用于分组 // 添加一个辅助函数用于分组