From 6aad692714b207c79a9913be48065bdf9fa6aa9c Mon Sep 17 00:00:00 2001 From: 陈鑫涛 <10125295+chen-xintao97@user.noreply.gitee.com> Date: Tue, 1 Jul 2025 17:21:05 +0800 Subject: [PATCH] 增加四舍五入计算 --- src/components/Common/CommonComponent/index.js | 2 ++ src/components/Common/Typesetting/typesetting.js | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------ src/components/QuickQuote/index.jsx | 18 +++++++++--------- src/mobile/quotation/detailNew.jsx | 1 + 4 files changed, 172 insertions(+), 99 deletions(-) diff --git a/src/components/Common/CommonComponent/index.js b/src/components/Common/CommonComponent/index.js index e4dcaf8..9059053 100644 --- a/src/components/Common/CommonComponent/index.js +++ b/src/components/Common/CommonComponent/index.js @@ -2880,6 +2880,7 @@ export default class CommonComponent extends Component { /* 如果是选择空值,则将特殊字符过滤为空值 */ value = ""; } + console.log("🚀 ~ sAssignFieldObj:", 66666) /* 回带值声明 */ const returnValue = {}; @@ -2923,6 +2924,7 @@ export default class CommonComponent extends Component { const [changeData] = dropDownDataNew.filter(item => (!commonUtils.isEmpty(res) ? item[res] : item.sId) === value.toString()); if (!commonUtils.isEmpty(sAssignField)) { /* 赋值数组 */ + const sAssignFieldObj = sAssignField.split(","); if (commonUtils.isNotEmptyObject(changeData)) { for (const child of sAssignFieldObj) { diff --git a/src/components/Common/Typesetting/typesetting.js b/src/components/Common/Typesetting/typesetting.js index f1e134a..48a5979 100644 --- a/src/components/Common/Typesetting/typesetting.js +++ b/src/components/Common/Typesetting/typesetting.js @@ -59,7 +59,7 @@ const Typesetting = props => { const [materialWidth, setMaterialWidth] = useState(0); const [dProductQty, setDProductQty] = useState(0); const [materialName, setMaterialName] = useState(""); - const [dMaterialsKQty, setDMaterialsKQty] = useState(0); + // const [dMaterialsKQty, setDMaterialsKQty] = useState(0); const [dPartsLength, setDPartsLength] = useState(0); const [newDHorizontalType, setNewDHorizontalType] = useState(0); const [newDPortraitType, setNewDPortraitType] = useState(0); @@ -70,6 +70,8 @@ const Typesetting = props => { const boxsRef = useRef(null); const typesettingBox = useRef(null); const typesettingBoxs = useRef(null); + const svgBox = useRef(null); + const svgBoxs = useRef(null); // 获取外层盒子尺寸 const clientWidth = boxWidth || 400; const clientHeight = boxHeight || 300; @@ -92,23 +94,24 @@ const Typesetting = props => { const H = masterData?.dWidth || 0; const D = masterData?.dHeight || 0; // 动态计算公式值 - const evaluateFormula = (formula, variables) => { - if (!formula) return 0; // 如果公式为空,返回0 - try { - // 提取公式中的变量名 - const variableNames = formula.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || []; - // 构建函数参数 - const params = variableNames.join(","); - // 替换公式中的变量为实际值 - const func = new Function(params, `return ${formula}`); - // 提取变量值 - const args = variableNames.map(name => Number(variables[name]) || 0); - // 执行函数并返回结果 - return func(...args); - } catch (error) { - return 0; - } - }; + const evaluateFormula = (formula, variables) => { + if (!formula) return 0; // 如果公式为空,返回0 + try { + // 提取公式中的变量名 + const variableNames = formula.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || []; + // 构建函数参数 + const params = variableNames.join(","); + // 替换公式中的变量为实际值 + const func = new Function(params, `return ${formula}`); + // 提取变量值 + const args = variableNames.map(name => Number(variables[name]) || 0); + // 执行函数并返回结果 + return func(...args); + } catch (error) { + console.error("公式执行错误:", error); + return 0; + } +}; // 计算公式值 const variables = { L, @@ -119,7 +122,7 @@ const Typesetting = props => { }; const { sStripType = 0 } = props.state.selectedNode; let boxList = []; - if (sColumnNameConfig ) { + if (sColumnNameConfig) { const slaveNewData = JSON.parse(sColumnNameConfig); const tables = [ { name: "盒型类别", value: slaveRowData.sBoxType, type: null }, @@ -200,13 +203,14 @@ const Typesetting = props => { const boxWidthOffset = evaluateFormula(sSecondLongitudinalOffset, variabless); // 第二列纵向偏移 const isVertical = sSettingMethod === "从上到下"; // true 表示竖向排列,false 表示横向排列 sSettingMethod === '从上到下' const reference = sSGroupOffset === "首盒"; // 第三列参考 - console.log(innerWidth,innerHeight,dFWidthOffset,dFLengthOffset,dSWidthOffset,dSLengthOffset,boxLengthOffset,boxWidthOffset,'typeSetting'); - + console.log(innerWidth, innerHeight, dFWidthOffset, dFLengthOffset, dSWidthOffset, dSLengthOffset, boxLengthOffset, boxWidthOffset, "typeSetting"); + // 计算内层盒子尺寸 加上间距 let jInnerHeight = innerHeight; let jInnerWidth = innerWidth; let dSvgBoxWidth = innerWidth; let dSvgBoxHeight = innerHeight; + const isRrotate = iFAngle === 90 || iFAngle === 270 || iSAngle === 90 || iSAngle === 270; if (iFAngle === 90 || iFAngle === 270 || iSAngle === 90 || iSAngle === 270) { jInnerHeight = innerWidth; jInnerWidth = innerHeight; @@ -229,8 +233,8 @@ const Typesetting = props => { }; // 加上间距后的最大盒子长宽 计算每列可以放多少个组合 需要计算间距 // 每个盒子加上边距 和第二组偏移量 如果根据次盒再加上次盒偏移量 - const dSWidthOffsetCombined = (innerWidthCombined + boxLengthOffset + (reference ? 0 : dSLengthOffset)) - let cols = dSWidthOffsetCombined === 0 ? 0 : Math.floor(outerWidth / dSWidthOffsetCombined); + const dSWidthOffsetCombined = innerWidthCombined + boxLengthOffset + (reference ? 0 : dSLengthOffset); + let cols = dSWidthOffsetCombined === 0 ? 0 : Math.floor(outerWidth / dSWidthOffsetCombined); let rows = Math.floor(outerHeight / (innerHeightCombined + boxWidthOffset + (reference ? 0 : dSWidthOffset))); let colsMaxLength = (cols - 1) * (innerWidthCombined + boxLengthOffset + (reference ? 0 : dSLengthOffset)) + innerWidthCombined; while (colsMaxLength >= outerWidth && cols > 0) { @@ -373,11 +377,15 @@ const Typesetting = props => { alignItems: "center", position: "absolute", left: `${ - isVertical ? dSLengthOffset : iSAngle === 90 || iSAngle === 270 + isVertical + ? dSLengthOffset + : iSAngle === 90 || iSAngle === 270 ? innerHeight + dFLengthOffset + dSLengthOffset + dYBJJ : innerWidth + dFLengthOffset + dSLengthOffset + dYBJJ }px`, - top: `${isVertical ? jInnerHeight + dFWidthOffset + dSWidthOffset + dXBJJ: iSAngle === 90 || iSAngle === 270 ? dSWidthOffset : dSWidthOffset}px`, + top: `${ + isVertical ? jInnerHeight + dFWidthOffset + dSWidthOffset + dXBJJ : iSAngle === 90 || iSAngle === 270 ? dSWidthOffset : dSWidthOffset + }px`, }} >
@@ -416,8 +424,8 @@ const Typesetting = props => {
{ useEffect(() => { // 计算缩放比例 // setBoxKey(new Date().getTime()); - // setTimeout(() => { + setTimeout(() => { const scaleX = (clientWidth - 50) / (outerWidth + 110); const scaleY = (clientHeight - 5) / (outerHeight + 90); const newScale = Math.min(scaleX, scaleY); @@ -478,68 +486,91 @@ const Typesetting = props => { boxRef.current.style.transform = `scale(${scaleX}, ${scaleY})`; boxRef.current.style.transformOrigin = "top left"; } - // }, 0); + }, 0); }, [radioValue, slaveRowData, masterData, selectedNode, slaveData]); // 生成里层 div 的数组 const innerDivs = []; - - for (let col = 0; col < cols; col++) { - for (let row = 0; row < rows; row++) { - const leftPosition = col * (innerWidthCombined + dYBJJ); - const topPosition = row * (innerHeightCombined + dXBJJ); - innerDivs.push(createBox(col, row, 1, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + // 生成盒子 + if (cols === 0 || rows === 0) { + if (cols > 0) { + for (let col = 0; col < cols; col++) { + const leftPosition = col * (innerWidthCombined + dYBJJ); + const topPosition = 0 * (innerHeightCombined + dXBJJ); + innerDivs.push(createBoxOne(col, 0, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + } } - // 如果可以放下首盒 - if (remaining) { - if (isVertical) { - let leftPosition = 0; - let topPosition = 0; - if (reference) { - // 是否首盒 - // 首盒的上边距下边距 末尾盒子的上下边距 添加那一行的上边距 - leftPosition = col * innerWidthCombined; - topPosition = rows * innerHeightCombined; - } else { - leftPosition = col * (innerWidthCombined + dYBJJ); ; - topPosition = rows *( innerHeightCombined + dXBJJ); - } - innerDivs.push(createBoxOne(col, rows, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); - } else { - for (let index = 0; index < rows; index++) { - // 先默认为首盒参考 - let topPosition = 0; + if (rows > 0) { + for (let row = 0; row < rows; row++) { + const leftPosition = 0 * (innerWidthCombined + dYBJJ); + const topPosition = row * (innerHeightCombined + dXBJJ); + innerDivs.push(createBoxOne(0, row, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + } + } + } else { + for (let col = 0; col < cols; col++) { + for (let row = 0; row < rows; row++) { + const leftPosition = col * (innerWidthCombined + dYBJJ); + const topPosition = row * (innerHeightCombined + dXBJJ); + innerDivs.push(createBox(col, row, 1, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + } + // 如果可以放下首盒 + if (remaining) { + if (isVertical) { let leftPosition = 0; + let topPosition = 0; if (reference) { - topPosition = index * (innerHeightCombined + boxWidthOffset); - leftPosition = cols * (innerWidthCombined + boxLengthOffset); + // 是否首盒 + // 首盒的上边距下边距 末尾盒子的上下边距 添加那一行的上边距 + leftPosition = col * innerWidthCombined; + topPosition = rows * innerHeightCombined; } else { - topPosition = index * (innerHeightCombined + boxWidthOffset + dSWidthOffset); - leftPosition = cols * (innerWidthCombined + boxLengthOffset + dSLengthOffset); + leftPosition = col * (innerWidthCombined + dYBJJ); + topPosition = rows * (innerHeightCombined + dXBJJ); + } + innerDivs.push(createBoxOne(col, rows, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + } else { + for (let index = 0; index < rows; index++) { + // 先默认为首盒参考 + let topPosition = 0; + let leftPosition = 0; + if (reference) { + topPosition = index * (innerHeightCombined + boxWidthOffset); + leftPosition = cols * (innerWidthCombined + boxLengthOffset); + } else { + topPosition = index * (innerHeightCombined + boxWidthOffset + dSWidthOffset); + leftPosition = cols * (innerWidthCombined + boxLengthOffset + dSLengthOffset); + } + innerDivs.push(createDiv(col, index, 3, leftPosition + col * dYBJJ, topPosition + index * dXBJJ, iFAngle, DisableMateriallIcon)); } - innerDivs.push(createDiv(col, index, 3, leftPosition + (col * dYBJJ), topPosition + (index * dXBJJ), iFAngle, DisableMateriallIcon)); } } } } - // 如果第一行只能放下一个 - if (cols === 0 && !isVertical) { - const maxLength = Number(slaveDataDetail?.dMaxLength); - if (maxLength > innerWidth) { - let leftPosition = 0; - let topPosition = 0; - innerDivs.push(createBoxOne(0, rows, 3, leftPosition , topPosition , iFAngle, DisableMateriallIcon)); - } - } - // 如果第一列 - if (rows === 0) { - const maxWidth = Number(slaveDataDetail?.dMaxWidth); - if (maxWidth > innerHeight) { - let leftPosition = 0; - let topPosition = 0; - innerDivs.push(createBoxOne(cols, 0, 3, leftPosition , topPosition, iFAngle, DisableMateriallIcon)); - } - } - + + // // 如果第一行只能放下一个 + // if (cols === 0 && !isVertical) { + // const maxLength = Number(slaveDataDetail?.dMaxLength); + // if (maxLength > innerWidth) { + // let leftPosition = 0; + // let topPosition = 0; + // innerDivs.push(createBoxOne(0, rows, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + // } + // } + + // // 如果第一列 + // if (rows === 0 && isVertical) { + // const maxWidth = Number(slaveDataDetail?.dMaxWidth); + // if (maxWidth > innerHeight) { + // for (let index = 0; index < cols; index++) { + // let leftPosition = index * (innerWidthCombined + dYBJJ); + // let topPosition = 0; + // innerDivs.push(createBoxOne(cols, 0, 3, leftPosition, topPosition, iFAngle, DisableMateriallIcon)); + // } + // } + // } + + console.log(cols, rows, innerDivs.length, "innerDivs"); + // 判断展开长展开宽是否变化 if (dPartsLength !== innerWidth && !innerDivs.length) { setDPartsLength(innerWidth); @@ -566,14 +597,23 @@ const Typesetting = props => { : remaining ? rows + rows * (cols * 2) : rows * (cols * 2); - // 计算竖版数量 - if ((cols === 1 && rows === 0 )|| (cols === 0 && rows === 1 )) { - dSinglePQty = 1 - } - const dHorizontalType = isVertical ? cols : remaining ? cols * 2 + 1 : cols * 2; - const dPortraitType = isVertical ? (remaining ? rows * 2 + 1 : rows * 2) : remaining ? rows : rows; + let dHorizontalType = isVertical ? cols : remaining ? cols * 2 + 1 : cols * 2; + let dPortraitType = isVertical ? (remaining ? rows * 2 + 1 : rows * 2) : remaining ? rows : rows; + if (cols === 0 || rows === 0) { + if (innerDivs.length > 0) { + if (cols === 0 && rows > 0) { + dSinglePQty = rows; + dPortraitType = rows; + dHorizontalType = 1; + } else if (rows === 0 && cols > 0) { + dSinglePQty = cols; + dHorizontalType = cols; + dPortraitType = 1; + } + } + } const newDProductQty = masterData.dProductQty; const dMaterialsKQty = slaveDataDetail.dMaterialsKQty || 1; if ( @@ -646,6 +686,14 @@ const Typesetting = props => { // typesettingBox.current.style.top = dSBLB + "px"; // typesettingBox.current.style.left = dZBLB + "px"; } + if (svgBox.current) { + svgBox.current.style.width = newMaterialLength + dYBLB + "px"; + svgBox.current.style.height = newMaterialWidth + dXBLB + "px"; + } + if (svgBoxs.current) { + svgBoxs.current.style.width = newMaterialLength + dYBLB + "px"; + svgBoxs.current.style.height = newMaterialWidth + dXBLB + "px"; + } if (typesettingBoxs.current) { typesettingBoxs.current.style.backgroundColor = "#b7e0ff"; // typesettingBox.current.style.margin = [dSBLB, dYBLB, dXBLB, dZBLB].map(item => item + "px").join(" "); @@ -659,7 +707,7 @@ const Typesetting = props => { Number(slaveDataDetail?.dMaxLength) >= Number(slaveRowData?.dMachineLength) && Number(slaveDataDetail?.dMaxWidth) >= Number(slaveRowData?.dMachineWidth); - const isShow = slaveRowData && slaveRowData.dMachineLength && slaveRowData.dMaxWidth && slaveRowData.dMaxLength && isMax && innerDivs.length > 0; + const isShow = (slaveRowData && slaveRowData.dMachineLength && slaveRowData.dMaxWidth && slaveRowData.dMaxLength && isMax && innerDivs.length > 0); console.log( slaveDataDetail?.dMaxLength, slaveDataDetail?.dMaxWidth, @@ -717,7 +765,18 @@ const Typesetting = props => { }} >
-
+
{boxList.length ? innerDivs : []}
{ }} >
-
+
{boxList.length ? innerDivs : []}
{
{ height: `${materialWidth * 0.3}px`, position: "absolute", right: "10px", - top: `${materialWidth / 2 + 8}px`, + top: `${materialWidth / 2 + 8}px`, width: "2px", backgroundColor: "#333", }} @@ -1147,7 +1217,7 @@ const Typesetting = props => { width: "30px", backgroundColor: "#333", position: "absolute", - top: `${materialWidth / 2 }px`, + top: `${materialWidth / 2}px`, right: "-4.5px", }} /> diff --git a/src/components/QuickQuote/index.jsx b/src/components/QuickQuote/index.jsx index 5797c07..7b71128 100644 --- a/src/components/QuickQuote/index.jsx +++ b/src/components/QuickQuote/index.jsx @@ -268,7 +268,7 @@ const QuickQuoteEvent = props => { extraState.backendParamsConfig = sParamConfig; extraState.backendConfig = { sParentFieldsName: sFieldName, sBoxModel: boxModel }; const sBackendParams = sParamConfig - .map((item) => { + .map(item => { const { sParamDefault, sParam, sFieldName, iOrder } = item; return !sParamDefault ? "" @@ -772,10 +772,10 @@ const QuickQuoteEvent = props => { delete partsDataRow.dMaterialsKQty; delete partsDataRow.dMaterialsLength; delete partsDataRow.dMaterialsWidth; - if (productClassify.bSpecialRules) { - partsDataRow.dMachineLength = partsDataRow.dMaxMachineLength; - partsDataRow.dMachineWidth = partsDataRow.dMaxMachineWidth; - } + // if (productClassify.bSpecialRules) { + // partsDataRow.dMachineLength = partsDataRow.dMaxMachineLength; + // partsDataRow.dMachineWidth = partsDataRow.dMaxMachineWidth; + // } controlData.push(partsDataRow); // 材料信息 for (let i = 0; i < partInfo.materialsInfo.length; i++) { @@ -1978,14 +1978,15 @@ const BoxComponent = props => { // 提取公式中的变量名 const variableNames = formula.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || []; // 构建函数参数 - const params = variableNames.join(","); + const params = variableNames.join(",") + ",Math"; // 替换公式中的变量为实际值 const func = new Function(params, `return ${formula}`); // 提取变量值 const args = variableNames.map(name => Number(variables[name]) || 0); // 执行函数并返回结果 - return func(...args); + return func(...args, Math); } catch (error) { + console.error("公式执行错误:", error); return 0; } }; @@ -2006,7 +2007,7 @@ const BoxComponent = props => { slaveNewData.forEach(x => { let key = 0; if (x.sAssignFormula) { - key = parseFloat(evaluateFormula(x.sAssignFormula, variables)).toFixed(2); + key = evaluateFormula(x.sAssignFormula, variables); slaveRowData[x.sName] = key; } else { key = slaveRowData[x.sName]; @@ -2958,7 +2959,6 @@ const BackendParamsExtraComponent = props => { return props.getSqlDropDownData(...args); }, onDataChange: (name, sFieldName, changeValue, sId, dropDownData, isWait) => { - const iIndex = slaveData.findIndex(item => item.sId === slaveRowData.sId); const iIndex1 = slaveData[iIndex].sBackProcessData.findIndex(item => item[sParentFieldsName]); const showConfig = viewConfigs.find(item => item.sName === sFieldName); diff --git a/src/mobile/quotation/detailNew.jsx b/src/mobile/quotation/detailNew.jsx index f51e51a..ddd7ffb 100644 --- a/src/mobile/quotation/detailNew.jsx +++ b/src/mobile/quotation/detailNew.jsx @@ -2312,6 +2312,7 @@ const PrintParamsComponent = props => { iColValue: 8, }; }); + console.log("🚀 ~ printParamsConfig:", printParamsConfig) const result = []; for (let i = 0; i < printParams.length + 1; i++) { -- libgit2 0.22.2