From dd96280972040e13477dad28a9bdb8249464a3b8 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Thu, 14 Dec 2023 17:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E6=9F=A5=E8=B0=83=E6=95=B4=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maintenanceSpotCheck/spotChange/index.jsx | 78 ++++++++++++++----- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/weapp/src/packages/maintenanceSpotCheck/spotChange/index.jsx b/weapp/src/packages/maintenanceSpotCheck/spotChange/index.jsx index e272ddf6..14207dd4 100644 --- a/weapp/src/packages/maintenanceSpotCheck/spotChange/index.jsx +++ b/weapp/src/packages/maintenanceSpotCheck/spotChange/index.jsx @@ -24,6 +24,8 @@ function Index() { startingPlaceName: '', stopPlaceName: '', }) + const [routeCodeDisabled, setRouteCodeDisabled] = useState(true); + const [sectionNoDisabled, setSectionNoDisabled] = useState(true); useEffect(() => { getRoad() @@ -75,35 +77,71 @@ function Index() { [key]: value } - let name = [] - let code = [] - let no = [] - let data = road?.filter(d => (nextValue?.routeName ? nextValue?.routeName == d?.routeName : true) - && (nextValue?.routeCode ? nextValue?.routeCode == d?.routeCode : true) - && (nextValue?.sectionNo ? nextValue?.sectionNo == d?.sectionNo : true)) + let routeName = [] + let routeCode = [] + let sectionNo = [] + let data = [...road] data.forEach(v => { - if (v.routeName && !name.includes(v.routeName)) { - name.push(v.routeName) - } - if (v.routeCode && !code.includes(v.routeCode)) { - code.push(v.routeCode) - } - if (v.sectionNo && !no.includes(v.sectionNo)) { - no.push(v.sectionNo) + if (v.routeName && !routeName.includes(v.routeName)) { + routeName.push(v.routeName) } }); - setNameList(name) - setCodeList(code) - setNoList(no) + + if (key == 'routeName') { + nextValue.routeCode = '' + nextValue.sectionNo = '' + data?.forEach(v => { + if (nextValue?.routeName && nextValue?.routeName == v.routeName && v.routeCode && !routeCode.includes(v.routeCode)) { + routeCode.push(v.routeCode) + } + }); + setCodeList(routeCode) + } + if (key == 'routeCode') { + nextValue.sectionNo = '' + data = road?.filter(s => nextValue?.routeName == s?.routeName) + data?.forEach(v => { + if (nextValue?.routeCode && nextValue?.routeCode == v?.routeCode && v.sectionNo && !sectionNo.includes(v.sectionNo)) { + sectionNo.push(v.sectionNo) + } + if (!nextValue?.routeCode && v.routeCode && !routeCode.includes(v.routeCode)) { + routeCode.push(v.routeCode) + } + }); + if (!nextValue?.routeCode) { + setCodeList(routeCode) + } + setNoList(sectionNo) + } + + setNameList(routeName) + + if (nextValue?.routeName) { + setRouteCodeDisabled(false) + } else { + setRouteCodeDisabled(true) + } + + if (nextValue?.routeName && nextValue?.routeCode) { + setSectionNoDisabled(false) + } else { + setSectionNoDisabled(true) + } if (nextValue.routeName && nextValue.routeCode && nextValue.sectionNo) { - nextValue.startingPlaceName = data[0]?.startingPlaceName - nextValue.stopPlaceName = data[0]?.stopPlaceName + let find = road?.find( + s => nextValue.routeName == s.routeName + && nextValue.routeCode == s.routeCode + && nextValue.sectionNo == s.sectionNo + ) + nextValue.startingPlaceName = find?.startingPlaceName + nextValue.stopPlaceName = find?.stopPlaceName } else { nextValue.startingPlaceName = '' nextValue.stopPlaceName = '' } + setChecked(nextValue) } @@ -168,6 +206,7 @@ function Index() { mode='selector' range={codeList} onChange={e => handleCheckChange(codeList[e.detail.value], 'routeCode')} + disabled={routeCodeDisabled} > {checked.routeCode || '请选择'} @@ -189,6 +228,7 @@ function Index() { mode='selector' range={noList} onChange={e => handleCheckChange(noList[e.detail.value], 'sectionNo')} + disabled={sectionNoDisabled} > {checked.sectionNo || '请选择'}