diff --git a/weapp/src/packages/patrol/index.jsx b/weapp/src/packages/patrol/index.jsx index e1e18170..d756cb2f 100644 --- a/weapp/src/packages/patrol/index.jsx +++ b/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 ( { - !isSuperAdmin && + (!isSuperAdmin || isView) && 上报类型 @@ -477,7 +475,7 @@ const Index = () => { } { isView ? - 删除 : + isSuperAdmin && 删除 : 上报 } diff --git a/weapp/src/packages/patrolView/index.config.js b/weapp/src/packages/patrolView/index.config.js index e69de29b..d4a27101 100644 --- a/weapp/src/packages/patrolView/index.config.js +++ b/weapp/src/packages/patrolView/index.config.js @@ -0,0 +1,3 @@ +export default { + onReachBottomDistance: 50 +} \ No newline at end of file diff --git a/weapp/src/packages/patrolView/index.jsx b/weapp/src/packages/patrolView/index.jsx index c78b6b07..e152cb07 100644 --- a/weapp/src/packages/patrolView/index.jsx +++ b/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() { { - showListData && showListData.length > 0 ? showListData && showListData.map((e, index) => { + listData && listData.length > 0 ? listData && listData.map((e, index) => { return ( handleDetail(index)}> diff --git a/weapp/src/pages/user/index.jsx b/weapp/src/pages/user/index.jsx index b2f24a95..7108d37e 100644 --- a/weapp/src/pages/user/index.jsx +++ b/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' }) }