feat(purchase): 优化采购模块UI与逻辑处理

- 在CostCard组件中添加了对空成本项列表的条件渲染
- 更新EmptyBoxModule和OrderPackage组件中的数组长度判断为可选链形式
- 在MelonFarmer组件中增加supplierVO的日志输出并修正isLast属性比较逻辑
- 重构OrderCost组件的成本初始化逻辑,提升性能和代码可读性
- 移除OrderCostItem组件中不必要的控制台日志
- 优化OrderCostItem组件中selected状态的赋值逻辑
- 升级Weigh组件中关于供应商字段的布尔值判断方式
- 将PurchasePreview组件中空箱使用明细的显示条件改为可选链判断
- 提升create页面中添加瓜农按钮的视觉样式与布局结构
- 更新应用版本号从v0.0.26至v0.0.28
This commit is contained in:
shenyifei 2025-12-04 17:57:10 +08:00
parent 47c7bdf357
commit 1676290798
10 changed files with 86 additions and 95 deletions

View File

@ -94,6 +94,7 @@ export default function CostCard(props: CostCardComponentProps) {
hint="点击金额可直接编辑" hint="点击金额可直接编辑"
/> />
{orderCostItemList.length > 0 && (
<View className="flex flex-1 flex-col gap-2 pl-4"> <View className="flex flex-1 flex-col gap-2 pl-4">
{orderCostItemList.map((orderCostItem) => { {orderCostItemList.map((orderCostItem) => {
return ( return (
@ -111,6 +112,7 @@ export default function CostCard(props: CostCardComponentProps) {
); );
})} })}
</View> </View>
)}
</View> </View>
</View> </View>

View File

@ -128,7 +128,7 @@ export default function EmptyBoxModule(props: IEmptyBoxModuleProps) {
initBoxBrandList().then(); initBoxBrandList().then();
setEmptyBoxList(orderPackageList); setEmptyBoxList(orderPackageList);
if (orderPackageList.length > 0) { if (orderPackageList?.length > 0) {
// 根据当前供应商确定需要检查的纸箱类型 // 根据当前供应商确定需要检查的纸箱类型
let requiredTypes: string[] = ["EMPTY"]; let requiredTypes: string[] = ["EMPTY"];

View File

@ -549,6 +549,7 @@ export default forwardRef<MelonFarmerRef, IMelonFarmerProps>(
}); });
}; };
console.log("supplierVO", supplierVO);
if (!supplierVO) { if (!supplierVO) {
return; return;
} }
@ -588,9 +589,9 @@ export default forwardRef<MelonFarmerRef, IMelonFarmerProps>(
<Radio.Group <Radio.Group
direction="horizontal" direction="horizontal"
value={ value={
supplierVO.isLast supplierVO.isLast === true
? "true" ? "true"
: !supplierVO.isLast : supplierVO.isLast === false
? "false" ? "false"
: undefined : undefined
} }

View File

@ -3,7 +3,6 @@ import { Icon } from "@/components";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { Checkbox, Input, Toast } from "@nutui/nutui-react-taro"; import { Checkbox, Input, Toast } from "@nutui/nutui-react-taro";
import { generateShortId } from "@/utils"; import { generateShortId } from "@/utils";
import { business } from "@/services";
// 定义ref暴露的方法接口 // 定义ref暴露的方法接口
export interface OrderCostRef { export interface OrderCostRef {
@ -30,38 +29,26 @@ export default forwardRef<OrderCostRef, IOrderCostProps>(
// 初始化函数 // 初始化函数
const init = async (costIds: string[]) => { const init = async (costIds: string[]) => {
let newOrderCostList: BusinessAPI.OrderCost[] = []; // 创建一个映射用于快速查找orderCostItemList中的项目
const orderCostMap = new Map<string, BusinessAPI.OrderCost>();
// 获取成本列表 orderCostList?.forEach((item) => {
const { if (item.costId && costIds.includes(item.costId)) {
data: { data: costList, success }, orderCostMap.set(item.costId, item);
} = await business.cost.listCost({ }
costListQry: {
status: true,
},
}); });
if (success) { // 构建初始列表基于costTemplate中的项目
const newCostList = costList?.filter((item) => { const newOrderCostList: IOrderCost[] = [];
return costIds.includes(item.costId);
});
// 遍历costList将costList中的项目添加到orderCostList中 // 遍历costList将costList中的项目添加到orderCostList中
newCostList?.forEach((item) => { parsedCostTemplate.productionTypeList?.forEach((item) => {
const orderCost = orderCostList.find( const existingItem = orderCostMap.get(item.costItemId);
(cost) => cost.costId === item.costId,
);
const selected = parsedCostTemplate.productionTypeList?.some( if (existingItem) {
(cost) => {
return cost.costId === item.costId;
},
);
if (orderCost) {
newOrderCostList.push({ newOrderCostList.push({
...orderCost, ...existingItem,
selected: selected, selected: !!existingItem,
}); });
} else { } else {
newOrderCostList.push({ newOrderCostList.push({
@ -70,14 +57,13 @@ export default forwardRef<OrderCostRef, IOrderCostProps>(
costId: item.costId, costId: item.costId,
name: item.name, name: item.name,
type: item.type, type: item.type,
selected: selected, selected: false,
count: 1, count: 1,
price: item.price || 0, price: item.price || 0,
unit: item.unit || "元", unit: item.unit || "元",
}); });
} }
}); });
}
onChange?.({ onChange?.({
...value, ...value,

View File

@ -47,8 +47,6 @@ export default forwardRef<OrderCostItemRef, IOrderCostItemProps>(
} }
}); });
console.log("orderCostItemList,", orderCostItemList);
// 构建初始列表基于costTemplate中的项目 // 构建初始列表基于costTemplate中的项目
const newOrderCostItemList: IOrderCostItem[] = []; const newOrderCostItemList: IOrderCostItem[] = [];
@ -62,7 +60,7 @@ export default forwardRef<OrderCostItemRef, IOrderCostItemProps>(
name: item.name, name: item.name,
price: item.price, price: item.price,
unit: item.unit, unit: item.unit,
selected: true, selected: !!existingItem,
count: existingItem?.count || 1, count: existingItem?.count || 1,
payerType: existingItem?.payerType, payerType: existingItem?.payerType,
type: item.type, type: item.type,
@ -82,7 +80,7 @@ export default forwardRef<OrderCostItemRef, IOrderCostItemProps>(
name: item.name, name: item.name,
price: item.price, price: item.price,
unit: item.unit, unit: item.unit,
selected: true, selected: !!existingItem,
count: existingItem?.count || 1, count: existingItem?.count || 1,
payerType: existingItem?.payerType, payerType: existingItem?.payerType,
type: item.type, type: item.type,
@ -90,7 +88,6 @@ export default forwardRef<OrderCostItemRef, IOrderCostItemProps>(
}); });
}); });
console.log("newOrderCostItemList,", newOrderCostItemList);
onChange?.({ onChange?.({
...value, ...value,
orderCostItemList: newOrderCostItemList, orderCostItemList: newOrderCostItemList,

View File

@ -41,7 +41,7 @@ export default forwardRef<OrderPackageRef, IOrderPackageProps>(
useEffect(() => { useEffect(() => {
// 初始化数据 // 初始化数据
if (orderPackageList.length > 0) { if (orderPackageList?.length > 0) {
// 根据当前供应商确定需要检查的纸箱类型 // 根据当前供应商确定需要检查的纸箱类型
let requiredTypes: string[] = []; let requiredTypes: string[] = [];

View File

@ -245,7 +245,7 @@ export default function PurchasePreview(props: IPurchasePreviewProps) {
</View> </View>
</View> </View>
{purchaseOrder.orderPackageList.length > 0 && ( {purchaseOrder.orderPackageList?.length > 0 && (
<> <>
<View className="text-sm font-bold">使</View> <View className="text-sm font-bold">使</View>
<View className="flex flex-col gap-2.5"> <View className="flex flex-col gap-2.5">

View File

@ -535,9 +535,9 @@ export default forwardRef<WeighRef, IWeightProps>(function Weigh(props, ref) {
<Radio.Group <Radio.Group
direction="horizontal" direction="horizontal"
value={ value={
supplierVO.isPaper supplierVO.isPaper === true
? "true" ? "true"
: !supplierVO.isPaper : supplierVO.isPaper === false
? "false" ? "false"
: undefined : undefined
} }
@ -639,7 +639,7 @@ export default forwardRef<WeighRef, IWeightProps>(function Weigh(props, ref) {
<Radio.Group <Radio.Group
direction="horizontal" direction="horizontal"
value={ value={
supplierVO.isDepositPaid supplierVO.isDepositPaid === true
? "true" ? "true"
: supplierVO.isDepositPaid === false : supplierVO.isDepositPaid === false
? "false" ? "false"

View File

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

View File

@ -1,8 +1,8 @@
import hocAuth from "@/hocs/auth"; import hocAuth from "@/hocs/auth";
import { CommonComponent } from "@/types/typings"; import {CommonComponent} from "@/types/typings";
import { View } from "@tarojs/components"; import {View} from "@tarojs/components";
import { purchase } from "@/constant"; import {purchase} from "@/constant";
import { useEffect, useRef, useState } from "react"; import {useEffect, useRef, useState} from "react";
import { import {
Icon, Icon,
MelonFarmer, MelonFarmer,
@ -22,10 +22,10 @@ import {
Weigh, Weigh,
WeighRef, WeighRef,
} from "@/components"; } from "@/components";
import { business } from "@/services"; import {business} from "@/services";
import { buildUrl, generateShortId, SupplierWeightCalculator } from "@/utils"; import {buildUrl, generateShortId, SupplierWeightCalculator} from "@/utils";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import { Button } from "@nutui/nutui-react-taro"; import {Button} from "@nutui/nutui-react-taro";
const defaultSupplierList: Partial<BusinessAPI.OrderSupplier>[] = [ const defaultSupplierList: Partial<BusinessAPI.OrderSupplier>[] = [
{ {
@ -422,6 +422,9 @@ export default hocAuth(function Page(props: CommonComponent) {
purchaseOrder?.orderSupplierList[ purchaseOrder?.orderSupplierList[
purchaseOrder?.orderSupplierList.length - 1 purchaseOrder?.orderSupplierList.length - 1
]?.isLast && ( ]?.isLast && (
<View className="flex flex-1 flex-col gap-2.5 bg-[#D1D5DB] p-2.5 pt-2.5">
<View className={"flex flex-1 flex-col gap-2.5"}>
<View className="text-sm font-bold"></View>
<Button <Button
icon={<Icon name={"plus"} size={20} />} icon={<Icon name={"plus"} size={20} />}
type={"primary"} type={"primary"}
@ -435,6 +438,8 @@ export default hocAuth(function Page(props: CommonComponent) {
> >
<View></View> <View></View>
</Button> </Button>
</View>
</View>
)} )}
</View> </View>