/* eslint-disable */
import React, { useEffect, useState, useRef } from "react";
import { VerticalLeftOutlined, VerticalRightOutlined } from "@ant-design/icons";
import styles from "./index.less";
import { bottom } from "react-grid-layout/build/utils";
const BoxShowImgMaterial = props => {
const boxRef = useRef(null);
const textRef = useRef(null);
const textRefs = useRef(null);
const nTextRefs = useRef(null);
const nTextRef = useRef(null);
const [boxKey,setBoxKey] = useState(new Date().getTime())
const clientWidth = 200;
const clientHeight = 300;
const boxScale = 300 / 400;
// 找出盒型信息
const { slaveData, selectedNode } = props.state;
const { boxModel } = props;
const slaveDataDetail = slaveData?.find(item => item.sTreeNodeName === selectedNode.showName && item.sBoxModel === boxModel);
if (slaveDataDetail) {
// 最大上机长 上机宽 排版长 排版宽 材料长 材料宽
var { dMaxLength, dMaxWidth, dMachineLength, dMachineWidth, dWlcd, dWlkd, dSBLB, dXBLB, dZBLB, dYBLB, scale } = slaveDataDetail;
}
// 计算可以放置的盒子数量
const horizontalBoxes = Math.floor(dWlkd / dMachineWidth);
const verticalBoxes = Math.floor(dWlcd / dMachineLength);
const scaleX = (clientWidth - 50) / (dWlkd + 60);
const scaleY = (clientHeight - 25) / (dWlcd + 90);
// 动态生成多个 materialBox
const generateMaterialBoxes = () => {
const boxes = [];
for (let i = 0; i < horizontalBoxes * verticalBoxes; i++) {
boxes.push(
);
}
return boxes;
};
// 计算材料利用率
const availability = ((((horizontalBoxes * verticalBoxes) * (Number(dMachineLength) * Number(dMachineWidth)) / (Number(dWlcd) * Number(dWlkd)))) * 100).toFixed(2);
useEffect(() => {
// setBoxKey(new Date().getTime());
setTimeout(() => {
if (boxRef.current && textRef.current && textRefs.current && nTextRef.current && nTextRefs.current) {
// 计算父元素的缩放因子
const scaleX = (clientWidth - 50) / (dWlkd + 60);
const scaleY = (clientHeight - 25) / (dWlcd + 90);
// 对父元素应用缩放
boxRef.current.style.transform = `scale(${scaleX}, ${scaleY})`;
boxRef.current.style.transformOrigin = "top left";
// // 对子元素应用逆缩放
textRef.current.style.transform = `scale(${1 / scaleX}, ${1 / scaleY})`;
textRef.current.style.transformOrigin = "top left";
textRefs.current.style.transform = `scale(${1 / scaleX}, ${1 / scaleY})`;
textRefs.current.style.transformOrigin = "top left";
}
}, 0);
}, [slaveDataDetail]);
const isMax = slaveDataDetail?.dMaxWidth * slaveDataDetail?.dMaxLength > slaveDataDetail?.dMachineLength * slaveDataDetail?.dMachineWidth
const isDPartsLength = slaveDataDetail?.dPartsLength < slaveDataDetail?.dMaxLength && slaveDataDetail?.dPartsWidth < slaveDataDetail?.dMaxWidth
const isShow = isDPartsLength && slaveDataDetail && slaveDataDetail.dMachineLength && slaveDataDetail.dMaxWidth && slaveDataDetail.dMaxLength && isMax
return (
<>
{isShow ? (
{dWlkd}
材料利用率:
{availability}%
{generateMaterialBoxes()}
) : (
""
)}
>
);
};
export default BoxShowImgMaterial;