index.js
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* 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';
import {search as searchModel} from '../../models';
import { connect } from '@tarojs/redux';
import { bindActionCreators } from 'redux';
import { setFilter } from '../../actions/filterData';
import event from '../../utils/event.js'
import './index.scss';
import wx from '../../libs/wx';
@connect(({ filterData, filterMenu }) => ({
filterData,
filterMenu
}), (dispatch) => {
return bindActionCreators({
setFilter
}, dispatch);
})
export default class Search extends Component {
constructor() {
super(...arguments);
this.state = {
filter: [],
selectList: {}
};
}
config = {
navigationBarTitleText: '筛选'
}
componentDidMount () {
console.log(this.$router);
let { params } = this.$router;
if (params && params.query) {
params.query = decodeURI(params.query);
}
searchModel.getFilterData(params).then(ret => {
if (ret && ret.code === 200) {
this.setState({
filter: ret.data && ret.data.filter || []
});
}
});
let {selectList} = this.state;
selectList = this.props.filterData;
let brandValue = params['brand'];
if (brandValue) {
selectList['brand'] = brandValue;
}
if (selectList) {
this.setState({
selectList
});
}
}
onChangeFilter(item) {
let {selectList} = this.state;
for (var key in item) {
selectList[key] = item[key]
}
this.setState({
selectList
});
}
onResetFilter() {
let {setFilter} = this.props;
let {selectList} = this.state;
for (var key in selectList) {
selectList[key] = '';
}
setFilter(selectList);
this.setState({
selectList
});
}
onConfirmSearch() {
let {setFilter, filterMenu} = this.props;
let {selectList} = this.state;
event.emit('reset-page-loading', { filterMenu: filterMenu});
setFilter(selectList);
wx.navigateBack({
delta: 1
})
}
render () {
let {filter, selectList} = this.state;
return (
<View className="filter-page">
{/* <PageTitle pageTitle="筛选"></PageTitle> */}
{
filter.map((item, index) => {
return (
<FilterGroup list={item} selectList={selectList} onChangeFilter={this.onChangeFilter.bind(this)} key={index}></FilterGroup>
)
})
}
<View className="filter-btn">
<View className="reset-btn" onClick={this.onResetFilter}>清空</View>
<Button className="confirm-btn" onClick={this.onConfirmSearch}>确认</Button>
</View>
</View>
)
}
}