Authored by 肖亚东

筛选逻辑重整 — review by 李其昌

... ... @@ -21,6 +21,7 @@ export default class FilterGroup extends Component {
static defaultProps = {
list: {},
selectList: {},
styleDic : {
'品类': 'group-text ', '性别': 'group-text ', '尺码': 'group-text square '
}
... ... @@ -35,18 +36,22 @@ export default class FilterGroup extends Component {
this.setState({filterId: list.filterId});
}
changeFilter(item) {
let {setFilter, filterData} = this.props;
// let {setFilter, filterData} = this.props;
if (filterData[this.state.filterId] && item.itemId === filterData[this.state.filterId]) {
setFilter({[this.state.filterId]: ''});
} else {
setFilter({[this.state.filterId]: item.itemId});
}
// if (filterData[this.state.filterId] && item.itemId === filterData[this.state.filterId]) {
// setFilter({[this.state.filterId]: ''});
// } else {
// setFilter({[this.state.filterId]: item.itemId});
// }
let {onChangeFilter} = this.props;
onChangeFilter({[this.state.filterId]: item.itemId});
}
render() {
let {list, filterData, styleDic} = this.props;
let {list, filterData, styleDic, selectList} = this.props;
let itemList = list.itemList || [];
return (
... ... @@ -63,14 +68,14 @@ export default class FilterGroup extends Component {
<View key={item.itemId} className="group-item">
{
list.filterName === '品牌' &&
<View className={filterData[list.filterId] === item.itemId ? 'group-img actived' : 'group-img'} onClick={this.changeFilter.bind(this, item)}>
<View className={selectList[list.filterId] === item.itemId ? 'group-img actived' : 'group-img'} onClick={this.changeFilter.bind(this, item)}>
<Image src={getImgUrl(item.itemUrl, 140, 70)} className="img" mode="aspectFit"/>
<View className="text">{item.itemName}</View>
</View>
}
{
list.filterName !== '品牌' &&
<View className={filterData[list.filterId] === item.itemId ? styleDic[list.filterName]+'actived' : styleDic[list.filterName]} onClick={this.changeFilter.bind(this, item)}>{item.itemName}</View>
<View className={selectList[list.filterId] === item.itemId ? styleDic[list.filterName]+'actived' : styleDic[list.filterName]} onClick={this.changeFilter.bind(this, item)}>{item.itemName}</View>
}
</View>
)
... ...
/* eslint-disable react/no-unused-state */
import Taro, { Component, navigateBack } from '@tarojs/taro';
import { View, Text, Navigator, Button } from '@tarojs/components';
import { FilterGroup, PageTitle } from '../../components';
... ... @@ -21,7 +22,7 @@ export default class Search extends Component {
super(...arguments);
this.state = {
filter: [],
selectFilter: {}
selectList: {}
};
}
... ... @@ -39,47 +40,45 @@ export default class Search extends Component {
});
}
});
let {selectList} = this.state;
selectList = this.props.filterData;
if (selectList) {
this.setState({
selectList
});
}
}
onChangeFilter(item) {
// let {setFilter, filterData} = this.props;
// if (filterData[this.state.filterId] && item.itemId === filterData[this.state.filterId]) {
// setFilter({[this.state.filterId]: ''});
// } else {
// setFilter({[this.state.filterId]: item.itemId});
// }
// console.log('================1111====================');
// console.log(item);
// console.log('=================11111================');
// let {selectFilter} = this.props;
// this.setState({
// selectFilter: item
// });
let {selectList} = this.state;
for (var key in item) {
selectList[key] = item[key]
}
// console.log('==================2222==================');
// console.log(selectFilter);
// console.log('==================2222==================');
this.setState({
selectList
});
}
onResetFilter() {
let {setFilter} = this.props;
let filter = {};
let {selectList} = this.state;
this.state.filter.map(item => {
filter[item.filterId] = {};
});
for (var key in selectList) {
selectList[key] = '';
}
setFilter(selectList);
setFilter(filter);
this.setState({
selectList
});
}
onConfirmSearch() {
console.log('====================================');
console.log(this.props.filterData);
console.log('====================================');
let {setFilter} = this.props;
let {selectList} = this.state;
setFilter(selectList);
wx.navigateBack({
delta: 1
... ... @@ -87,7 +86,7 @@ export default class Search extends Component {
}
render () {
let {filter} = this.state;
let {filter, selectList} = this.state;
return (
<View className="filter-page">
... ... @@ -96,7 +95,7 @@ export default class Search extends Component {
{
filter.map((item, index) => {
return (
<FilterGroup list={item} onChangeFilter={this.onChangeFilter.bind(this)} key={index}></FilterGroup>
<FilterGroup list={item} selectList={selectList} onChangeFilter={this.onChangeFilter.bind(this)} key={index}></FilterGroup>
)
})
}
... ...