🎈 perf(购物页面): 新增下拉刷新数据
This commit is contained in:
parent
d6e9107276
commit
4f09a902ac
@ -1,5 +1,6 @@
|
|||||||
import { View, Text } from "@tarojs/components"
|
import { View, Text } from "@tarojs/components"
|
||||||
import { memo } from "react"
|
import { memo } from "react"
|
||||||
|
import IconFont from "../iconfont/iconfont"
|
||||||
import style from "./index.module.scss"
|
import style from "./index.module.scss"
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
@ -9,12 +10,10 @@ type Params = {
|
|||||||
|
|
||||||
export default memo(({onClose, styleObj = {}}:Params) => {
|
export default memo(({onClose, styleObj = {}}:Params) => {
|
||||||
return (
|
return (
|
||||||
<View
|
<View style={styleObj} className={style.icon_a_cuowuwrong_self} onClick={onClose}>
|
||||||
style={styleObj}
|
<View className={style.icon_a_btn}>
|
||||||
className={style.icon_a_cuowuwrong_self}
|
<IconFont name='icon-guanbi' size={30} color='#ccc'></IconFont>
|
||||||
onClick={onClose}
|
|
||||||
>
|
|
||||||
<Text className={`iconfont icon-guanbi ${style.icon_a_btn}`}></Text>
|
|
||||||
</View>
|
</View>
|
||||||
|
</View>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
height: 60px;
|
height: 60px;
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
padding-left: 60px;
|
padding-left: 60px;
|
||||||
padding-right: 30px;
|
|
||||||
background: #eee;
|
background: #eee;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -45,7 +45,7 @@ export const Shopping: FC = memo(() => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
interface InternalContainer { }
|
interface InternalContainer {}
|
||||||
|
|
||||||
const ShoppingCartContainer: FC<InternalContainer> = () => {
|
const ShoppingCartContainer: FC<InternalContainer> = () => {
|
||||||
const { isManageStatus, setManageStatus, selectedAmount, currentCheckedPurchaserId, currentCheckedSaleMode, colorStore, setColorStore } = useShoppingContext()
|
const { isManageStatus, setManageStatus, selectedAmount, currentCheckedPurchaserId, currentCheckedSaleMode, colorStore, setColorStore } = useShoppingContext()
|
||||||
@ -59,12 +59,17 @@ const ShoppingCartContainer: FC<InternalContainer> = () => {
|
|||||||
|
|
||||||
const { fetchData, state } = ShoppingCartListApi()
|
const { fetchData, state } = ShoppingCartListApi()
|
||||||
|
|
||||||
|
const [searchOptions, setSearchOptions] = useState({
|
||||||
|
short_name_or_phone: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData(searchOptions)
|
||||||
|
}, [searchOptions])
|
||||||
|
|
||||||
// 输入了搜索关键字
|
// 输入了搜索关键字
|
||||||
const getSearchData = useCallback(e => {
|
const getSearchData = useCallback(e => {
|
||||||
fetchData({ short_name_or_phone: e })
|
setSearchOptions(prev => ({ ...prev, short_name_or_phone: e }))
|
||||||
// pageNum.current.page = 1
|
|
||||||
// setOrderData(() => ({ list: [], total: 0 }))
|
|
||||||
// setSearchField((val) => ({ ...val, name: e, size: 10 }))
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const [shoppingCartData, setShoppingCartData] = useState<{ list: ShoppingCartData[]; total: number }>({ list: [], total: 0 })
|
const [shoppingCartData, setShoppingCartData] = useState<{ list: ShoppingCartData[]; total: number }>({ list: [], total: 0 })
|
||||||
@ -104,7 +109,7 @@ const ShoppingCartContainer: FC<InternalContainer> = () => {
|
|||||||
if (!targetGoodsKind) return Taro.showToast({ title: '请先选择客户', icon: 'error' })
|
if (!targetGoodsKind) return Taro.showToast({ title: '请先选择客户', icon: 'error' })
|
||||||
const checkedGoodsKind = Object.values(targetGoodsKind).reduce((prev, item: Goods) => {
|
const checkedGoodsKind = Object.values(targetGoodsKind).reduce((prev, item: Goods) => {
|
||||||
if (item.checked) {
|
if (item.checked) {
|
||||||
return [...prev,item.id]
|
return [...prev, item.id]
|
||||||
}
|
}
|
||||||
return prev
|
return prev
|
||||||
}, [])
|
}, [])
|
||||||
@ -153,6 +158,24 @@ const ShoppingCartContainer: FC<InternalContainer> = () => {
|
|||||||
setColorStore(() => tempObject)
|
setColorStore(() => tempObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载刷新数据
|
||||||
|
const [refreshStatus, setRefreshStatus] = useState(false)
|
||||||
|
|
||||||
|
// 下拉刷新
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
setRefreshStatus(true)
|
||||||
|
const res = await fetchData(searchOptions)
|
||||||
|
if (res.success) {
|
||||||
|
console.log('请求 成功')
|
||||||
|
setRefreshStatus(false)
|
||||||
|
Taro.showToast({ title: '刷新成功', icon: 'success' })
|
||||||
|
} else {
|
||||||
|
console.log('请求 失败')
|
||||||
|
Taro.showToast({ title: '刷新失败', icon: 'error' })
|
||||||
|
setRefreshStatus(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={classnames('flex-col', styles.shopping)} id='shoppingContainer'>
|
<View className={classnames('flex-col', styles.shopping)} id='shoppingContainer'>
|
||||||
<View className={styles['shopping--topBar']} id='topBar'>
|
<View className={styles['shopping--topBar']} id='topBar'>
|
||||||
@ -168,7 +191,11 @@ const ShoppingCartContainer: FC<InternalContainer> = () => {
|
|||||||
</View>
|
</View>
|
||||||
<View className={classnames('flex-item', 'flex-col', styles['shopping--context'])}>
|
<View className={classnames('flex-item', 'flex-col', styles['shopping--context'])}>
|
||||||
<View className={classnames(styles.shopping__list__container, 'flex-item')} style={{ height: listHeight }}>
|
<View className={classnames(styles.shopping__list__container, 'flex-item')} style={{ height: listHeight }}>
|
||||||
<InfiniteScroll statusMore={statusMore}>
|
<InfiniteScroll
|
||||||
|
statusMore={statusMore}
|
||||||
|
refresherEnabled={true}
|
||||||
|
selfOnRefresherRefresh={handleRefresh}
|
||||||
|
refresherTriggered={refreshStatus}>
|
||||||
{!!shoppingCartData?.list?.length &&
|
{!!shoppingCartData?.list?.length &&
|
||||||
shoppingCartData?.list?.map((item, index) => {
|
shoppingCartData?.list?.map((item, index) => {
|
||||||
return <ItemList itemData={item} key={index}></ItemList>
|
return <ItemList itemData={item} key={index}></ItemList>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user