Browse Source

数据筛选

release_0.0.4
liujiangyong 2 years ago
parent
commit
7e87891186
  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) {
Taro.showToast({ title: '上报成功', icon: 'none', duration: 1500 })
setTimeout(() => {
Taro.reLaunch({
url: '/pages/home/index'
});
Taro.navigateBack()
}, 1500)
} else {
Taro.showToast({ title: res.data.message || '请求出错', icon: 'none' })
@ -285,7 +283,7 @@ const Index = () => {
return (
<View className='patrol'>
{
!isSuperAdmin &&
(!isSuperAdmin || isView) &&
<View className='report-type'>
<View className='text'>上报类型</View>
<RadioGroup onChange={handleTypeChange}>
@ -477,7 +475,7 @@ const Index = () => {
}
{
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>
}
</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 Taro, { useDidShow, useRouter } from '@tarojs/taro'
import Taro, { useDidShow, useRouter, useReachBottom } from '@tarojs/taro'
import { View, Picker, Input, Image } from '@tarojs/components'
import moment from 'moment'
import './index.scss'
@ -17,22 +17,26 @@ import conserveActiveIcon from '../../static/img/patrolView/conserve-active.svg'
function Index() {
const userInfo = Taro.getStorageSync('userInfo') || {};
const router = useRouter()
const { params: { limit } } = router
const { params: { filter } } = router
const [isPatrol, setIsPatrol] = useState(true)
const [datePicker, setDatePicker] = useState(moment().format('YYYY-MM-DD'))
const [listData, setListData] = useState([])
const [showListData, setShowListData] = useState([])
const [filterText, setFilterText] = useState('')
const [systemInfo, setSystemInfo] = useState('')
const [page, setPage] = useState(0)
const [num, setNum] = useState(Math.random())
const limit = 10
useEffect(() => {
getList()
}, [datePicker])
setPage(0)
setNum(Math.random())
}, [isPatrol, datePicker])
useEffect(() => {
setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve'))
}, [isPatrol])
getList(page == 0 ? true : false)
}, [num])
function dealError(error) {
Taro.showToast({
@ -42,21 +46,29 @@ function Index() {
});
throw new Error(error);
}
const getList = () => {
const getList = (isInit) => {
Taro.showLoading({ title: '加载中' })
request.get(
getReportList(),
{ startTime: datePicker + ' 00:00:00', endTime: datePicker + ' 23:59:59' }
).then(res => {
const data = {
limit,
page,
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()
if (res.statusCode == 200) {
let { data } = res
if (limit === 'my') {
data = data.filter(item => item.user.name === userInfo.name)
if (res.data.length === 0) {
Taro.showToast({
title: '没有更多了',
icon: 'none'
})
}
setListData(data)
setShowListData(data.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve'))
return data;
const temp = isInit ? [] : listData
const nextListData = temp.concat(res.data)
setListData(nextListData)
} else {
dealError(res.data.message || '请求出错');
}
@ -65,6 +77,13 @@ function Index() {
});
}
//
useReachBottom(() => {
console.log('onReachBottom')
setPage(page + 1)
setNum(Math.random())
})
useDidShow(() => {
let refresh = Taro.getStorageSync('refresh'); //
if (refresh) {
@ -88,20 +107,20 @@ function Index() {
}
const handleConfirm = e => {
let nextList = listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')
nextList = nextList.filter(item => item.road.includes(e.detail.value))
setShowListData(nextList)
setPage(0)
setNum(Math.random())
}
const handleInput = e => {
setFilterText(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 => {
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 (
@ -140,7 +159,7 @@ function Index() {
<View style={{ marginTop: '110px' }}>
{
showListData && showListData.length > 0 ? showListData && showListData.map((e, index) => {
listData && listData.length > 0 ? listData && listData.map((e, index) => {
return (
<View className='cardBox' key={index} onClick={() => handleDetail(index)}>
<View className='card-item' >

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

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

Loading…
Cancel
Save