Authored by QC-L

完成筛选功能 review by 黄敬囿

@@ -8,6 +8,7 @@ import sort from '../../static/images/sort.png'; @@ -8,6 +8,7 @@ import sort from '../../static/images/sort.png';
8 import sortUp from '../../static/images/sort-up.png'; 8 import sortUp from '../../static/images/sort-up.png';
9 import sortDown from '../../static/images/sort-down.png'; 9 import sortDown from '../../static/images/sort-down.png';
10 import './index.scss'; 10 import './index.scss';
  11 +import router from '../../router/index';
11 12
12 @connect(({ filterMenu }) => { 13 @connect(({ filterMenu }) => {
13 return {filterMenu} 14 return {filterMenu}
@@ -74,6 +75,13 @@ export default class filterMenu extends Component { @@ -74,6 +75,13 @@ export default class filterMenu extends Component {
74 }); 75 });
75 } 76 }
76 77
  78 + goToFilter() {
  79 + let { screen } = this.props;
  80 + router.go('filter', {
  81 + ...screen
  82 + });
  83 + }
  84 +
77 render() { 85 render() {
78 let {tabs, hasFilter, tabClass, filterMenu, fromPage} = this.props; 86 let {tabs, hasFilter, tabClass, filterMenu, fromPage} = this.props;
79 let {curOrder} = this.state; 87 let {curOrder} = this.state;
@@ -114,10 +122,10 @@ export default class filterMenu extends Component { @@ -114,10 +122,10 @@ export default class filterMenu extends Component {
114 </View> 122 </View>
115 { 123 {
116 hasFilter && 124 hasFilter &&
117 - <Navigator className="filter-btn" url="/pages/filter/index" hover-class="none"> 125 + <View className="filter-btn" onClick={this.goToFilter} hover-class="none">
118 <Image src={filterIcon} className="filter-icon"></Image> 126 <Image src={filterIcon} className="filter-icon"></Image>
119 <Text className="text">筛选</Text> 127 <Text className="text">筛选</Text>
120 - </Navigator> 128 + </View>
121 } 129 }
122 </View> 130 </View>
123 ) 131 )
@@ -29,7 +29,9 @@ export default class Search extends Component { @@ -29,7 +29,9 @@ export default class Search extends Component {
29 } 29 }
30 30
31 componentDidMount () { 31 componentDidMount () {
32 - searchModel.getFilterData().then(ret => { 32 + console.log(this.$router);
  33 + let { params } = this.$router;
  34 + searchModel.getFilterData(params).then(ret => {
33 if (ret && ret.code === 200) { 35 if (ret && ret.code === 200) {
34 this.setState({ 36 this.setState({
35 filter: ret.data && ret.data.filter || [] 37 filter: ret.data && ret.data.filter || []
@@ -3,13 +3,18 @@ import { View, Button } from '@tarojs/components'; @@ -3,13 +3,18 @@ import { View, Button } from '@tarojs/components';
3 import { SearchBar, FilterMenu, ProductList, PageTitle } from '../../components'; 3 import { SearchBar, FilterMenu, ProductList, PageTitle } from '../../components';
4 import { common as commonModel } from '../../models'; 4 import { common as commonModel } from '../../models';
5 import { connect } from '@tarojs/redux'; 5 import { connect } from '@tarojs/redux';
6 - 6 +import { bindActionCreators } from 'redux';
  7 +import { clearFilter } from '../../actions/filterData';
7 import './index.scss'; 8 import './index.scss';
8 9
9 @connect(({ filterMenu, filterData }) => ({ 10 @connect(({ filterMenu, filterData }) => ({
10 filterMenu, 11 filterMenu,
11 filterData 12 filterData
12 -})) 13 +}), (dispatch) => {
  14 + return bindActionCreators({
  15 + clearFilter
  16 + }, dispatch);
  17 +})
13 18
14 export default class SearchList extends Component { 19 export default class SearchList extends Component {
15 constructor(props) { 20 constructor(props) {
@@ -67,7 +72,6 @@ export default class SearchList extends Component { @@ -67,7 +72,6 @@ export default class SearchList extends Component {
67 } 72 }
68 } 73 }
69 74
70 - params.gender = ''  
71 75
72 // 初始化数据 76 // 初始化数据
73 tabs.map(item => { 77 tabs.map(item => {
@@ -101,6 +105,11 @@ export default class SearchList extends Component { @@ -101,6 +105,11 @@ export default class SearchList extends Component {
101 this.getProductData(nextProps.filterMenu); 105 this.getProductData(nextProps.filterMenu);
102 } 106 }
103 107
  108 + componentWillUnmount() {
  109 + let { clearFilter } = this.props;
  110 + clearFilter();
  111 + }
  112 +
104 onScroll(e) { 113 onScroll(e) {
105 if (e.detail.scrollTop > 72 && !this.state.isFixed) { 114 if (e.detail.scrollTop > 72 && !this.state.isFixed) {
106 this.setState({ 115 this.setState({
@@ -193,8 +202,6 @@ export default class SearchList extends Component { @@ -193,8 +202,6 @@ export default class SearchList extends Component {
193 202
194 if (order) { 203 if (order) {
195 params.order = order; 204 params.order = order;
196 - } else {  
197 - // params.type = order ? '' : type;  
198 } 205 }
199 206
200 // 系列,品牌,品类 207 // 系列,品牌,品类
@@ -260,15 +267,15 @@ export default class SearchList extends Component { @@ -260,15 +267,15 @@ export default class SearchList extends Component {
260 searchList = latelySearch || [] 267 searchList = latelySearch || []
261 } 268 }
262 console.log(searchList); 269 console.log(searchList);
263 - if (searchList.length >= 10) {  
264 - searchList.pop();  
265 - }  
266 - searchList.unshift({search_word: e.detail.value});  
267 - try {  
268 - Taro.setStorageSync('latelySearch', searchList);  
269 - } catch (error) {  
270 - console.log(error);  
271 - } 270 + if (searchList.length >= 10) {
  271 + searchList.pop();
  272 + }
  273 + searchList.unshift({search_word: e.detail.value});
  274 + try {
  275 + Taro.setStorageSync('latelySearch', searchList);
  276 + } catch (error) {
  277 + console.log(error);
  278 + }
272 } 279 }
273 280
274 render() { 281 render() {
@@ -307,7 +314,7 @@ export default class SearchList extends Component { @@ -307,7 +314,7 @@ export default class SearchList extends Component {
307 <PageTitle pageTitle={pageTitle} selfClass="pd"></PageTitle> 314 <PageTitle pageTitle={pageTitle} selfClass="pd"></PageTitle>
308 } 315 }
309 <View className={ this.state.fixed ? 'fixed' : '' }> 316 <View className={ this.state.fixed ? 'fixed' : '' }>
310 - <FilterMenu filterMenu={filterMenu} tabs={ this.state.tabs } fromPage="search" hasFilter = { this.state.hasFilter } > </FilterMenu> 317 + <FilterMenu filterMenu={ filterMenu } tabs = { this.state.tabs } fromPage = "search" hasFilter = { this.state.hasFilter } screen={this.$router.params} > </FilterMenu>
311 < /View> 318 < /View>
312 <ProductList list={productList[type]}></ProductList> 319 <ProductList list={productList[type]}></ProductList>
313 </ScrollView> 320 </ScrollView>
@@ -33,5 +33,8 @@ export default { @@ -33,5 +33,8 @@ export default {
33 }, 33 },
34 search: { 34 search: {
35 path: '/pages/search/index' 35 path: '/pages/search/index'
36 - } 36 + },
  37 + filter: {
  38 + path: '/pages/filter/index'
  39 + },
37 } 40 }