import hocAuth from "@/hocs/auth"; import { CommonComponent } from "@/types/typings"; import { useEffect, useRef, useState } from "react"; import { Text, View } from "@tarojs/components"; import { Button, DatePicker, Dialog, Input, PickerOption, SafeArea, Step, Steps, Toast, } from "@nutui/nutui-react-taro"; import shipOrder from "@/constant/shipOrder"; import Taro from "@tarojs/taro"; import classNames from "classnames"; import { business } from "@/services"; import dayjs from "dayjs"; export default hocAuth(function Page(props: CommonComponent) { const { router, setLoading } = props; const shipOrderId = router.params .shipOrderId as BusinessAPI.ShipOrderVO["shipOrderId"]; // 获取当年的第一天和今天,用于限制日期选择范围 const currentYear = new Date().getFullYear(); const startDate = new Date(currentYear, 0, 1); // 当年第一天 const endDate = new Date(); // 今天 const [show, setShow] = useState(false); const formatter = (type: string, option: PickerOption) => { switch (type) { case "year": option.label += "年"; break; case "month": option.label += "月"; break; case "day": option.label += "日"; break; case "hour": option.label += "时"; break; case "minute": option.label += "分"; break; default: break; } return option; }; const [scale, setScale] = useState(0.5); // 缩放比例 const [step, setStep] = useState(1); const [moduleList, setModuleList] = useState([]); const [height, setHeight] = useState(); const [shipOrderVO, setShipOrderVO] = useState(); const [deliveryTemplate, setDeliveryTemplate] = useState(); const [previewUrl, setPreviewUrl] = useState(); // 表单错误状态 const [formErrors, setFormErrors] = useState<{ watermelonGrade?: boolean; shippingAddress?: boolean; estimatedArrivalDate?: boolean; remark?: boolean; itemGrades?: { [key: string]: boolean }; }>({}); const init = async (shipOrderId: BusinessAPI.ShipOrderVO["shipOrderId"]) => { const { data } = await business.shipOrder.showShipOrder({ shipOrderShowQry: { shipOrderId, }, }); const shipOrderVO = data.data; if (shipOrderVO) { setShipOrderVO(shipOrderVO); const { data } = await business.dealer.showDealer({ dealerShowQry: { dealerId: shipOrderVO.dealerId, }, }); setDeliveryTemplate(data.data?.deliveryTemplate!); } }; useEffect(() => { if (shipOrderId) { init(shipOrderId).then(); } }, [shipOrderId]); useEffect(() => { if (deliveryTemplate && shipOrderVO) { const template = JSON.parse(deliveryTemplate); // 将 shipOrderVO 转换为 examples 的数据格式,然后再替换 moduleList 里面的 config 数据 const convertedData = convertShipOrderVOToExamplesFormat(shipOrderVO); const updatedTemplate = updateTemplateConfig(template, convertedData); setModuleList(updatedTemplate); } }, [shipOrderVO, deliveryTemplate]); const [touchInfo, setTouchInfo] = useState({ startDistance: 0, startScale: 0.5, }); // 触摸信息 const [position, setPosition] = useState({ x: 0, y: -(29.7 * 37.8 * 0.5) }); // 当前位置 const [startPosition, setStartPosition] = useState({ x: 0, y: 0 }); // 起始位置 // 将 shipOrderVO 转换为 examples 的数据格式 const convertShipOrderVOToExamplesFormat = ( shipOrderVO: BusinessAPI.ShipOrderVO, ) => { return { title: { title: "西瓜发货清单", }, dealerInfo: { dealerName: shipOrderVO.dealerName || "", vehicleNumber: shipOrderVO.vehicleNo || "", destination: shipOrderVO.receivingAddress || "", watermelonGrade: shipOrderVO.watermelonGrade || "", }, shippingInfo: { shippingFrom: shipOrderVO.shippingAddress || "", date: shipOrderVO.shippingDate || "", }, weightInfo: { data: shipOrderVO.shipOrderItemList, accountCompany: "", sumAmount: shipOrderVO.shipOrderItemList?.reduce( (acc, item) => acc + item?.totalAmount!, 0, ) || "", }, packingSpec: { data: shipOrderVO.shipOrderPackageList?.map((item) => ({ boxCategory: item.boxCategory || "", boxType: item.boxProduct || "", quantity: item.quantity?.toString() || "", unitPrice: item.unitPrice?.toString() || "", amount: item.itemAmount?.toString() || "", unitWeight: item.singleWeight?.toString() || "", weight: item.totalWeight?.toString() || "", })) || [], }, vehicleInfo: { driverPhone: shipOrderVO?.driverPhone || "", licensePlate: shipOrderVO.licensePlate || "", estimatedArrivalTime: shipOrderVO.estimatedArrivalDate ? dayjs(shipOrderVO?.estimatedArrivalDate).format("YYYY年MM月DD日") : "", freightDebt: shipOrderVO.freightDebt?.toString() || "", strawMatDebt: shipOrderVO.strawMatDebt?.toString() || "", remarks: shipOrderVO.remark || "", }, otherFees: { trademark: shipOrderVO.trademarkFee?.toString() || "", labor: shipOrderVO.laborFee?.toString() || "", paperBox: shipOrderVO.cartonFee?.toString() || "", fee: shipOrderVO.provisionFee?.toString() || "", codingFee: shipOrderVO.codingFee?.toString() || "", }, totalAmount: { amount: shipOrderVO.totalAmount?.toString() || "", farmer: shipOrderVO.farmerInfo || "", }, otherInfo: { origin: "", supplier: "", departureTime: "", arrivalTime: "", productName: "", }, }; }; // 更新模板配置 const updateTemplateConfig = (template: any[], data: any) => { return template.map((module: any) => { const newModule = { ...module }; if (data[module.type]) { newModule.config = { ...module.config, ...data[module.type] }; } return newModule; }); }; // 渲染内容配置表单字段 const renderContentFields = (module) => { const contentSchema = module.schemas.find( (schema) => schema.title === "内容配置", ); if ( !contentSchema || !contentSchema.columns || contentSchema.columns.length === 0 ) { return null; } return ( {contentSchema.columns.map((column, index) => { return ( {column.title} {column.dataIndex === "requiredWatermelonGrade" && ( { // 清除错误状态 if (formErrors.watermelonGrade && value) { setFormErrors((prev) => ({ ...prev, watermelonGrade: false, })); } setShipOrderVO((prev) => { return { ...prev!, watermelonGrade: value, }; }); }} onBlur={() => { // 失焦时校验 if (!shipOrderVO?.watermelonGrade) { setFormErrors((prev) => ({ ...prev, watermelonGrade: true, })); Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } }} placeholder={ column.fieldProps?.placeholder || `请${column.title}` } type="text" className="flex-1" /> {formErrors.watermelonGrade && ( {`请${column.title}`} )} )} {column.dataIndex === "requiredShippingFrom" && ( { // 清除错误状态 if (formErrors.shippingAddress && value) { setFormErrors((prev) => ({ ...prev, shippingAddress: false, })); } setShipOrderVO((prev) => { return { ...prev!, shippingAddress: value, }; }); }} onBlur={() => { // 失焦时校验 if (!shipOrderVO?.shippingAddress) { setFormErrors((prev) => ({ ...prev, shippingAddress: true, })); Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } }} placeholder={ column.fieldProps?.placeholder || `请${column.title}` } type="text" className="flex-1" /> {formErrors.shippingAddress && ( {`请${column.title}`} )} )} {column.dataIndex === "requiredEstimatedArrivalTime" && ( setShow(true)} onBlur={() => { // 失焦时校验 if (!shipOrderVO?.estimatedArrivalDate) { setFormErrors((prev) => ({ ...prev, estimatedArrivalDate: true, })); Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请选择${column.title}`, }); } }} /> setShow(false)} onConfirm={(_, values) => { // 选择日期后清除错误状态 if (formErrors.estimatedArrivalDate) { setFormErrors((prev) => ({ ...prev, estimatedArrivalDate: false, })); } setShipOrderVO((prev) => { return { ...prev!, estimatedArrivalDate: dayjs( values.join("-"), ).format("YYYY-MM-DD"), }; }); }} /> {formErrors.estimatedArrivalDate && ( {`请${column.title}`} )} )} {column.dataIndex === "requiredRemarks" && ( { // 清除错误状态 if (formErrors.remark && value) { setFormErrors((prev) => ({ ...prev, remark: false, })); } setShipOrderVO((prev) => { return { ...prev!, remark: value, }; }); }} onBlur={() => { // 失焦时校验 if (!shipOrderVO?.remark) { setFormErrors((prev) => ({ ...prev, remark: true, })); Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } }} placeholder={ column.fieldProps?.placeholder || `请${column.title}` } type="text" className="flex-1" /> {formErrors.remark && ( {`请${column.title}`} )} )} {column.dataIndex === "requiredGrade" && ( <> {shipOrderVO?.shipOrderItemList?.map( (shipOrderItem, index) => { return ( 单价:{shipOrderItem.unitPrice} 元/斤 { // 清除该项的错误状态 if ( formErrors.itemGrades?.[ shipOrderItem.itemId ] && value ) { setFormErrors((prev) => ({ ...prev, itemGrades: { ...prev.itemGrades, [shipOrderItem.itemId]: false, }, })); } setShipOrderVO((prev) => { return { ...prev!, shipOrderItemList: prev?.shipOrderItemList?.map((item) => { if ( item.itemId === shipOrderItem.itemId ) { return { ...item, watermelonGrade: value, }; } return item; }), }; }); }} onBlur={() => { // 失焦时校验 if (!shipOrderItem.watermelonGrade) { setFormErrors((prev) => ({ ...prev, itemGrades: { ...prev.itemGrades, [shipOrderItem.itemId]: true, }, })); Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写第${index + 1}项的品级`, }); } }} placeholder={ column.fieldProps?.placeholder || `请${column.title}` } type="text" className="flex-1" /> {formErrors.itemGrades?.[shipOrderItem.itemId] && ( {`请${column.title}`} )} ); }, )} )} ); })} ); }; // 表单校验 const validateForm = () => { const errors: any = {}; let hasErrors = false; // 检查各模块中的必填字段是否已填写 for (const module of moduleList) { const contentSchema = module.schemas.find( (schema) => schema.title === "内容配置", ); if ( !contentSchema || !contentSchema.columns || contentSchema.columns.length === 0 ) { continue; } for (const column of contentSchema.columns) { // 检查西瓜品级字段是否开启且已填写 if (column.dataIndex === "requiredWatermelonGrade") { if (!shipOrderVO?.watermelonGrade) { errors.watermelonGrade = true; hasErrors = true; Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } } // 检查发货地字段是否开启且已填写 else if (column.dataIndex === "requiredShippingFrom") { if (!shipOrderVO?.shippingAddress) { errors.shippingAddress = true; hasErrors = true; Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } } // 检查预计到仓时间字段是否开启且已填写 else if (column.dataIndex === "requiredEstimatedArrivalTime") { if (!shipOrderVO?.estimatedArrivalDate) { errors.estimatedArrivalDate = true; hasErrors = true; Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请选择${column.title}`, }); } } // 检查备注字段是否开启且已填写 else if (column.dataIndex === "requiredRemarks") { if (!shipOrderVO?.remark) { errors.remark = true; hasErrors = true; Toast.show("toast", { icon: "fail", title: column.fieldProps?.placeholder || `请填写${column.title}`, }); } } // 检查品级字段是否开启且已填写 else if (column.dataIndex === "requiredGrade") { if (shipOrderVO?.shipOrderItemList) { const itemGradesErrors: { [key: string]: boolean } = {}; for (let i = 0; i < shipOrderVO.shipOrderItemList.length; i++) { const item = shipOrderVO.shipOrderItemList[i]; if (!item.watermelonGrade) { itemGradesErrors[item.itemId] = true; hasErrors = true; Toast.show("toast", { icon: "fail", title: `请填写第${i + 1}项的品级`, }); } } if (Object.keys(itemGradesErrors).length > 0) { errors.itemGrades = itemGradesErrors; } } } } } setFormErrors(errors); return !hasErrors; }; // 预览确认 const previewAndConfirm = () => { console.log(step); if (step === 1) { // 在第一步时校验表单 if (!validateForm()) { return; } } if (step === 2) { // 显示确认对话框 Dialog.open("dialog", { title: "生成发货单据", content: "即将生成发货单据,请确认发货单据是否正确。", confirmText: "确认生成", cancelText: "取消", onConfirm: async () => { // 截图预览内容 await capturePreview(); Dialog.close("dialog"); // 进入第三步 setStep(3); }, onCancel: () => { Dialog.close("dialog"); }, }); return; } if (step < 3) { setStep(step + 1); } }; // 生成发货单据 const generateShippingDocument = async () => { // 显示确认对话框 Dialog.open("dialog", { title: "生成发货单据", content: "即将生成发货单据,请确认发货单据是否正确。", confirmText: "确认生成", cancelText: "取消", onConfirm: async () => { // 截图预览内容 await capturePreview(); Dialog.close("dialog"); // 进入第三步 setStep(3); }, onCancel: () => { Dialog.close("dialog"); }, }); }; // 将预览内容转换为HTML字符串的函数 const generateHtmlString = () => { let htmlString = `
`; moduleList.forEach((module) => { const config = module.config; if (module.type === "title") { htmlString += `
${config.title || ""}
`; } if (module.type === "dealerInfo") { htmlString += `
`; if (config.showDealerName || config.showWatermelonGrade) { htmlString += `
${ config.showWatermelonGrade ? `${config.dealerName || ""}-${config.watermelonGrade || ""}` : config.dealerName || "" }
`; } else { htmlString += `
`; } if (config.showDestination || config.showVehicleNumber) { htmlString += `
${config.destination || ""} ${config.vehicleNumber || ""}
`; } else { htmlString += `
`; } htmlString += `
`; } if (module.type === "shippingInfo") { htmlString += `
`; if (config.showShippingFrom) { htmlString += `
发货地:
${config.shippingFrom || ""}
`; } if (config.showDate) { htmlString += `
日期:
${config.date || ""}
`; } htmlString += `
`; } if (module.type === "weightInfo") { if (config.data) { config.data.forEach((item: any) => { htmlString += `
`; if (config.showNetWeight) { htmlString += `
净重:
${item.netWeight || ""}
${config.netWeightUnit === "1" ? "斤" : "公斤"}
`; } if (config.showBoxWeight) { htmlString += `
箱重:
${item.boxWeight || ""}
${config.boxWeightUnit === "1" ? "斤" : "公斤"}
`; } if (config.showGrossWeight) { htmlString += `
毛重:
${item.grossWeight || ""}
${config.grossWeightUnit === "1" ? "斤" : "公斤"}
`; } if (config.showUnitPrice) { htmlString += `
单价:
${item.unitPrice || ""}
${config.unitPriceUnit === "1" ? "元/斤" : "元/公斤"}
`; } if (config.showAmount) { htmlString += `
金额:
${item.totalAmount || ""}
`; } if (config.showGrade) { htmlString += `
品级:
${item.watermelonGrade || ""}
`; } htmlString += `
`; }); } htmlString += `
`; if (config.showAccountCompany) { htmlString += `
入账公司:
${config.accountCompany || ""}
`; } if (config.showSumAmount) { htmlString += `
总计:
${config.sumAmount || ""}
`; } htmlString += `
`; } if (module.type === "packingSpec") { htmlString += `
`; // 计算需要显示的列数 const visibleColumnCount = [ config.showBoxType, config.showQuantity, config.showUnitPrice, config.showAmount, config.showUnitWeight, config.showWeight, ].filter(Boolean).length + 1; // +1 是因为"规格:"列总是显示 const gridClass = `grid w-full gap-0 text-base grid-cols-${visibleColumnCount}`; htmlString += `
规格:
`; htmlString += `
`; if (config.columns) { config.columns.forEach((column: any, index: number) => { if (index === 0) { htmlString += `
 
`; return; } if ( (column.dataIndex === "boxType" && config.showBoxType) || (column.dataIndex === "quantity" && config.showQuantity) || (column.dataIndex === "unitPrice" && config.showUnitPrice) || (column.dataIndex === "amount" && config.showAmount) || (column.dataIndex === "unitWeight" && config.showUnitWeight) || (column.dataIndex === "weight" && config.showWeight) ) { htmlString += `
${column.title || ""}
`; } }); } htmlString += `
`; htmlString += `
`; if (config.data) { config.data.forEach((item: any, index: number) => { htmlString += `
${ item.boxCategory === "FOUR_GRAIN" ? "4粒装" : item.boxCategory === "TWO_GRAIN" ? "2粒装" : "未知" }
`; htmlString += `
${item.boxType || ""}
`; if (config.showQuantity) { htmlString += `
${item.quantity || ""}
`; } if (config.showUnitPrice) { htmlString += `
${item.unitPrice || ""}
`; } if (config.showAmount) { htmlString += `
${item.amount || ""}
`; } if (config.showUnitWeight) { htmlString += `
${item.unitWeight || ""}
`; } if (config.showWeight) { htmlString += `
${item.weight || ""}
`; } htmlString += `
`; }); } htmlString += `
总件数
`; if (config.showQuantity) { htmlString += `
${ config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.quantity || 0), 0, ) || 0 }
`; } if (config.showUnitPrice) { htmlString += `
`; } if (config.showAmount) { htmlString += `
${ config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.amount || 0), 0, ) || 0 }
`; } if (config.showUnitWeight) { htmlString += `
`; } if (config.showWeight) { htmlString += `
${ config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.weight || 0), 0, ) || 0 }
`; } htmlString += `
`; htmlString += `
`; } if (module.type === "vehicleInfo") { htmlString += `
`; if (config.showDriverPhone) { htmlString += `
司机号码:
${config.driverPhone || ""}
`; } if (config.showLicensePlate) { htmlString += `
车牌:
${config.licensePlate || ""}
`; } if (config.showEstimatedArrivalTime) { htmlString += `
预计到仓时间:
${config.estimatedArrivalTime || ""}
`; } if (config.showRemarks) { htmlString += `
备注:
${config.remarks || ""}
`; } if (config.showFreightDebt) { htmlString += `
${config.freightDebtTitle || "运费欠"}:
${config.freightDebt || ""}
`; } if (config.showStrawMatDebt) { htmlString += `
草帘欠:
${config.strawMatDebt || ""}
`; } htmlString += `
`; } if (module.type === "otherFees") { htmlString += `
`; if (config.feeItems) { config.feeItems.forEach((feeType: any) => { htmlString += `
${(config.feeLabels && config.feeLabels[feeType]) || ""}:
${config[feeType] || ""}元
`; }); } htmlString += `
`; } if (module.type === "totalAmount") { htmlString += `
`; if (config.showTotalAmount) { htmlString += `
${config.sumTitle || "合计金额"}:
${config.amount || ""}
`; } if (config.showFarmer) { htmlString += `
瓜农:
${config.farmer || ""}
`; } htmlString += `
`; } if (module.type === "otherInfo") { htmlString += `
产地:
${config.origin || ""}
供应商:
${config.supplier || ""}
发车时间:
${config.departureTime || ""}
到达时间:
${config.arrivalTime || ""}
产品名称:
${config.productName || ""}
`; } }); htmlString += `
`; return htmlString; }; // 截图预览内容 const capturePreview = async () => { // 请求 poster.qilincloud168.com/api/v1/pdfs 接口 请求参数是 html 内容 的json 格式响应结果为 // 调用API生成PDF const { data } = await Taro.request({ url: "https://poster.qilincloud168.com/api/v1/pdf", method: "POST", header: { "content-type": "application/json", }, data: { html: generateHtmlString(), }, }); if (data && data.path) { setPreviewUrl(data.path); // 保存到系统相册 Taro.downloadFile({ url: data.path, }).then((downloadRes) => { if (downloadRes.tempFilePath) { Taro.saveImageToPhotosAlbum({ filePath: downloadRes.tempFilePath, complete: (res) => { console.log("saveImageToPhotosAlbum", res); }, }) .then(() => { Taro.showToast({ title: "发货单据已保存到相册,您可以将生成的PDF发送给好友", icon: "none", duration: 3000, }); }) .catch((e) => { console.log("e", e); Taro.showToast({ title: "保存失败", icon: "none", duration: 3000, }); }); } }); } }; // 返回上一步 const goToPrevStep = () => { if (step > 0) { setStep(step - 1); } }; // 重置表单 const resetForm = () => { setStep(1); // 重置表单错误状态 setFormErrors({}); // 重新加载初始数据 if (shipOrderId) { setLoading(true); init(shipOrderId).then(() => { setLoading(false); }); } }; // 重新生成单据 const regenerateDocument = () => { setStep(1); }; // 放大 const zoomIn = () => { setScale((prev) => Math.min(prev + 0.1, 3)); // 最大放大到3倍 }; // 缩小 const zoomOut = () => { setScale((prev) => Math.max(prev - 0.1, 0.5)); // 最小缩小到0.5倍 }; // 重置缩放 const resetZoom = () => { setScale(0.5); setPosition({ x: 0, y: -(29.7 * 37.8 * 0.5) }); // 重置位置 }; // 计算两点间距离 const getDistance = (touches) => { const dx = touches[0].clientX - touches[1].clientX; const dy = touches[0].clientY - touches[1].clientY; return Math.sqrt(dx * dx + dy * dy); }; // 处理触摸开始事件 const handleTouchStart = (e) => { const touches = e.touches; if (touches.length === 2) { // 双指触摸,记录初始距离和当前缩放值 const distance = getDistance(touches); setTouchInfo({ startDistance: distance, startScale: scale, }); } else if (touches.length === 1) { // 单指触摸,记录起始位置 setStartPosition({ x: touches[0].clientX - position.x, y: touches[0].clientY - position.y, }); } }; // 处理触摸移动事件 const handleTouchMove = (e) => { const touches = e.touches; e.preventDefault(); // 阻止默认滚动行为 if (touches.length === 2) { // 双指触摸,计算缩放比例 const currentDistance = getDistance(touches); const newScale = touchInfo.startScale * (currentDistance / touchInfo.startDistance); // 限制缩放范围在0.5到3之间 setScale(Math.min(Math.max(0.5, newScale), 3)); } else if (touches.length === 1 && scale > 0.5) { // 单指触摸且已放大,允许拖动 setPosition({ x: touches[0].clientX - startPosition.x, y: touches[0].clientY - startPosition.y, }); } }; // 处理触摸结束事件 const handleTouchEnd = (e) => { // 可以在这里添加触摸结束后的处理逻辑 console.log("Touch ended", e); }; const [topBarHeight, setTopBarHeight] = useState(0); const [bottomBarHeight, setBottomBarHeight] = useState(0); const topBarRef = useRef(null); const bottomBarRef = useRef(null); // 处理下载功能 const handleDownload = async () => { Taro.showToast({ title: "正在生成并下载发货单据", icon: "none", duration: 2000, }); // 调用capturePreview函数生成并下载PDF await capturePreview(); }; // 处理分享功能 const handleShare = async () => { Taro.showToast({ title: "正在分享到微信", icon: "none", duration: 2000, }); if (previewUrl) { // 保存到系统相册 Taro.downloadFile({ url: previewUrl, }).then((downloadRes) => { console.log("downloadRes", downloadRes); if (downloadRes.tempFilePath) { // 下载完成后转发 Taro.shareFileMessage({ filePath: downloadRes.tempFilePath, complete: (res) => { console.log("complete", res); }, }); } }); } }; useEffect(() => { // 获取 topBar 和 bottomBar 的实际高度 const queryTopBar = Taro.createSelectorQuery(); queryTopBar .select("#topBar") .boundingClientRect((rect: any) => { if (rect) { setTopBarHeight(rect.height); } }) .exec(); const queryBottomBar = Taro.createSelectorQuery(); queryBottomBar .select("#bottomBar") .boundingClientRect((rect: any) => { if (rect) { setBottomBarHeight(rect.height); } }) .exec(); }, [step]); useEffect(() => { // 计算滚动区域高度:窗口高度 - topBar高度 - bottomBar高度 const windowHeight = Taro.getSystemInfoSync().windowHeight; setHeight(windowHeight - topBarHeight - bottomBarHeight); }, [topBarHeight, bottomBarHeight]); return ( {shipOrder.steps.map((item, index) => ( ))} {step === 1 && ( {moduleList.map((module) => { const contentFields = renderContentFields(module); // 如果没有内容配置字段,则不渲染该模块 if (!contentFields) return null; return ( {module.title} {contentFields} ); })} )} {step === 2 && ( {/* 缩放控制按钮 */} {Math.round(scale * 100)}% {/* 预览区域 */} {moduleList.map((module) => { const config = module.config; if (module.type === "title") { return ( {config.title} ); } if (module.type === "dealerInfo") { return ( {config.showDealerName || config.showWatermelonGrade ? ( {config.showWatermelonGrade ? `${config.dealerName}-${config.watermelonGrade}` : config.dealerName} ) : ( )} {config.showDestination || config.showVehicleNumber ? ( {config.destination} {config.vehicleNumber} ) : ( )} ); } if (module.type === "shippingInfo") { return ( {config.showShippingFrom && ( <> 发货地: {config.shippingFrom} )} {config.showDate && ( <> 日期: {config.date} )} ); } if (module.type === "weightInfo") { return ( <> {config.data?.map((item: any, index: number) => { return ( {config.showNetWeight && ( 净重: {item.netWeight} {config.netWeightUnit === "1" ? "斤" : "公斤"} )} {config.showBoxWeight && ( 箱重: {item.boxWeight} {config.boxWeightUnit === "1" ? "斤" : "公斤"} )} {config.showGrossWeight && ( 毛重: {item.grossWeight} {config.grossWeightUnit === "1" ? "斤" : "公斤"} )} {config.showUnitPrice && ( 单价: {item.unitPrice} {config.unitPriceUnit === "1" ? "元/斤" : "元/公斤"} )} {config.showAmount && ( 金额: {item.totalAmount} )} {config.showGrade && ( 品级: {item.watermelonGrade} )} ); })} {config.showAccountCompany && ( 入账公司: {config.accountCompany} )} {config.showSumAmount && ( 总计: {config.sumAmount} )} ); } if (module.type === "packingSpec") { // 计算需要显示的列数 const visibleColumnCount = [ config.showBoxType, config.showQuantity, config.showUnitPrice, config.showAmount, config.showUnitWeight, config.showWeight, ].filter(Boolean).length + 1; // +1 是因为"规格:"列总是显示 return ( <>
规格:
{config.columns.map((column: any, index: number) => { if (index === 0) { return (
 
); } if ( (column.dataIndex === "boxType" && config.showBoxType) || (column.dataIndex === "quantity" && config.showQuantity) || (column.dataIndex === "unitPrice" && config.showUnitPrice) || (column.dataIndex === "amount" && config.showAmount) || (column.dataIndex === "unitWeight" && config.showUnitWeight) || (column.dataIndex === "weight" && config.showWeight) ) { return (
{column.title}
); } return <>; })}
{config.data?.map((item: any, index: number) => ( 0, }, )} > {item.boxCategory === "FOUR_GRAIN" ? "4粒装" : item.boxCategory === "TWO_GRAIN" ? "2粒装" : "未知"} {item.boxType} {config.showQuantity && ( {item.quantity} )} {config.showUnitPrice && ( {item.unitPrice} )} {config.showAmount && ( {item.amount} )} {config.showUnitWeight && ( {item.unitWeight} )} {config.showWeight && ( {item.weight} )} ))} 总件数 {config.showQuantity && ( {config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.quantity), 0, )} )} {config.showUnitPrice && ( )} {config.showAmount && ( {config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.amount), 0, )} )} {config.showUnitWeight && ( )} {config.showWeight && ( {config.data?.reduce( (acc: any, cur: any) => acc + Number(cur.weight), 0, )} )} ); } if (module.type === "vehicleInfo") { return ( {config.showDriverPhone && ( <> 司机号码: {config.driverPhone} )} {config.showLicensePlate && ( <> 车牌: {config.licensePlate} )} {config.showEstimatedArrivalTime && ( <> 预计到仓时间: {config.estimatedArrivalTime} )} {config.showRemarks && ( <> 备注: {config.remarks} )} {config.showFreightDebt && ( <> {config.freightDebtTitle || "运费欠"}: {config.freightDebt} )} {config.showStrawMatDebt && ( <> 草帘欠: {config.strawMatDebt} )} ); } if (module.type === "otherFees") { return ( {config.feeItems?.map((feeType: any) => ( <> {config.feeLabels[feeType]}: {config[feeType]}元 ))} ); } if (module.type === "totalAmount") { return ( {config.showTotalAmount && ( <> {config.sumTitle || "合计金额"}: {config.amount} )} {config.showFarmer && ( <> 瓜农: {config.farmer} )} ); } if (module.type === "otherInfo") { return ( 产地: {config.origin} 供应商: {config.supplier} 发车时间: {config.departureTime} 到达时间: {config.arrivalTime} 产品名称: {config.productName} ); } })}
)} {step === 3 && previewUrl && ( 发货单据生成成功 您的发货单据已生成,可以下载或转发给好友 提示:您可以随时在发货单据列表中重新下载 )}
{/* 步骤控制按钮 */} {step == 1 && ( )} {step == 1 && ( )} {step == 2 && ( )} {step == 2 && ( )} {step == 3 && ( )} {step == 3 && ( )}
); });