Browse Source

(*)添加线路编码

dev
ww664853070 2 years ago
parent
commit
94b350b396
  1. 12
      api/app/lib/controllers/data/road.js
  2. 56
      weapp/src/packages/components/inputPickers/index.jsx
  3. 30
      weapp/src/packages/components/inputPickers/index.scss
  4. 56
      weapp/src/packages/patrol/index.jsx

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

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const roadKeyMap = require('./road.json') const roadKeyMap = require('./road.json')
async function importIn (ctx) { async function importIn(ctx) {
// 数据导入 // 数据导入
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
@ -32,7 +32,7 @@ async function importIn (ctx) {
} }
} }
async function get (ctx) { async function get(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { level, road, sectionStart, sectionEnd } = ctx.query; const { level, road, sectionStart, sectionEnd } = ctx.query;
@ -76,14 +76,14 @@ async function get (ctx) {
} }
} }
async function getRoadSection (ctx) { async function getRoadSection(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { level, road, sectionStart, sectionEnd } = ctx.query; const { level, road, sectionStart, sectionEnd } = ctx.query;
let findOption = { let findOption = {
where: {}, where: {},
order: [['id', 'DESC']], order: [['id', 'DESC']],
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName'] attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode']
} }
if (level) { if (level) {
@ -119,7 +119,7 @@ async function getRoadSection (ctx) {
} }
} }
async function edit (ctx) { async function edit(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const data = ctx.request.body; const data = ctx.request.body;
@ -145,7 +145,7 @@ async function edit (ctx) {
} }
} }
async function del (ctx) { async function del(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { roadId } = ctx.params; const { roadId } = ctx.params;

56
weapp/src/packages/components/inputPickers/index.jsx

@ -0,0 +1,56 @@
/*
* 输入框筛选选择器
*/
import React, { useState, useEffect } from 'react'
import { View, Picker, Image, Input, Text } from '@tarojs/components'
import arrowIcon from '../../../static/img/patrol/arrow-down.svg'
import './index.scss'
export default function InputPicker(props) {
const { title, placeholder, selector, value, onInput, isView } = props
const [curSelector, setCurSelector] = useState([])
useEffect(() => {
setCurSelector(selector)
}, [])
useEffect(()=>{
handleInput({ detail: { value: value } })
},[value])
function handleInput({ detail: { value: v } }) {
onInput(v)
if (v) {
setCurSelector(selector.filter(item => item && item.includes(v)))
} else {
setCurSelector(selector)
}
}
const handlePickerChange = (e) => {
onInput(curSelector[e.detail.value])
}
return (
<View className='input-picker'>
<View className='input-box'>
<View className='title'>{title}</View>
<Input
className='input'
type='text'
placeholder={placeholder}
border={false}
value={value}
onInput={handleInput}
disabled={isView}
/>
</View>
{
!isView &&
<Picker mode='selector' range={curSelector} onChange={handlePickerChange}>
<Image src={arrowIcon} className='img' />
</Picker>
}
</View>
)
}

30
weapp/src/packages/components/inputPickers/index.scss

@ -0,0 +1,30 @@
.input-picker {
display: flex;
justify-content: space-between;
height: 96px;
align-items: center;
background-color: #fff;
margin-bottom: 5px;
.input-box {
padding: 12px 0;
flex-grow: 1;
display: flex;
align-items: center;
.title {
margin-left: 12px;
}
.input {
margin-left: 20px;
flex-grow: 1;
}
}
.img {
width: 24px;
height: 14px;
margin: 0 30px;
}
}

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

@ -3,6 +3,7 @@ import Taro, { useRouter } from '@tarojs/taro';
import { View, RadioGroup, Radio, Image, Input, Picker, Video } from '@tarojs/components'; import { View, RadioGroup, Radio, Image, Input, Picker, Video } from '@tarojs/components';
import { AtButton, AtTextarea, AtImagePicker } from 'taro-ui'; import { AtButton, AtTextarea, AtImagePicker } from 'taro-ui';
import InputPicker from '../components/inputPicker'; import InputPicker from '../components/inputPicker';
import InputPickers from '../components/inputPickers';
import VideoUpload from '../../components/uploads' import VideoUpload from '../../components/uploads'
import request from '@/services/request'; import request from '@/services/request';
import environment from '../../config'; import environment from '../../config';
@ -49,6 +50,10 @@ const Index = () => {
const [sourceRoadStartSel, setSourceRoadStartSel] = useState([]) const [sourceRoadStartSel, setSourceRoadStartSel] = useState([])
const [sourceRoadEndSel, setSourceRoadEndSel] = useState([]) const [sourceRoadEndSel, setSourceRoadEndSel] = useState([])
const [codeRoadSel, setCodeRoadSel] = useState([])
const [roadList, setRoadList] = useState([])
const [codeRoad, setCodeRoad] = useState('')
const prjType = const prjType =
isAnomaly ? isAnomaly ?
[ [
@ -169,14 +174,18 @@ const Index = () => {
let nextSourceRoadSel = [] let nextSourceRoadSel = []
let nextSourceRoadStartSel = [] let nextSourceRoadStartSel = []
let nextSourceRoadEndSel = [] let nextSourceRoadEndSel = []
let nextCodeRoadSel = []
data.map(item => { data.map(item => {
nextSourceRoadSel.push(item.routeName) nextSourceRoadSel.push(item.routeName)
nextSourceRoadStartSel.push(item.startingPlaceName) nextSourceRoadStartSel.push(item.startingPlaceName)
nextSourceRoadEndSel.push(item.stopPlaceName) nextSourceRoadEndSel.push(item.stopPlaceName)
nextCodeRoadSel.push(item.routeCode)
}) })
setSourceRoadSel(nextSourceRoadSel) setSourceRoadSel(nextSourceRoadSel)
setSourceRoadStartSel(nextSourceRoadStartSel) setSourceRoadStartSel(nextSourceRoadStartSel)
setSourceRoadEndSel(nextSourceRoadEndSel) setSourceRoadEndSel(nextSourceRoadEndSel)
setCodeRoadSel(nextCodeRoadSel)
setRoadList(data)
} else { } else {
Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' }) Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' })
} }
@ -205,7 +214,7 @@ const Index = () => {
]) ])
}, [reportType]) }, [reportType])
function report () { function report() {
if (!canReport) { return } if (!canReport) { return }
if ( if (
(isPatrol && (!projectType || !road)) (isPatrol && (!projectType || !road))
@ -280,7 +289,7 @@ const Index = () => {
}) })
} }
function deleteReport () { function deleteReport() {
Taro.showModal({ Taro.showModal({
title: '提示', title: '提示',
content: '确定删除吗?', content: '确定删除吗?',
@ -307,7 +316,7 @@ const Index = () => {
}) })
} }
function handleInput ({ detail: { value } }, type) { function handleInput({ detail: { value } }, type) {
switch (type) { switch (type) {
case 'roadSectionStart': case 'roadSectionStart':
setRoadSectionStart(value) setRoadSectionStart(value)
@ -339,15 +348,15 @@ const Index = () => {
} }
} }
function handleTypeChange (e) { function handleTypeChange(e) {
setReportType(e.detail.value) setReportType(e.detail.value)
} }
function handleImgChange (files, operationType, index, type) { function handleImgChange(files, operationType, index, type) {
if (operationType === 'remove') { if (operationType === 'remove') {
setImg(false) setImg(false)
} }
function setImg (isAdd, url) { function setImg(isAdd, url) {
switch (type) { switch (type) {
case 'scenePic': case 'scenePic':
let nextImg = sceneImg let nextImg = sceneImg
@ -434,12 +443,33 @@ const Index = () => {
} }
} }
function handleImgClick (index, file) { function handleImgClick(index, file) {
Taro.previewImage({ Taro.previewImage({
urls: [file.url] // http urls: [file.url] // http
}) })
} }
useEffect(() => {
console.log(road, '所在道路的值');
let newRoadList = roadList.filter(e => e.routeName.match(road))
console.log(newRoadList, '过滤后的列表');
let codeRoadSel = []
if (newRoadList.length && road != '') {
newRoadList.forEach((e, index) => {
codeRoadSel.push(e.routeCode)
})
}
console.log(codeRoadSel, '最新的线路列表');
setCodeRoadSel(codeRoadSel)
if (codeRoadSel.length) {
setCodeRoad(codeRoadSel[0])
} else {
setCodeRoad('')
}
}, [road])
console.log(codeRoadSel, '线路编码');
console.log(sourceRoadSel, '所在道路');
console.log(roadList, '线路列表');
return ( return (
<View className='patrol'> <View className='patrol'>
{/* { {/* {
@ -520,6 +550,18 @@ const Index = () => {
isView={isView} isView={isView}
/> : '' /> : ''
} }
{
isPatrol || isAnomaly ?
<InputPickers
key={codeRoadSel} // keyselector
title='线路编码:'
placeholder='请选择或输入您所在的道路'
value={codeRoad}
onInput={setCodeRoad}
selector={codeRoadSel}
isView={isView}
/> : ''
}
{ {
isPatrol || isAnomaly ? isPatrol || isAnomaly ?

Loading…
Cancel
Save