Compare commits

...

2 Commits

  1. 2
      api/app/lib/controllers/data/road.js
  2. 145
      weapp/src/packages/patrol/index.jsx

2
api/app/lib/controllers/data/road.js

@ -96,7 +96,7 @@ async function getRoadSection (ctx) {
let findOption = {
where: { del: false },
order: [['id', 'DESC']],
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level']
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level', 'startStation', 'stopStation']
}
if (level) {

145
weapp/src/packages/patrol/index.jsx

@ -225,11 +225,12 @@ const Index = () => {
]);
const [routeNameList, setRouteNameList] = useState([]);
const [routeCodeList, setRouteCodeList] = useState([]);
const [sectionNoList, setSectionNoList] = useState([]);
const [stationRangeList, setStationRangeList] = useState([]);
const [roadChecked, setRoadChecked] = useState({
routeName: '',
routeCode: '',
sectionNo: '',
stationRange: '',
startingPlaceName: '',
stopPlaceName: '',
})
@ -362,6 +363,7 @@ const Index = () => {
routeName: data.road,
routeCode: data.codeRoad,
sectionNo: data.road_?.sectionNo || '-',
stationRange: `${data.road_?.startStation || ' '} - ${data.road_?.stopStation || ' '}`,
startingPlaceName: data.roadSectionStart,
stopPlaceName: data.roadSectionEnd,
})
@ -415,35 +417,22 @@ const Index = () => {
let nextSourceRoadStartSel = []
let nextSourceRoadEndSel = []
let nextCodeRoadSel = []
let routeName = []
let routeCode = []
let sectionNo = []
const selLevel = roadTypeList.find(item => item.checked).value
data.forEach(item => {
nextSourceRoadStartSel.push(item.startingPlaceName)
nextSourceRoadEndSel.push(item.stopPlaceName)
nextCodeRoadSel.push(item.routeCode)
if (item.routeName && !routeName.includes(item.routeName) && item.level === selLevel) {
routeName.push(item.routeName)
}
if (item.routeCode && !routeCode.includes(item.routeCode)) {
if (item.routeCode && !routeCode.includes(item.routeCode) && item.level === selLevel) {
routeCode.push(item.routeCode)
}
if (item.sectionNo && !sectionNo.includes(item.sectionNo)) {
sectionNo.push(item.sectionNo)
}
})
setSourceRoadStartSel(nextSourceRoadStartSel)
setSourceRoadEndSel(nextSourceRoadEndSel)
setCodeRoadSel(nextCodeRoadSel)
setRoadList(data)
setRouteNameList(routeName)
setRouteCodeList(routeCode)
setSectionNoList(sectionNo)
} else {
Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' })
}
@ -529,6 +518,7 @@ const Index = () => {
&& roadChecked?.routeCode == r?.routeCode
&& roadChecked?.sectionNo == r?.sectionNo
)?.id,
}
if (reportType === 'patrol' || isAnomaly || isRoad) {
data['scenePic'] = sceneImg
@ -757,52 +747,40 @@ const Index = () => {
}
}
const handleRoadCheckChange = (value, key, typeList = roadTypeList) => {
const handleRoadCheckChange = (value, key, typeList = roadTypeList, sectionNo) => {
let nextValue = {
...roadChecked,
[key]: value
}
let routeCode = []
let sectionNo = []
let data = roadList.filter(r => r.level === typeList.find(t => t.checked).value)
if (key == 'routeName') {
// routeName
let routeName = []
data.forEach(item => {
if (item.routeName && !routeName.includes(item.routeName)) {
routeName.push(item.routeName)
}
})
if (value) {
routeName = routeName.filter(item => item.indexOf(value) > -1)
}
setRouteNameList(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 == 'stationRange') nextValue.sectionNo = sectionNo;
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)
nextValue.stationRange = ''
let routeCode = []
let matchData = []
data.forEach(item => {
if (item.routeCode.indexOf(value) > -1) {
routeCode.push(item.routeCode)
}
if (!nextValue?.routeCode && v.routeCode && !routeCode.includes(v.routeCode)) {
routeCode.push(v.routeCode)
if (item.routeCode === value) {
matchData.push(item)
}
});
if (!nextValue?.routeCode) {
setRouteCodeList(routeCode)
})
setRouteCodeList(routeCode)
if (matchData.length) {
// 线
nextValue.routeName = matchData[0].routeName
//
setStationRangeList(matchData.map(s => ({
label: `${s.startStation || ' '} - ${s.stopStation || ' '}`,
sectionNo: s.sectionNo,
})))
} else {
nextValue.routeName = ''
setStationRangeList([])
}
setSectionNoList(sectionNo)
}
if (nextValue?.routeName) {
@ -823,6 +801,7 @@ const Index = () => {
&& nextValue.routeCode == s.routeCode
&& nextValue.sectionNo == s.sectionNo
)
nextValue.startingPlaceName = find?.startingPlaceName
nextValue.stopPlaceName = find?.stopPlaceName
setRoadCodeHead(find?.routeCode?.charAt(0))
@ -1080,7 +1059,7 @@ const Index = () => {
for (let i = 0, len = items.length; i < len; ++i) {
items[i].checked = items[i].value === e.detail.value
}
handleRoadCheckChange('', 'routeName', items)
handleRoadCheckChange('', 'routeCode', items) // routeCode
setRoadTypeList(items)
}
@ -1104,77 +1083,75 @@ const Index = () => {
</RadioGroup>
</View>
</View>
<View className='code-choice'>
<Text style={{ color: 'red' }}>*&nbsp;</Text>路线名称
{!(isView && isBeforeReport) && <View className={`code-choice`}>
<Text style={{ color: 'red' }}>*&nbsp;</Text>线路编码
<View className='select-box'>
<View className='picker'>
<Input
style={{ textAlign: 'right' }}
type='text'
placeholder='输入关键字筛选'
placeholder='选择或输入编码'
border={false}
value={roadChecked.routeName}
onInput={e => handleRoadCheckChange(e.detail.value, 'routeName')}
value={roadChecked.routeCode}
onInput={e => handleRoadCheckChange(e.detail.value, 'routeCode')}
disabled={isView}
/>
<Picker
mode='selector'
range={routeNameList}
onChange={e => handleRoadCheckChange(routeNameList[e.detail.value], 'routeName')}
range={routeCodeList}
onChange={e => handleRoadCheckChange(routeCodeList[e.detail.value], 'routeCode')}
disabled={isView}
>
<AtIcon className='arrow' value='chevron-down' size='20' color='#999' />
</Picker>
{roadChecked.routeCode && !isView && <AtIcon
value='close-circle'
size='20'
color='#999'
onClick={() => handleRoadCheckChange('', 'routeCode')}
/>}
</View>
{!isView && <AtIcon
value='close-circle'
size='20'
color='#999'
onClick={() => handleRoadCheckChange('', 'routeName')}
/>}
</View>
</View>
{!(isView && isBeforeReport) && <View className={`code-choice ${routeCodeDisabled && !isView ? ` disabled` : ``}`}>
<Text style={{ color: 'red' }}>*&nbsp;</Text>线路编码
</View>}
<View className='code-choice disabled'>
<Text style={{ color: 'red' }}>*&nbsp;</Text>路线名称
<View className='select-box'>
<Picker
mode='selector'
range={routeCodeList}
onChange={e => handleRoadCheckChange(routeCodeList[e.detail.value], 'routeCode')}
disabled={routeCodeDisabled}
range={routeNameList}
onChange={e => handleRoadCheckChange(routeNameList[e.detail.value], 'routeName')}
disabled={true}
>
<View className='picker'>
<View>{roadChecked.routeCode || '选择线路编码'}</View>
<View>{roadChecked.routeName || '选择编码自动带出'}</View>
<AtIcon className='arrow' value='chevron-down' size='20' color='#999' />
</View>
</Picker>
{roadChecked.routeCode && !isView && <AtIcon
value='close-circle'
size='20'
color='#999'
onClick={() => handleRoadCheckChange('', 'routeCode')}
/>}
</View>
</View>}
</View>
<View className={`code-choice ${sectionNoDisabled && !isView ? ` disabled` : ``}`}>
<Text style={{ color: 'red' }}>*&nbsp;</Text>路段序号
<Text style={{ color: 'red' }}>*&nbsp;</Text>桩号区间
<View className='select-box'>
<Picker
mode='selector'
range={sectionNoList}
onChange={e => handleRoadCheckChange(sectionNoList[e.detail.value], 'sectionNo')}
range={stationRangeList}
rangeKey='label'
onChange={e => handleRoadCheckChange(stationRangeList[e.detail.value].label, 'stationRange', undefined, stationRangeList[e.detail.value].sectionNo)}
disabled={sectionNoDisabled}
>
<View className='picker'>
<View>{roadChecked.sectionNo || '请选择路段序号'}</View>
<View>{roadChecked.stationRange || '请选择桩号区间'}</View>
<AtIcon className='arrow' value='chevron-down' size='20' color='#999' />
</View>
</Picker>
{roadChecked.sectionNo && !isView && <AtIcon
{roadChecked.stationRange && !isView && <AtIcon
value='close-circle'
size='20'
color='#999'
onClick={() => handleRoadCheckChange('', 'sectionNo')}
onClick={() => handleRoadCheckChange('', 'stationRange', undefined, '')}
/>}
</View>
</View>

Loading…
Cancel
Save