diff --git a/api/app/lib/controllers/data/road.js b/api/app/lib/controllers/data/road.js index 794cbe52..e95ae7d1 100644 --- a/api/app/lib/controllers/data/road.js +++ b/api/app/lib/controllers/data/road.js @@ -93,7 +93,7 @@ async function getRoadSection (ctx) { let findOption = { where: {}, order: [['id', 'DESC']], - attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode'] + attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo'] } if (level) { diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index 39691c79..8a4f5fc9 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -207,7 +207,11 @@ async function reportDetail (ctx) { const reportRes = await models.Report.findOne({ where: { id: reportId - } + }, + include: [{ + model: models.Road, + as: 'road_', + }], }) ctx.status = 200; diff --git a/weapp/src/packages/patrol/index.jsx b/weapp/src/packages/patrol/index.jsx index 106b271e..a0a9cfe7 100644 --- a/weapp/src/packages/patrol/index.jsx +++ b/weapp/src/packages/patrol/index.jsx @@ -47,7 +47,6 @@ const Index = () => { const [conserveUnderwayImg, setConserveUnderwayImg] = useState([]) // 养护中图片 const [conserveAfterImg, setConserveAfterImg] = useState([]) // 养护后图片 - const [sourceRoadSel, setSourceRoadSel] = useState([]) const [sourceRoadStartSel, setSourceRoadStartSel] = useState([]) const [sourceRoadEndSel, setSourceRoadEndSel] = useState([]) @@ -65,7 +64,6 @@ const Index = () => { const [roadCodeHead, setRoadCodeHead] = useState('X') const [roadCodeEnd, setRoadCodeEnd] = useState('') - const [otherType, setOtherType] = useState('') // 道路类型-其他 const [patrolContentEdit, setPatrolContentEdit] = useState(true) // 养护基本信息是否可编辑 const [patrolContent, setPatrolContent] = useState({ @@ -208,6 +206,19 @@ const Index = () => { const [appointUser, setAppointUser] = useState(null) // 责任人在userList的index const [handleAdvice, setHandleAdvice] = useState('') // 处理意见 + const [routeNameList, setRouteNameList] = useState([]); + const [routeCodeList, setRouteCodeList] = useState([]); + const [sectionNoList, setSectionNoList] = useState([]); + const [roadChecked, setRoadChecked] = useState({ + routeName: '', + routeCode: '', + sectionNo: '', + startingPlaceName: '', + stopPlaceName: '', + }) + const [routeCodeDisabled, setRouteCodeDisabled] = useState(true); + const [sectionNoDisabled, setSectionNoDisabled] = useState(true); + const prjType = isAnomaly ? [ @@ -240,18 +251,6 @@ const Index = () => { const [canReport, setCanReport] = useState(true) - const [typeList, setTypeList] = useState([ - { - value: 'patrol', - text: '巡查', - checked: true - }, - { - value: 'conserve', - text: '养护', - checked: false - } - ]) useEffect(() => { if (isRoad) { Taro.setNavigationBarTitle({ title: '在建项目' }) @@ -329,6 +328,14 @@ const Index = () => { setHandleCenter(data.handleContent) } setIsBeforeReport(dayjs(data.time).diff('2023-08-03 00:00:00', 'h') < 0) + + setRoadChecked({ + routeName: data.road, + routeCode: data.codeRoad, + sectionNo: data.road_?.sectionNo || '-', + startingPlaceName: data.roadSectionStart, + stopPlaceName: data.roadSectionEnd, + }) } else { Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' }) } @@ -375,21 +382,37 @@ const Index = () => { Taro.hideLoading() if (res.statusCode == 200 || res.statusCode == 204) { const { data } = res - let nextSourceRoadSel = [] let nextSourceRoadStartSel = [] let nextSourceRoadEndSel = [] let nextCodeRoadSel = [] - data.map(item => { - nextSourceRoadSel.push(item.routeName) + + let routeName = [] + let routeCode = [] + let sectionNo = [] + + data.forEach(item => { nextSourceRoadStartSel.push(item.startingPlaceName) nextSourceRoadEndSel.push(item.stopPlaceName) nextCodeRoadSel.push(item.routeCode) + + if (item.routeName && !routeName.includes(item.routeName)) { + routeName.push(item.routeName) + } + if (item.routeCode && !routeCode.includes(item.routeCode)) { + routeCode.push(item.routeCode) + } + if (item.sectionNo && !sectionNo.includes(item.sectionNo)) { + sectionNo.push(item.sectionNo) + } }) - setSourceRoadSel(nextSourceRoadSel) setSourceRoadStartSel(nextSourceRoadStartSel) setSourceRoadEndSel(nextSourceRoadEndSel) setCodeRoadSel(nextCodeRoadSel) setRoadList(data) + + setRouteNameList(routeName) + setRouteCodeList(routeCode) + setSectionNoList(sectionNo) } else { Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' }) } @@ -426,26 +449,10 @@ const Index = () => { } }, []) - useEffect(() => { - setTypeList([ - { - value: 'patrol', - text: '巡查', - checked: reportType === 'patrol' ? true : false - }, - { - value: 'conserve', - text: '养护', - checked: reportType === 'conserve' ? true : false - } - ]) - }, [reportType]) - function report() { if (!canReport) { return } if ( - (isPatrol && (!road || !roadCodeEnd)) - || (isAnomaly && !road) + ((isPatrol || isAnomaly) && (!roadChecked.routeCode || !roadChecked.sectionNo || !roadChecked.routeName)) || (kind === 'patrol' && (Object.values(patrolContent).every(c => c.value === '') && !patrolContent.inspectionNoException.selected || Object.values(patrolContent).some(c => c.label !== '巡查结果无异常' && c.selected && c.value === ''))) @@ -476,17 +483,21 @@ const Index = () => { let data = { reportType: isPatrol ? reportType : kind, projectType: reportProjectType, - road, - roadSectionStart, - roadSectionEnd, + road: roadChecked.routeName, + roadSectionStart: roadChecked.startingPlaceName, + roadSectionEnd: roadChecked.stopPlaceName, address, content, longitude, latitude, - codeRoad, + codeRoad: roadChecked.routeCode, projectName, handleState: isAnomaly ? '待处理' : undefined, - videoUrl: videoqn + videoUrl: videoqn, + roadId: roadList.find(r => roadChecked?.routeName == r?.routeName + && roadChecked?.routeCode == r?.routeCode + && roadChecked?.sectionNo == r?.sectionNo + )?.id, } if (reportType === 'patrol' || isAnomaly || isRoad) { data['scenePic'] = sceneImg @@ -496,7 +507,6 @@ const Index = () => { data['conserveAfterPic'] = conserveAfterImg } if (isPatrol) { - data.codeRoad = roadCodeHead + roadCodeEnd if (kind === 'patrol') { Object.keys(patrolContent).forEach(key => { data[key] = patrolContent[key].value @@ -716,8 +726,72 @@ const Index = () => { } } - function handleTypeChange(e) { - setReportType(e.detail.value) + const handleRoadCheckChange = (value, key) => { + let nextValue = { + ...roadChecked, + [key]: value + } + let routeName = [] + let routeCode = [] + let sectionNo = [] + let data = [...roadList] + data.forEach(v => { + if (v.routeName && !routeName.includes(v.routeName)) { + routeName.push(v.routeName) + } + }); + + 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) + } + }); + setRouteCodeList(routeCode) + } + if (key == 'routeCode') { + nextValue.sectionNo = '' + data = roadList?.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) { + setRouteCodeList(routeCode) + } + setSectionNoList(sectionNo) + } + + setRouteNameList(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 + setRoadCodeHead(data[0]?.routeCode?.charAt(0)) + } else { + nextValue.startingPlaceName = '' + nextValue.stopPlaceName = '' + } + + setRoadChecked(nextValue) } function handleImgChange(files, operationType, index, type) { @@ -962,71 +1036,74 @@ const Index = () => { } return ( - {/* { - (!isSuperAdmin || isView) - && !isRoad && !isAnomaly - && - - 上报类型 - - { - typeList.map((item, i) => { - return ( - - {item.text} - - ) - }) - } - - - } */} - { - isPatrol ? <> - {!(isView && isBeforeReport) && + isPatrol || isAnomaly ? <> + + 路线名称: + + handleRoadCheckChange(routeNameList[e.detail.value], 'routeName')} + disabled={isView} + > + + {roadChecked.routeName || '请选择路线名称'} + + + + {!isView && handleRoadCheckChange('', 'routeName')} + />} + + + {!(isView && isBeforeReport) && 线路编码: - { - setRoadCodeHead(e.detail.value[0]); - if (roadCodeEnd.length >= 9) { - queryConserveInfo(e.detail.value[0], roadCodeEnd) - } else { - setRoadStartSel([]) - setRoadEndSel([]) - setRoadSectionStart('') - setRoadSectionEnd('') - setRoad('') - if (!patrolContentEdit) { - setPatrolContentEdit(true) - let nextInfo = { ...conserveInfo } - Object.keys(conserveInfo).forEach(key => { - nextInfo[key].value = '' - }) - setConserveInfo(nextInfo) - } - } - }}> - X - Y - C - - handleInput(e, 'roadCodeEnd')} - disabled={isView} - /> + + handleRoadCheckChange(routeCodeList[e.detail.value], 'routeCode')} + disabled={routeCodeDisabled} + > + + {roadChecked.routeCode || '请选择线路编码'} + + + + {roadChecked.routeCode && !isView && handleRoadCheckChange('', 'routeCode')} + />} + } + + 路段序号: + + handleRoadCheckChange(sectionNoList[e.detail.value], 'sectionNo')} + disabled={sectionNoDisabled} + > + + {roadChecked.sectionNo || '请选择路段序号'} + + + + {roadChecked.sectionNo && !isView && handleRoadCheckChange('', 'sectionNo')} + />} + + 道路类型: { onInput={() => { }} disabled={true} /> - {!(isView && isBeforeReport) && <> - 其他: - setProjectType(value === '无' ? '' : value)} - selector={prjTypeSelector} - isView={isView} - /> - } - : '' } @@ -1104,73 +1159,25 @@ const Index = () => { /> : '' } - { - isAnomaly ? - : '' - } - { - isAnomaly || (isView && isBeforeReport) ? - : '' - } - { isPatrol || isAnomaly ? 所属路段: handleInput(e, 'roadSectionStart')} - disabled={isView} + value={roadChecked.startingPlaceName} + disabled={true} /> - { - !isView && - setRoadSectionStart(roadStartSel[e.detail.value])} - > - - - } 至  handleInput(e, 'roadSectionEnd')} - disabled={isView} + value={roadChecked.stopPlaceName} + disabled={true} /> - { - !isView && - setRoadSectionEnd(roadEndSel[e.detail.value])} - > - - - } : '' } diff --git a/weapp/src/packages/patrol/index.scss b/weapp/src/packages/patrol/index.scss index 5281f66a..e44ca6bd 100644 --- a/weapp/src/packages/patrol/index.scss +++ b/weapp/src/packages/patrol/index.scss @@ -182,6 +182,10 @@ page { } } + .disabled { + background-color: #eee; + } + .patrol-content { background-color: #fff; margin-bottom: 5px; @@ -330,4 +334,21 @@ page { align-items: center; flex-wrap: wrap; } + + .select-box { + width: calc(100% - 192px - 16px); + display: flex; + justify-content: flex-end; + + .picker { + width: 400px; + display: flex; + justify-content: flex-end; + align-items: center; + + .arrow { + margin: 0 32px; + } + } + } } \ No newline at end of file