diff --git a/src/components/QuickQuote/index.jsx b/src/components/QuickQuote/index.jsx index c52993d..964112b 100644 --- a/src/components/QuickQuote/index.jsx +++ b/src/components/QuickQuote/index.jsx @@ -1574,53 +1574,66 @@ const ContentComponent = props => { } else if (!sAllPartsName) { sAllPartsName = showName; } - // 默认选中盒型 如果配置了默认值 - const sAllPartsNameDefaultRef = useRef(sAllPartsNameDefault); - + const hasAutoSetDefault = useRef(false); useEffect(() => { - sAllPartsNameDefaultRef.current = sAllPartsNameDefault; - }, [sAllPartsNameDefault]); - + hasAutoSetDefault.current = false; + }, [selectedNode]); + // 2. 监听两个依赖:sAllPartsNameDefault 与 slaveData useEffect(() => { - if (sAllPartsNameDefaultRef.current && props.state.slaveData) { - const boxModelList = sAllPartsName.split(","); - const slaveData = props.state.slaveData; - if (slaveData.length === boxModelList.length) { - const sAllPartsNameDefaultList = JSON.parse(sAllPartsNameDefaultRef.current); - const getSqlDropDownData = async ({ sId, sSqlCondition = {} }, cb) => { - const url = `${commonConfig.server_host}business/getSelectLimit/${sId}`; - const body = { - sKeyUpFilterName: "", - pageNum: 1, - pageSize: 1000, - sSqlCondition, - }; - const retrunData = await commonServices.postValueService(props.app.token, body, url); - const dropDownData = retrunData.data?.dataset?.rows; - if (dropDownData && sAllPartsNameDefaultList.length) { - sAllPartsNameDefaultList.forEach((item, index) => { - const sPartNameList = item.sPartName?.split(","); - if (sPartNameList && sPartNameList.length) { - sPartNameList.forEach(sPartName => { - const box = dropDownData.find(box => box.sId === item.sBoxId); // Define 'box' here - const boxData = dropDownData.map((itemBox, indexBox) => ({ - ...itemBox, - iOrder: indexBox + 1, - })); - if (box) { // Check if 'box' exists before using it - props.onDataChange("slaveUp" + sPartName, "sName", { sName: box.sName }, box.sId, boxData); - } - }); - } - }); - } + if ( + !hasAutoSetDefault.current && // 尚未执行 + selectedNode?.sAllPartsNameDefault?.length && // 有默认值 + props.state.slaveData?.length // 子表数据已就位 + ) { + const boxModelList = sAllPartsName.split(','); + const { slaveData } = props.state; + + // 数量对不上不处理 + if (slaveData.length !== boxModelList.length) return; + + // 标记为已执行,后续不再进来 + hasAutoSetDefault.current = true; + + // 取默认值列表(深拷贝,避免后续 JSON.parse 出错) + const sAllPartsNameDefaultList = JSON.parse( + sAllPartsNameDefault + ); + + const getSqlDropDownData = async ({ sId, sSqlCondition = {} }, cb) => { + const url = `${commonConfig.server_host}business/getSelectLimit/${sId}`; + const body = { + sKeyUpFilterName: "", + pageNum: 1, + pageSize: 1000, + sSqlCondition, }; - getSqlDropDownData( - { sId: '17428091410008594700322758474000', sSqlCondition: { sProductClassifyId: selectedNode.sId } } - ); - } + const retrunData = await commonServices.postValueService(props.app.token, body, url); + const dropDownData = retrunData.data?.dataset?.rows; + if (dropDownData && sAllPartsNameDefaultList.length) { + sAllPartsNameDefaultList.forEach((item, index) => { + const sPartNameList = item.sPartName?.split(","); + if (sPartNameList && sPartNameList.length) { + sPartNameList.forEach(sPartName => { + const box = dropDownData.find(box => box.sId === item.sBoxId); // Define 'box' here + const boxData = dropDownData.map((itemBox, indexBox) => ({ + ...itemBox, + iOrder: indexBox + 1, + })); + if (box) { // Check if 'box' exists before using it + props.onDataChange("slaveUp" + sPartName, "sName", { sName: box.sName }, box.sId, boxData); + } + }); + } + }); + } + }; + + getSqlDropDownData({ + sId: '17428091410008594700322758474000', + sSqlCondition: { sProductClassifyId: selectedNode.sId }, + }); } - }, [sAllPartsNameDefaultRef.current, props.state.slaveData]); + }, [selectedNode?.sAllPartsNameDefault, props.state.slaveData]); const boxModelList = sAllPartsName.split(","); const [activeKey, setActiveKey] = useState(0); @@ -2543,10 +2556,10 @@ const BoxComponent = props => { { src: getImageUrl(removeExtension(slaveRowData.sPackDetailPathUpLoad)), alt: "展开图" }, { src: getImageUrl(removeExtension(slaveRowData.sPackPath)), alt: "立体图" }, ]; - if (!slaveRowData.sPackDetailPathUpLoad) { - imagesData = [{ src: slaveRowData.sPackPath, alt: "立体图" }]; + if (!slaveRowData.sPackDetailPathUpLoad) { + imagesData = [{ src: getImageUrl(removeExtension(slaveRowData.sPackPath)), alt: "立体图" }]; } else if (!slaveRowData.sPackPath) { - imagesData = [{ src: slaveRowData.sPackPath, alt: "立体图" }]; + imagesData = [{ src: getImageUrl(removeExtension(slaveRowData.sPackPath)), alt: "立体图" }]; } const { activeKey = 0 } = state; useEffect(() => {