|
@@ -1,40 +1,68 @@
|
1
|
1
|
import { useEffect, useState } from "react"
|
2
|
|
-import Taro from "@tarojs/taro"
|
|
2
|
+import Taro, {useDidShow}from "@tarojs/taro"
|
3
|
3
|
import { View, ScrollView } from "@tarojs/components"
|
4
|
4
|
import CustomNav from "@/components/CustomNav"
|
5
|
5
|
import NullCard from "@/components/NullCard";
|
|
6
|
+import Footer from "@/components/Footer";
|
6
|
7
|
import withLayout from '@/layouts'
|
7
|
|
-import { getMachineryList } from '@/services/machinery'
|
8
|
8
|
import { useModel } from "@/store"
|
|
9
|
+import { getMachineryList } from '@/services/machinery'
|
9
|
10
|
import MachineryCard from './Card'
|
10
|
11
|
import './style.less'
|
11
|
12
|
|
12
|
13
|
export default withLayout((props) => {
|
13
|
14
|
const { location } = useModel('location')
|
14
|
15
|
const [machinery, setMachinery] = useState([])
|
|
16
|
+ const [currentPage, setCurrentPage] = useState(1)
|
|
17
|
+ const [isMore, setIsMore] = useState(false)
|
|
18
|
+
|
15
|
19
|
const goDetail = (val) => {
|
16
|
20
|
Taro.navigateTo({ url: `/pages/machineryDetail/index?id=${val}` });
|
17
|
21
|
}
|
18
|
22
|
const goMap = (val) => {
|
19
|
23
|
Taro.navigateTo({ url: `/pages/machineryMap/index?id=${val}` });
|
20
|
24
|
}
|
21
|
|
- useEffect(() => {
|
22
|
|
- getMachineryList({ location: location }).then((res) => {
|
23
|
|
- setMachinery(res.records)
|
|
25
|
+ // 上拉加载
|
|
26
|
+ const handleScrollToLower = () => {
|
|
27
|
+ setCurrentPage(currentPage + 1)
|
|
28
|
+ }
|
|
29
|
+ const getList = () => {
|
|
30
|
+ getMachineryList({ location: location,pageNum: currentPage }).then(res => {
|
|
31
|
+ const lst = currentPage === 1 ? res.records || [] : machinery.concat(res.records || [])
|
|
32
|
+ //长列表加载当下一页没有数据时
|
|
33
|
+ if (res.records.length == 0 && currentPage != 1) {
|
|
34
|
+ setIsMore(true)
|
|
35
|
+ return
|
|
36
|
+ }
|
|
37
|
+ setMachinery(lst)
|
24
|
38
|
})
|
25
|
|
- }, [location])
|
|
39
|
+ }
|
|
40
|
+ useDidShow(() => {
|
|
41
|
+ getList();
|
|
42
|
+ })
|
|
43
|
+ useEffect(() => {
|
|
44
|
+ getList();
|
|
45
|
+ }, [currentPage,location])
|
|
46
|
+
|
26
|
47
|
return (
|
27
|
48
|
<View className='page-index'>
|
28
|
49
|
<View className='index-navbar'>
|
29
|
50
|
<CustomNav title='农机列表' />
|
30
|
51
|
</View>
|
31
|
52
|
<View className='index-container machineryListContent'>
|
32
|
|
- <ScrollView scrollY style={{ height: '100%' }}>
|
|
53
|
+ <ScrollView scrollY
|
|
54
|
+ enhanced
|
|
55
|
+ onScrollToLower={isMore ? '' : handleScrollToLower}
|
|
56
|
+ style={{ height: '100%' }}
|
|
57
|
+ >
|
33
|
58
|
{
|
34
|
59
|
machinery.length === 0 ? <NullCard value='您还没有农机!' /> :
|
35
|
|
- machinery?.map((item) => {
|
36
|
|
- return <MachineryCard value={item} key={item.machineryId} onClick={() => goDetail(item.machineryId)} goMap={() => goMap(item.machineryId)} />
|
37
|
|
- })
|
|
60
|
+ machinery?.map((item) => {
|
|
61
|
+ return <MachineryCard value={item} key={item.machineryId} onClick={() => goDetail(item.machineryId)} goMap={() => goMap(item.machineryId)} />
|
|
62
|
+ })
|
|
63
|
+ }
|
|
64
|
+ {
|
|
65
|
+ machinery.length === 0 || isMore && <Footer />
|
38
|
66
|
}
|
39
|
67
|
</ScrollView>
|
40
|
68
|
</View>
|