吃个甘蔗嚼一年 3 年之前
父節點
當前提交
5bff6647be

+ 42
- 6
src/components/List/index.jsx 查看文件

@@ -14,7 +14,7 @@ export default React.forwardRef((props, ref) => {
14 14
     onDataChange,
15 15
     noData,
16 16
     className,
17
-    refres,//刷新复位
17
+    refresOff,//刷新复位
18 18
     refresherEnabled,
19 19
     ...leftProps
20 20
   } = props
@@ -35,12 +35,44 @@ export default React.forwardRef((props, ref) => {
35 35
       setForceUpdate(forceUpdate + 1)
36 36
     }
37 37
   }
38
+  //下拉刷新回弹结束
39
+  const listPullDown = () => refresOff()
38 40
 
39
-  const loadingOff = () => {
40
-    refres()
41
+  const fetchList = () => {
42
+    if (!request) return;
43
+
44
+    setLoading(true)
45
+    request({
46
+      ...params,
47
+      pageSize,
48
+      pageNum: pageRef.current.current
49
+    }).then((res) => {
50
+      const { records, ...pageInfo } = res || {}
51
+
52
+      const lst = pageInfo.current === 1 ? records || [] : list.concat(records || [])
53
+      setList(lst)
54
+      setHasMore(pageInfo.current < pageInfo.pages)
55
+
56
+      if (onDataChange) {
57
+        onDataChange(lst, { paramsChanged: pageInfo.current === 1 })
58
+      }
59
+
60
+      pageRef.current = pageInfo
61
+      setLoading(false)
62
+
63
+    }).catch((err) => {
64
+
65
+      console.error(err)
66
+      setLoading(false)
67
+
68
+      if (onError) {
69
+        onError(err)
70
+      }
71
+    })
41 72
   }
42 73
 
43
-  const fetchList = () => {
74
+  //刷新的请求
75
+  const getList = () => {
44 76
     if (!request) return;
45 77
 
46 78
     setLoading(true)
@@ -50,6 +82,7 @@ export default React.forwardRef((props, ref) => {
50 82
       pageNum: pageRef.current.current
51 83
     }).then((res) => {
52 84
       const { records, ...pageInfo } = res || {}
85
+
53 86
       const lst = pageInfo.current === 1 ? records || [] : list.concat(records || [])
54 87
       setList(lst)
55 88
       setHasMore(pageInfo.current < pageInfo.pages)
@@ -59,9 +92,13 @@ export default React.forwardRef((props, ref) => {
59 92
       }
60 93
 
61 94
       pageRef.current = pageInfo
95
+      listPullDown()
96
+
62 97
       setLoading(false)
63 98
 
64 99
     }).catch((err) => {
100
+      Taro.stopPullDownRefresh()
101
+
65 102
       console.error(err)
66 103
       setLoading(false)
67 104
 
@@ -107,8 +144,7 @@ export default React.forwardRef((props, ref) => {
107 144
       scrollY
108 145
       enhanced
109 146
       refresherEnabled={refresherEnabled}
110
-
111
-      onRefresherrefresh={fetchRef.current = fetchList}
147
+      onRefresherrefresh={getList}
112 148
       onScrollToLower={handleScrollToLower}
113 149
       className={`${className} ${uqCls} list-view`}
114 150
     >

+ 5
- 2
src/shop/components/ShopKeeper/shopKeeper.jsx 查看文件

@@ -45,6 +45,7 @@ export default (props) => {
45 45
       title: '刷新成功',
46 46
       icon: 'none'
47 47
     })
48
+
48 49
     setTimeout(() => {
49 50
       setRefres(true)
50 51
 
@@ -158,13 +159,14 @@ export default (props) => {
158 159
           {/* 未核销 */}
159 160
           {activeTab === 0 &&
160 161
             <view style={{ height: '45vh' }}>
162
+
161 163
               <List
162 164
                 style={{ height: '100%' }}
163 165
                 request={getVerifiedOrder}
164 166
                 params={queryParams}
165 167
                 onDataChange={setAllList}
166 168
                 refresherEnabled={refres}
167
-                refres={refresOff}
169
+                refresOff={refresOff}
168 170
                 noData={<NoData />}
169 171
                 render={({ item, index }) =>
170 172
                   <ShopUnused key={(index)} item={item} />}
@@ -182,8 +184,9 @@ export default (props) => {
182 184
                 request={getVerifiedOrder}
183 185
                 params={queryParams}
184 186
                 refresherEnabled={refres}
185
-
186 187
                 onDataChange={setAllList}
188
+                refresOff={refresOff}
189
+
187 190
                 render={({ item, index }) => <ShopUsed verifiedOrder={verifiedOrder} key={(index)} item={item} />}
188 191
               >
189 192
               </List>

+ 0
- 1
src/shop/components/Sparead/spreadMoney.jsx 查看文件

@@ -89,7 +89,6 @@ export default (props) => {
89 89
             params={queryParams}
90 90
             noData={<NoData />}
91 91
             refresherEnabled
92
-
93 92
             render={({ item, index }) => <ShopCommission key={(index)} item={item} />}
94 93
           >
95 94
           </List>

+ 1
- 1
src/shop/pages/spread/spreadIndex.config.js 查看文件

@@ -2,7 +2,7 @@ export default {
2 2
   navigationBarTitleText: '十公里',
3 3
   navigationStyle: 'custom',
4 4
   disableScroll: true,
5
-
5
+  enablePullDownRefresh: true,
6 6
   usingComponents: {
7 7
     "mp-tabbar": "weui-miniprogram/tabbar/tabbar",
8 8
     "mp-tabs": "../../../components/tabs/index",

+ 5
- 5
src/shop/pages/spread/spreadIndex.jsx 查看文件

@@ -1,6 +1,6 @@
1 1
 import React, { useState, useEffect, useRef } from 'react'
2 2
 import CustomNav from '@/components/CustomNav'
3
-import { useRouter } from '@tarojs/taro'
3
+import Taro, { useRouter } from '@tarojs/taro'
4 4
 import { getShopList, getShopMoney, getVerifiedOrder } from '@/services/shopBoss'
5 5
 import { withSubscribeMessage } from '@/utils/subscribeMessage'
6 6
 import withLayout from '@/layouts'
@@ -20,7 +20,7 @@ import { View } from '@tarojs/components'
20 20
 export default withLayout((props) => {
21 21
   const { router, person } = props
22 22
   const { params } = useRouter()
23
-  const { tab,shopOrderId } = params || {}
23
+  const { tab, shopOrderId } = params || {}
24 24
   const [currentTab, setCurrentTab] = useState(0)
25 25
   //顶部的商铺列表
26 26
   const [shopList, setShopList] = useState([])
@@ -29,7 +29,7 @@ export default withLayout((props) => {
29 29
   // const shopOrderId='1a8deba868489b0be19cba941e6f577e'
30 30
   const shopId = shop?.shopId
31 31
 
32
-  
32
+
33 33
   const [amountType, setAmountType] = useState('order')
34 34
   const [isVerified, setisVerified] = useState(0)
35 35
   const [shopMoney, setShopMoney] = useState([])
@@ -52,9 +52,9 @@ export default withLayout((props) => {
52 52
       const { shopList: list, shop: current } = res
53 53
       setShopList(list)
54 54
       if (shopOrderId) {
55
-        setShop(list.filter(x=>x.shopId==shopOrderId)[0])
55
+        setShop(list.filter(x => x.shopId == shopOrderId)[0])
56 56
       }
57
-      else{
57
+      else {
58 58
         setShop(current)
59 59
       }
60 60
     })