refactor(delivery): 重构发货单相关逻辑以适配新接口
- 修改了发货单字段引用,将 shipOrderId 更新为 orderShipId - 调整了发货单接口调用方法和参数结构 - 替换了 convertPurchaseOrderToShipOrder 工具函数为 convertPurchaseOrderToOrderShip - 优化了采购表单中 orderShip 数据的初始化逻辑 - 在多个组件中更新了 OrderShipVO 类型的使用 - 调整了发货单文档生成相关的数据结构和接口调用 - 增加了对 orderShipList 为空时的默认值处理 - 修复了采购成本计算中重复添加运费的问题 - 补充了供应商定价方式的判断逻辑 - 增加了包纸箱状态的显示逻辑 - 添加了必要的控制台日志以便调试 - 升级了应用版本号至 v0.0.36
This commit is contained in:
parent
e6573b43e8
commit
b98ad2fb40
@ -103,5 +103,5 @@ export default defineAppConfig({
|
||||
navigationBarBackgroundColor: "#fff",
|
||||
navigationBarTitleText: "WeChat",
|
||||
navigationBarTextStyle: "black",
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -378,8 +378,8 @@ const Step1Form = forwardRef<Step1FormRef, Step1FormProps>((props, ref) => {
|
||||
|
||||
setOrderShip({
|
||||
...orderShip!,
|
||||
shipOrderItemList:
|
||||
orderShip?.shipOrderItemList?.map(
|
||||
orderShipItemList:
|
||||
orderShip?.orderShipItemList?.map(
|
||||
(item: any) => {
|
||||
if (item.itemId === shipOrderItem.itemId) {
|
||||
return {
|
||||
@ -523,13 +523,13 @@ const Step1Form = forwardRef<Step1FormRef, Step1FormProps>((props, ref) => {
|
||||
module.config.showGrade
|
||||
) {
|
||||
console.log(
|
||||
"orderShip?.shipOrderItemList",
|
||||
orderShip?.shipOrderItemList,
|
||||
"orderShip?.orderShipItemList",
|
||||
orderShip?.orderShipItemList,
|
||||
);
|
||||
if (orderShip?.shipOrderItemList) {
|
||||
if (orderShip?.orderShipItemList) {
|
||||
const itemGradesErrors: { [key: string]: boolean } = {};
|
||||
for (let i = 0; i < orderShip.shipOrderItemList.length; i++) {
|
||||
const item = orderShip.shipOrderItemList[i];
|
||||
for (let i = 0; i < orderShip.orderShipItemList.length; i++) {
|
||||
const item = orderShip.orderShipItemList[i];
|
||||
if (!item.watermelonGrade) {
|
||||
itemGradesErrors[item.itemId] = true;
|
||||
hasErrors = true;
|
||||
|
||||
@ -22,18 +22,21 @@ export default function CostSummarySection(props: {
|
||||
let costWithoutFreight: number;
|
||||
let costWithFreight: number;
|
||||
|
||||
// 判断采购成本是否包含运费
|
||||
// 判断采购成本是否包含运费,包含运费说明已经加过一次了
|
||||
if (calculator.getRules().shouldIncludeFreightCost()) {
|
||||
costWithoutFreight = totalPurchaseCost - freightCost;
|
||||
costWithFreight = totalPurchaseCost;
|
||||
costWithFreight = totalPurchaseCost - freightCost;
|
||||
costWithoutFreight = costWithFreight - freightCost;
|
||||
} else {
|
||||
costWithoutFreight = totalPurchaseCost;
|
||||
costWithFreight = totalPurchaseCost + freightCost;
|
||||
}
|
||||
|
||||
console.log("采购成本", costWithoutFreight);
|
||||
console.log("采购成本(含运费)", costWithFreight);
|
||||
|
||||
// 计算单斤成本(不含运费)
|
||||
const unitCostWithoutFreight =
|
||||
totalNetWeight > 0 ? totalPurchaseCost / totalNetWeight : 0;
|
||||
totalNetWeight > 0 ? costWithoutFreight / totalNetWeight : 0;
|
||||
|
||||
// 计算单斤成本(含运费)
|
||||
const unitCostWithFreight =
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
||||
import { DeliveryStep1Form, DeliveryStep2Preview } from "@/components";
|
||||
import {
|
||||
convertPurchaseOrderToShipOrder,
|
||||
convertShipOrderVOToExamplesFormat,
|
||||
} from "@/utils";
|
||||
import { convertShipOrderVOToExamplesFormat } from "@/utils";
|
||||
import { business } from "@/services";
|
||||
import { Popup } from "@nutui/nutui-react-taro";
|
||||
import { View } from "@tarojs/components";
|
||||
@ -25,7 +22,7 @@ export default forwardRef<
|
||||
|
||||
const [previewVisible, setPreviewVisible] = useState(false);
|
||||
|
||||
const orderShip = convertPurchaseOrderToShipOrder(purchaseOrderVO);
|
||||
const orderShip = purchaseOrderVO.orderShipList[0];
|
||||
|
||||
const init = async (purchaseOrderVO: BusinessAPI.PurchaseOrderVO) => {
|
||||
const { data } = await business.dealer.showDealer({
|
||||
@ -39,7 +36,7 @@ export default forwardRef<
|
||||
// 将 shipOrderVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据
|
||||
const convertedData = convertShipOrderVOToExamplesFormat(
|
||||
purchaseOrderVO,
|
||||
orderShip,
|
||||
orderShip!,
|
||||
);
|
||||
const updatedTemplate = await updateTemplateConfig(
|
||||
template,
|
||||
@ -71,8 +68,10 @@ export default forwardRef<
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
init(purchaseOrderVO);
|
||||
}, [purchaseOrderVO.orderDealer.dealerId]);
|
||||
if (orderShip) {
|
||||
init(purchaseOrderVO);
|
||||
}
|
||||
}, [purchaseOrderVO.orderDealer.dealerId, orderShip]);
|
||||
|
||||
// 暴露方法给父组件
|
||||
useImperativeHandle(ref, () => ({
|
||||
|
||||
@ -230,6 +230,15 @@ export default function MarketPriceSection(props: {
|
||||
斤
|
||||
</Text>
|
||||
</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">
|
||||
<Text className="text-sm text-gray-500">采购单价</Text>
|
||||
<Text className="text-sm font-medium">
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { View } from "@tarojs/components";
|
||||
import { Icon, PurchaseStep1Form } from "@/components";
|
||||
import { convertPurchaseOrderToShipOrder } from "@/utils";
|
||||
import { convertPurchaseOrderToOrderShip } from "@/utils";
|
||||
|
||||
export default function PurchaseFormSection(props: {
|
||||
purchaseOrderVO: BusinessAPI.PurchaseOrderVO;
|
||||
@ -12,7 +12,7 @@ export default function PurchaseFormSection(props: {
|
||||
const shipOrderVO =
|
||||
purchaseOrderVO.orderShipList && purchaseOrderVO.orderShipList.length > 0
|
||||
? purchaseOrderVO.orderShipList[0]
|
||||
: convertPurchaseOrderToShipOrder(purchaseOrderVO);
|
||||
: convertPurchaseOrderToOrderShip(purchaseOrderVO);
|
||||
|
||||
if (!shipOrderVO) {
|
||||
return;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
// App 相关常量
|
||||
export const APP_VERSION = "v0.0.35";
|
||||
export const APP_VERSION = "v0.0.36";
|
||||
|
||||
@ -71,7 +71,7 @@ const updateOtherFeesModule = async (
|
||||
export default hocAuth(function Page(props: CommonComponent) {
|
||||
const { router, setLoading } = props;
|
||||
const shipOrderId = router.params
|
||||
.shipOrderId as BusinessAPI.OrderShipVO["shipOrderId"];
|
||||
.shipOrderId as BusinessAPI.OrderShipVO["orderShipId"];
|
||||
|
||||
const [step, setStep] = useState(1);
|
||||
const [moduleList, setModuleList] = useState<any[]>([]);
|
||||
@ -82,11 +82,11 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
|
||||
const step1FormRef = useRef<DeliveryStep1FormRef>(null);
|
||||
|
||||
const init = async (shipOrderId: BusinessAPI.OrderShipVO["shipOrderId"]) => {
|
||||
const init = async (orderShipId: BusinessAPI.OrderShipVO["orderShipId"]) => {
|
||||
setLoading(true);
|
||||
const { data } = await business.shipOrder.showShipOrder({
|
||||
shipOrderShowQry: {
|
||||
shipOrderId,
|
||||
const { data } = await business.orderShip.showOrderShip({
|
||||
orderShipShowQry: {
|
||||
orderShipId,
|
||||
},
|
||||
});
|
||||
const shipOrderVO = data.data;
|
||||
@ -141,7 +141,7 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
const updateTemplateConfig = async (
|
||||
template: any[],
|
||||
data: any,
|
||||
shipOrderVO: BusinessAPI.ShipOrderVO,
|
||||
shipOrderVO: BusinessAPI.OrderShipVO,
|
||||
) => {
|
||||
let templateList: any[] = [];
|
||||
template.map(async (module: any) => {
|
||||
@ -226,8 +226,8 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
|
||||
// 存储 至 shipOrder previewUrl
|
||||
if (shipOrderVO) {
|
||||
let formData: BusinessAPI.ShipOrderGenerateDocumentCmd = {
|
||||
shipOrderId: shipOrderVO?.shipOrderId,
|
||||
let formData: BusinessAPI.OrderShipGenerateDocumentCmd = {
|
||||
orderShipId: shipOrderVO?.orderShipId,
|
||||
document: data?.data?.path,
|
||||
};
|
||||
// 检查各模块中的必填字段是否已填写
|
||||
@ -263,11 +263,11 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
}
|
||||
// 检查品级字段是否开启且已填写
|
||||
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) {
|
||||
|
||||
@ -24,11 +24,11 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
const [step, setStep] = useState(1);
|
||||
const [moduleList, setModuleList] = useState<any[]>([]);
|
||||
const [document, setDocument] =
|
||||
useState<BusinessAPI.ShipOrderVO["document"]>();
|
||||
useState<BusinessAPI.OrderShipVO["document"]>();
|
||||
const [height, setHeight] = useState<number>();
|
||||
const [purchaseOrderVO, setPurchaseOrderVO] =
|
||||
useState<BusinessAPI.PurchaseOrderVO>();
|
||||
const [shipOrderVO, setShipOrderVO] = useState<BusinessAPI.ShipOrderVO>();
|
||||
const [shipOrderVO, setShipOrderVO] = useState<BusinessAPI.OrderShipVO>();
|
||||
|
||||
const step1FormRef = useRef<PurchaseStep1FormRef>(null);
|
||||
|
||||
@ -118,8 +118,8 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
|
||||
// 存储 至 shipOrder previewUrl
|
||||
if (shipOrderVO) {
|
||||
let formData: BusinessAPI.ShipOrderGenerateDocumentCmd = {
|
||||
shipOrderId: shipOrderVO?.shipOrderId,
|
||||
let formData: BusinessAPI.OrderShipGenerateDocumentCmd = {
|
||||
orderShipId: shipOrderVO?.orderShipId,
|
||||
document: data?.data?.path,
|
||||
};
|
||||
// 检查各模块中的必填字段是否已填写
|
||||
@ -155,11 +155,11 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
}
|
||||
// 检查品级字段是否开启且已填写
|
||||
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) {
|
||||
|
||||
@ -42,6 +42,7 @@ import {
|
||||
import { type DeliveryFormSectionRef } from "@/components/purchase/section/DeliveryFormSection";
|
||||
import {
|
||||
buildUrl,
|
||||
convertPurchaseOrderToOrderShip,
|
||||
formatCurrency,
|
||||
generateShortId,
|
||||
PurchaseOrderCalculator,
|
||||
@ -524,32 +525,41 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
});
|
||||
|
||||
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!);
|
||||
|
||||
purchaseOrderVO.orderCostList.map((item) => {
|
||||
item.price = purchaseOrderVO.orderCostItemList
|
||||
.filter((orderCost) =>
|
||||
item.costItemIds?.includes(orderCost.costItemId!),
|
||||
)
|
||||
?.reduce(
|
||||
(acc, cur) =>
|
||||
DecimalUtils.add(
|
||||
acc,
|
||||
DecimalUtils.multiply(cur.price || 0, cur.count || 0),
|
||||
),
|
||||
0,
|
||||
);
|
||||
|
||||
console.log("item", item);
|
||||
if (!item.price) {
|
||||
item.price = purchaseOrderVO.orderCostItemList
|
||||
.filter((orderCost) =>
|
||||
item.costItemIds?.includes(orderCost.costItemId!),
|
||||
)
|
||||
?.reduce(
|
||||
(acc, cur) =>
|
||||
DecimalUtils.add(
|
||||
acc,
|
||||
DecimalUtils.multiply(cur.price || 0, cur.count || 0),
|
||||
),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
console.log(
|
||||
"purchaseOrderVO.orderCostList",
|
||||
purchaseOrderVO.orderCostList,
|
||||
);
|
||||
|
||||
// 计提费
|
||||
const orderCost = purchaseOrderVO?.orderCostList.find(
|
||||
(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({
|
||||
orderCostId: generateShortId(),
|
||||
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({
|
||||
orderCostId: generateShortId(),
|
||||
costId: "",
|
||||
|
||||
@ -82,15 +82,15 @@ export class PurchaseOrderRules {
|
||||
/**
|
||||
* 获取定价方式
|
||||
*/
|
||||
getPricingMethod(): "BY_GROSS_WEIGHT" | "BY_NET_WEIGHT" {
|
||||
return this.order.pricingMethod!;
|
||||
getPricingMethod(supplier: BusinessAPI.OrderSupplier): "BY_GROSS_WEIGHT" | "BY_NET_WEIGHT" {
|
||||
return supplier.pricingMethod!;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据定价方式获取重量值
|
||||
*/
|
||||
getWeightByPricingMethod(supplier: BusinessAPI.OrderSupplier): number {
|
||||
return this.getPricingMethod() === "BY_GROSS_WEIGHT"
|
||||
return this.getPricingMethod(supplier) === "BY_GROSS_WEIGHT"
|
||||
? supplier.grossWeight || 0
|
||||
: supplier.netWeight || 0;
|
||||
}
|
||||
|
||||
@ -99,6 +99,12 @@ export class CostCalculator {
|
||||
const taxProvision = this.calculateTaxProvision();
|
||||
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(
|
||||
melonCost,
|
||||
otherCosts,
|
||||
@ -132,6 +138,7 @@ export class CostCalculator {
|
||||
private shouldIncludeCost(cost: BusinessAPI.OrderCost): boolean {
|
||||
// 运费需要特殊判断
|
||||
if (cost.name === "运费") {
|
||||
console.log("this.rules.shouldIncludeFreightCost()", this.rules.shouldIncludeFreightCost())
|
||||
return this.rules.shouldIncludeFreightCost();
|
||||
}
|
||||
|
||||
|
||||
@ -10,5 +10,5 @@ export {
|
||||
convertOrderPackagesToBoxBrands
|
||||
} from './boxBrandConverter'
|
||||
|
||||
export { convertPurchaseOrderToShipOrder } from './purchaseOrderConverter'
|
||||
export { convertPurchaseOrderToOrderShip } from './purchaseOrderConverter'
|
||||
export { convertShipOrderVOToExamplesFormat } from './shipOrderConverter'
|
||||
@ -7,7 +7,7 @@ import { DecimalUtils } from "@/utils/classes/calculators/core/DecimalUtils";
|
||||
* @param purchaseOrderVO 采购订单对象
|
||||
* @returns 发货单对象
|
||||
*/
|
||||
export const convertPurchaseOrderToShipOrder = (
|
||||
export const convertPurchaseOrderToOrderShip = (
|
||||
purchaseOrderVO: BusinessAPI.PurchaseOrderVO
|
||||
): BusinessAPI.OrderShip => {
|
||||
// 添加一个辅助函数用于分组
|
||||
|
||||
Loading…
Reference in New Issue
Block a user