Browse Source

Merge branch 'dev' of https://gitea.anxinyun.cn/gao.zhiyuan/Highways4Good into dev

release_0.0.4
巴林闲侠 2 years ago
parent
commit
903ba414bc
  1. 8
      weapp/src/packages/patrol/index.jsx
  2. 3
      weapp/src/packages/patrolView/index.config.js
  3. 67
      weapp/src/packages/patrolView/index.jsx
  4. 2
      weapp/src/pages/user/index.jsx

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

@ -184,9 +184,7 @@ const Index = () => {
if (res.statusCode == 200 || res.statusCode == 204) { if (res.statusCode == 200 || res.statusCode == 204) {
Taro.showToast({ title: '上报成功', icon: 'none', duration: 1500 }) Taro.showToast({ title: '上报成功', icon: 'none', duration: 1500 })
setTimeout(() => { setTimeout(() => {
Taro.reLaunch({ Taro.navigateBack()
url: '/pages/home/index'
});
}, 1500) }, 1500)
} else { } else {
Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' }) Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' })
@ -285,7 +283,7 @@ const Index = () => {
return ( return (
<View className='patrol'> <View className='patrol'>
{ {
!isSuperAdmin && (!isSuperAdmin || isView) &&
<View className='report-type'> <View className='report-type'>
<View className='text'>上报类型</View> <View className='text'>上报类型</View>
<RadioGroup onChange={handleTypeChange}> <RadioGroup onChange={handleTypeChange}>
@ -477,7 +475,7 @@ const Index = () => {
} }
{ {
isView ? isView ?
<AtButton type='primary' className='del-btn' onClick={deleteReport}>删除</AtButton> : isSuperAdmin && <AtButton type='primary' className='del-btn' onClick={deleteReport}>删除</AtButton> :
<AtButton type='primary' className='sub-btn' onClick={report}>上报</AtButton> <AtButton type='primary' className='sub-btn' onClick={report}>上报</AtButton>
} }
</View> </View>

3
weapp/src/packages/patrolView/index.config.js

@ -0,0 +1,3 @@
export default {
onReachBottomDistance: 50
}

67
weapp/src/packages/patrolView/index.jsx

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import Taro, { useDidShow, useRouter } from '@tarojs/taro' import Taro, { useDidShow, useRouter, useReachBottom } from '@tarojs/taro'
import { View, Picker, Input, Image } from '@tarojs/components' import { View, Picker, Input, Image } from '@tarojs/components'
import moment from 'moment' import moment from 'moment'
import './index.scss' import './index.scss'
@ -17,22 +17,26 @@ import conserveActiveIcon from '../../static/img/patrolView/conserve-active.svg'
function Index() { function Index() {
const userInfo = Taro.getStorageSync('userInfo') || {}; const userInfo = Taro.getStorageSync('userInfo') || {};
const router = useRouter() const router = useRouter()
const { params: { limit } } = router const { params: { filter } } = router
const [isPatrol, setIsPatrol] = useState(true) const [isPatrol, setIsPatrol] = useState(true)
const [datePicker, setDatePicker] = useState(moment().format('YYYY-MM-DD')) const [datePicker, setDatePicker] = useState(moment().format('YYYY-MM-DD'))
const [listData, setListData] = useState([]) const [listData, setListData] = useState([])
const [showListData, setShowListData] = useState([])
const [filterText, setFilterText] = useState('') const [filterText, setFilterText] = useState('')
const [systemInfo, setSystemInfo] = useState('') const [systemInfo, setSystemInfo] = useState('')
const [page, setPage] = useState(0)
const [num, setNum] = useState(Math.random())
const limit = 10
useEffect(() => { useEffect(() => {
getList() setPage(0)
}, [datePicker]) setNum(Math.random())
}, [isPatrol, datePicker])
useEffect(() => { useEffect(() => {
setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) getList(page == 0 ? true : false)
}, [isPatrol]) }, [num])
function dealError(error) { function dealError(error) {
Taro.showToast({ Taro.showToast({
@ -42,21 +46,29 @@ function Index() {
}); });
throw new Error(error); throw new Error(error);
} }
const getList = () => { const getList = (isInit) => {
Taro.showLoading({ title: '加载中' }) Taro.showLoading({ title: '加载中' })
request.get( const data = {
getReportList(), limit,
{ startTime: datePicker + ' 00:00:00', endTime: datePicker + ' 23:59:59' } page,
).then(res => { startTime: datePicker + ' 00:00:00',
endTime: datePicker + ' 23:59:59',
keyword: filterText,
reportType: isPatrol ? 'patrol' : 'conserve',
userId: filter === 'my' ? userInfo.id : '',
}
request.get(getReportList(), data).then(res => {
Taro.hideLoading() Taro.hideLoading()
if (res.statusCode == 200) { if (res.statusCode == 200) {
let { data } = res if (res.data.length === 0) {
if (limit === 'my') { Taro.showToast({
data = data.filter(item => item.user.name === userInfo.name) title: '没有更多了',
icon: 'none'
})
} }
setListData(data) const temp = isInit ? [] : listData
setShowListData(data.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) const nextListData = temp.concat(res.data)
return data; setListData(nextListData)
} else { } else {
dealError(res.data.message || '请求出错'); dealError(res.data.message || '请求出错');
} }
@ -65,6 +77,13 @@ function Index() {
}); });
} }
//
useReachBottom(() => {
console.log('onReachBottom')
setPage(page + 1)
setNum(Math.random())
})
useDidShow(() => { useDidShow(() => {
let refresh = Taro.getStorageSync('refresh'); // let refresh = Taro.getStorageSync('refresh'); //
if (refresh) { if (refresh) {
@ -88,20 +107,20 @@ function Index() {
} }
const handleConfirm = e => { const handleConfirm = e => {
let nextList = listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve') setPage(0)
nextList = nextList.filter(item => item.road.includes(e.detail.value)) setNum(Math.random())
setShowListData(nextList)
} }
const handleInput = e => { const handleInput = e => {
setFilterText(e.detail.value); setFilterText(e.detail.value);
if (!e.detail.value) { if (!e.detail.value) {
setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')); setPage(0)
setNum(Math.random())
} }
} }
const handleDetail = index => { const handleDetail = index => {
Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${showListData[index].id}` }) Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${listData[index].id}` })
} }
return ( return (
@ -140,7 +159,7 @@ function Index() {
<View style={{ marginTop: '110px' }}> <View style={{ marginTop: '110px' }}>
{ {
showListData && showListData.length > 0 ? showListData && showListData.map((e, index) => { listData && listData.length > 0 ? listData && listData.map((e, index) => {
return ( return (
<View className='cardBox' key={index} onClick={() => handleDetail(index)}> <View className='cardBox' key={index} onClick={() => handleDetail(index)}>
<View className='card-item' > <View className='card-item' >

2
weapp/src/pages/user/index.jsx

@ -24,7 +24,7 @@ const Index = ({ ...props }) => {
const toMyReport = () => { const toMyReport = () => {
Taro.navigateTo({ Taro.navigateTo({
url: '/packages/patrolView/index?limit=my' url: '/packages/patrolView/index?filter=my'
}) })
} }

Loading…
Cancel
Save