import hocAuth from "@/hocs/auth"; import { CommonComponent } from "@/types/typings"; import Taro from "@tarojs/taro"; import { business } from "@/services"; import { useEffect, useState } from "react"; import { View } from "@tarojs/components"; import { Button, SafeArea } from "@nutui/nutui-react-taro"; import { Icon, OrderFinalApprove, OrderRejectFinal } from "@/components"; import { buildUrl, OrderCalculator } from "@/utils"; import { DecimalUtils } from "@/utils/classes/calculators/core/DecimalUtils"; import dayjs from "dayjs"; import classNames from "classnames"; export default hocAuth(function Page(props: CommonComponent) { const { router, isInitialized, setIsInitialized, setLoading } = props; const orderId = router.params.orderId as BusinessAPI.OrderVO["orderId"]; const auditId = router.params.auditId as BusinessAPI.AuditVO["auditId"]; const [auditVO, setAuditVO] = useState(); const [orderVO, setOrderVO] = useState(); // 控制供应商采购单价列表展开状态 const [showAllSuppliers, setShowAllSuppliers] = useState(false); const init = async ( orderId: BusinessAPI.OrderVO["orderId"], auditId: BusinessAPI.AuditVO["auditId"], ) => { const { data: { data: auditVO, success: auditSuccess }, } = await business.audit.showAudit({ auditShowQry: { auditId, }, }); if (auditSuccess && auditVO) { setAuditVO(auditVO); } const { data: { data: orderVO, success: orderSuccess }, } = await business.order.showOrder({ orderShowQry: { orderId, }, }); if (orderSuccess) { setOrderVO(orderVO); } }; useEffect(() => { if (orderId && auditId && !isInitialized) { setLoading(true); init(orderId, auditId).then(() => { setIsInitialized(true); setLoading(false); }); } }, []); if (!orderVO) { return; } const calculator = new OrderCalculator(orderVO); let totalCost: number; const totalWeight = calculator.getTotalWeight(); const shouldIncludeFreightCost = calculator .getRules() .shouldIncludeFreightCost(); // 判断采购成本是否包含运费,包含运费说明已经加过一次了 if (calculator.getRules().shouldIncludeFreightCost()) { totalCost = calculator.getCostCalculator().calculateTotalPurchaseCost(true); } else { totalCost = calculator.getCostCalculator().calculateTotalPurchaseCost(); } const unitCost = totalWeight > 0 ? DecimalUtils.toDecimalPlaces( DecimalUtils.divide(totalCost, totalWeight), 2, ) : 0; const estimatedArrivalDate = orderVO.orderShipList[0].estimatedArrivalDate; const personalProfit = calculator.getPersonalProfit(); return ( <> {auditVO?.state === "AUDIT_REJECTED" && ( 驳回原因 {auditVO?.auditReason || "暂无驳回原因"} )} 收购单价 {/**/} {/* */} {/* {calculator.getAveragePurchasePrice()}*/} {/* */} {/* 元/斤*/} {/**/} {/* 供应商采购单价列表 */} {orderVO.orderSupplierList && orderVO.orderSupplierList.length > 0 && ( {orderVO.orderSupplierList .slice(0, showAllSuppliers ? undefined : 3) .map((supplier) => ( {supplier.name} {supplier.purchasePrice || 0} 元/斤 ))} {/* 查看更多按钮 */} {orderVO.orderSupplierList.length > 3 && ( setShowAllSuppliers(!showAllSuppliers)} > {showAllSuppliers ? "收起" : "查看更多"} )} )} 市场报价 {calculator.getAverageSalesPrice()} 元/斤 采购信息 {/* 采购单号,采购类型 */} 经销商 {orderVO.orderVehicle.dealerName}{" "} {orderVO?.orderVehicle?.vehicleNo ? "第" + orderVO.orderVehicle.vehicleNo + "车" : "暂未生成车次"} 采购类型 {orderVO.type === "PRODUCTION_PURCHASE" ? "产地采购单" : "市场采购单"} 成本明细 到货日期: {estimatedArrivalDate ? dayjs(estimatedArrivalDate).format("YYYY-MM-DD") : "暂无"} 市场报价 ¥{calculator.getMarketPrice()} 元 西瓜采购成本 ¥{calculator.getSupplierPurchaseCost()} 元 {orderVO.orderCostList .filter((item) => { return ( item.price * item.count > 0 && item.name !== "付瓜农定金" ); }) .map((item) => { return ( {item.name} ¥{item.price * item.count} 元 {item.name === "人工费" && ( 工头: {orderVO.foreman} )} ); })} {orderVO.orderDealer?.enableLoss && Number(orderVO.orderDealer?.lossAmount) > 0 && ( 损耗金额 ¥{orderVO.orderDealer?.lossAmount} 元 )} {Number(orderVO.orderDealer?.taxProvision || 0) > 0 && ( 计提税金 ¥{orderVO.orderDealer?.taxProvision} 元 )} {Number(orderVO.orderDealer?.taxSubsidy || 0) > 0 && ( 公司返点 ¥{orderVO.orderDealer?.taxSubsidy} 元 )} {orderVO.orderRebate && Number(orderVO.orderRebate.amount || 0) > 0 && ( 个人返点 ¥{orderVO.orderRebate?.amount} 元 )} {Number(orderVO.orderDealer?.costDifference || 0) > 0 && ( 调诚信志远分成 ¥{orderVO.orderDealer?.costDifference} 元 )} 成本合计( {shouldIncludeFreightCost ? "包含运费" : "不包含运费"}) ¥{totalCost} 元 成本单价 ¥{unitCost} 元/斤 利润 0, "text-red-500": personalProfit < 0, })} > ¥{personalProfit} 元 {/* 按钮操作 */} {auditVO?.type === "BOSS_AUDIT" && auditVO.state === "WAITING_AUDIT" && ( <> { // 返回首页 Taro.redirectTo({ url: "/pages/approval/pending", }); }} /> { // 关闭当前页面并跳转到采购单审核通过页面 Taro.redirectTo({ url: buildUrl(`/pages/approval/result`, { orderId: orderVO?.orderId, }), }); }} /> )} ); });