diff --git a/src/components/sp-radio/index.js b/src/components/sp-radio/index.js index 0139eae..bb0d3ea 100644 --- a/src/components/sp-radio/index.js +++ b/src/components/sp-radio/index.js @@ -24,7 +24,7 @@ export default class index extends PureComponent { {SpRadioData.map((item, index) => { return ( activeHandle(item)} > diff --git a/src/pages/planSelection/index.js b/src/pages/planSelection/index.js index 8d8a321..f14a627 100644 --- a/src/pages/planSelection/index.js +++ b/src/pages/planSelection/index.js @@ -51,8 +51,8 @@ export default class PlanSelection extends PureComponent { this.state = { isActive: null, allShopList: [], - shopList: [], searchKeyword: '', + listScrollTop: 0, loading: false } } @@ -60,7 +60,8 @@ export default class PlanSelection extends PureComponent { onSearchChange = (value) => { this.setState((prevState) => ({ searchKeyword: value, - shopList: filterShopsByKeyword(prevState.allShopList, value) + // 强制 ScrollView 回到顶部并刷新,避免复用旧列表节点 + listScrollTop: prevState.listScrollTop === 0 ? 0.01 : 0 })) } @@ -90,11 +91,10 @@ export default class PlanSelection extends PureComponent { const result = await api.planSelection.getShopList(data) console.log(result) const allShopList = result.list || [] - this.setState((prevState) => ({ + this.setState({ allShopList, - shopList: filterShopsByKeyword(allShopList, prevState.searchKeyword), loading: false - })) + }) } componentDidMount() { @@ -102,7 +102,9 @@ export default class PlanSelection extends PureComponent { } render() { - const { isActive, allShopList, shopList, searchKeyword, loading } = this.state + const { isActive, allShopList, searchKeyword, listScrollTop, loading } = this.state + // 每次渲染按关键词实时过滤,避免重复搜索时 shopList 与关键词不同步 + const shopList = filterShopsByKeyword(allShopList, searchKeyword) return ( @@ -128,10 +130,17 @@ export default class PlanSelection extends PureComponent { - + {loading && 正在加载...} {!loading && shopList.length > 0 && (