|
@@ -1,4 +1,4 @@
|
1
|
|
-import { useState, useEffect } from 'react'
|
|
1
|
+import { useState, useEffect, useCallback, useRef } from 'react'
|
2
|
2
|
import withLayout from '@/layout'
|
3
|
3
|
import { ScrollView, Input } from '@tarojs/components'
|
4
|
4
|
import '@/assets/css/iconfont.css'
|
|
@@ -8,71 +8,18 @@ import { API_MANAGE_CUSTOMER_LIST, API_MY_BUILDINGIDS } from '@/constants/api'
|
8
|
8
|
import './index.scss'
|
9
|
9
|
import ResidentListItem from '../components/ResidentListItem/index'
|
10
|
10
|
|
11
|
|
-export default withLayout(() => {
|
12
|
|
- // const [FilterMenu] = useState([
|
13
|
|
- // { name: '报备', id: 1 },
|
14
|
|
- // { name: '到访', id: 2 },
|
15
|
|
- // { name: '认筹', id: 3 },
|
16
|
|
- // { name: '认购', id: 4 },
|
17
|
|
- // { name: '签约', id: 5 },
|
18
|
|
- // { name: '报备无效', id: 6 },
|
19
|
|
- // { name: '报备过期', id: 7 }
|
20
|
|
- // ])
|
21
|
|
- // const [CurrentFilterMenuId, setCurrentFilterMenuId] = useState(null)
|
22
|
|
-
|
23
|
|
- // const CutFilter = (item) => {
|
24
|
|
- // return () => {
|
25
|
|
- // setCurrentFilterMenuId(item.id === CurrentFilterMenuId ? null : item.id)
|
26
|
|
- // }
|
27
|
|
- // }
|
28
|
|
-
|
29
|
|
- const user = useSelector(state => state.user)
|
|
11
|
+export default withLayout((props) => {
|
|
12
|
+ const { person } = props
|
|
13
|
+
|
30
|
14
|
const [BuildingIds, setBuildingIds] = useState([])
|
31
|
15
|
const [PageList, setPageList] = useState([])
|
32
|
16
|
const [IsPull, setPull] = useState(false)
|
33
|
|
- const [PersonId, setPersonId] = useState(null)
|
34
|
|
- const [pageNumber, setPageNumber] = useState(1)
|
35
|
17
|
const [HasNextPage, setHasNextPage] = useState(true)
|
36
|
18
|
const [CurrentBuildingId, setCurrentBuildingId] = useState(null)
|
37
|
19
|
const [CurrentBuildingName, setCurrentBuildingName] = useState(null)
|
38
|
|
- const [FilterData, setFilterData] = useState({})
|
39
|
|
-
|
40
|
|
- useEffect(() => {
|
41
|
|
- if (user?.userInfo?.person?.personId) {
|
42
|
|
- setPersonId(user.userInfo.person.personId)
|
43
|
|
- }
|
44
|
|
- }, [user])
|
45
|
|
-
|
46
|
|
- useEffect(() => {
|
47
|
|
- if (PersonId) {
|
48
|
|
- GetMyBuildingIds()
|
49
|
|
- }
|
50
|
|
- }, [PersonId])
|
51
|
|
-
|
52
|
|
- useEffect(() => {
|
53
|
|
- if (pageNumber === 1) {
|
54
|
|
- GetPageList()
|
55
|
|
- } else {
|
56
|
|
- setPageNumber(1)
|
57
|
|
- }
|
58
|
|
- }, [FilterData])
|
59
|
|
-
|
60
|
|
- useEffect(() => {
|
61
|
|
- if (BuildingIds.length) {
|
62
|
|
- setCurrentBuildingId(BuildingIds[0].buildingId)
|
63
|
|
- setCurrentBuildingName(BuildingIds[0].name)
|
64
|
|
- }
|
65
|
|
- }, [BuildingIds])
|
66
|
|
-
|
67
|
|
- useEffect(() => {
|
68
|
|
- if (CurrentBuildingId) {
|
69
|
|
- if (pageNumber === 1) {
|
70
|
|
- GetPageList()
|
71
|
|
- } else {
|
72
|
|
- setPageNumber(1)
|
73
|
|
- }
|
74
|
|
- }
|
75
|
|
- }, [CurrentBuildingId])
|
|
20
|
+ const [page, setPage] = useState({ pageNumber: 1 })
|
|
21
|
+ const queryParamsRef = useRef({})
|
|
22
|
+ const getListRef = useRef()
|
76
|
23
|
|
77
|
24
|
const GetMyBuildingIds = () => {
|
78
|
25
|
fetch({ url: API_MY_BUILDINGIDS, method: 'get' }).then((res) => {
|
|
@@ -80,52 +27,40 @@ export default withLayout(() => {
|
80
|
27
|
})
|
81
|
28
|
}
|
82
|
29
|
|
83
|
|
- // useEffect(() => {
|
84
|
|
- // if(CurrentFilterMenuId) {
|
85
|
|
- // if(pageNumber === 1) {
|
86
|
|
- // GetPageList()
|
87
|
|
- // } else {
|
88
|
|
- // setPageNumber(1)
|
89
|
|
- // }
|
90
|
|
- // }
|
91
|
|
- // }, [CurrentFilterMenuId])
|
92
|
|
-
|
93
|
30
|
const PageRefresh = () => { // 页面下拉刷新回调
|
94
|
31
|
setPull(true)
|
95
|
32
|
}
|
96
|
33
|
|
97
|
|
- const GetPageList = () => {
|
|
34
|
+ getListRef.current = (params) => {
|
|
35
|
+ if (!CurrentBuildingId) return;
|
|
36
|
+
|
98
|
37
|
setHasNextPage(false)
|
99
|
|
- fetch({ url: API_MANAGE_CUSTOMER_LIST, method: 'get', payload: { pageNumber, pageSize: 10, ...FilterData, buildingId: CurrentBuildingId } }).then((res) => {
|
100
|
|
- setPageList(pageNumber === 1 ? res.records || [] : PageList.concat(res.records || []))
|
|
38
|
+ fetch({
|
|
39
|
+ url: API_MANAGE_CUSTOMER_LIST,
|
|
40
|
+ payload: {
|
|
41
|
+ pageSize: 10,
|
|
42
|
+ ...params,
|
|
43
|
+ ...queryParamsRef.current,
|
|
44
|
+ buildingId: CurrentBuildingId
|
|
45
|
+ },
|
|
46
|
+ }).then((res) => {
|
|
47
|
+ setPageList(res.current === 1 ? res.records || [] : PageList.concat(res.records || []))
|
101
|
48
|
setHasNextPage(res.current < res.pages)
|
102
|
49
|
setPull(false)
|
103
|
50
|
})
|
104
|
51
|
}
|
105
|
52
|
|
106
|
|
- const PageLoadMore = () => { // 页面上拉加载更多
|
107
|
|
- if (HasNextPage) {
|
108
|
|
- setPageNumber(pageNumber + 1)
|
109
|
|
- }
|
110
|
|
- }
|
111
|
|
-
|
112
|
|
- useEffect(() => { // 下拉刷新触发
|
113
|
|
- if (IsPull) {
|
114
|
|
- if (pageNumber === 1) {
|
115
|
|
- GetPageList()
|
116
|
|
- } else {
|
117
|
|
- setPageNumber(1)
|
118
|
|
- }
|
119
|
|
- }
|
120
|
|
- }, [IsPull])
|
121
|
|
-
|
122
|
53
|
const PickerChange = (e) => {
|
123
|
54
|
setCurrentBuildingId(BuildingIds[e.detail.value - 0].buildingId)
|
124
|
55
|
setCurrentBuildingName(BuildingIds[e.detail.value - 0].name)
|
125
|
56
|
}
|
126
|
57
|
|
127
|
58
|
const SearchConfirm = (e) => {
|
128
|
|
- setFilterData({ ...FilterData, keywords: e.detail.value })
|
|
59
|
+ queryParamsRef.current = {
|
|
60
|
+ ...queryParamsRef.current,
|
|
61
|
+ keywords: e.detail.value,
|
|
62
|
+ }
|
|
63
|
+ setPage({ pageNumber: 1 })
|
129
|
64
|
}
|
130
|
65
|
|
131
|
66
|
const ListChange = (index) => {
|
|
@@ -136,6 +71,42 @@ export default withLayout(() => {
|
136
|
71
|
}
|
137
|
72
|
}
|
138
|
73
|
|
|
74
|
+ // 页面上拉加载更多
|
|
75
|
+ const PageLoadMore = () => {
|
|
76
|
+ if (HasNextPage) {
|
|
77
|
+ setPage({ pageNumber: page.pageNumber + 1 })
|
|
78
|
+ }
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ useEffect(() => {
|
|
82
|
+ GetMyBuildingIds()
|
|
83
|
+ }, [])
|
|
84
|
+
|
|
85
|
+ useEffect(() => {
|
|
86
|
+ if (BuildingIds.length) {
|
|
87
|
+ setCurrentBuildingId(BuildingIds[0].buildingId)
|
|
88
|
+ setCurrentBuildingName(BuildingIds[0].name)
|
|
89
|
+ }
|
|
90
|
+ }, [BuildingIds])
|
|
91
|
+
|
|
92
|
+ // 选择楼盘
|
|
93
|
+ useEffect(() => {
|
|
94
|
+ if (CurrentBuildingId) {
|
|
95
|
+ setPage({ pageNumber: 1 })
|
|
96
|
+ }
|
|
97
|
+ }, [CurrentBuildingId])
|
|
98
|
+
|
|
99
|
+ // 下拉刷新
|
|
100
|
+ useEffect(() => {
|
|
101
|
+ if (IsPull) {
|
|
102
|
+ setPage({ pageNumber: 1 })
|
|
103
|
+ }
|
|
104
|
+ }, [IsPull])
|
|
105
|
+
|
|
106
|
+ useEffect(() => {
|
|
107
|
+ getListRef.current(page)
|
|
108
|
+ }, [page])
|
|
109
|
+
|
139
|
110
|
return (
|
140
|
111
|
<view className='Page residentManager flex-v'>
|
141
|
112
|
|