|
|
@ -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' > |
|
|
|