index.js
4.02 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import Taro, {Component} from '@tarojs/taro';
import {View, Text, Image, Navigator} from '@tarojs/components';
import { connect } from '@tarojs/redux';
import { bindActionCreators } from 'redux';
import {changeType} from '../../actions/filterMenu';
import filterIcon from '../../static/images/filter.png';
import sort from '../../static/images/sort.png';
import sortUp from '../../static/images/sort-up.png';
import sortDown from '../../static/images/sort-down.png';
import './index.scss';
import router from '../../router/index';
import event from '../../utils/event.js';
@connect(({ filterMenu }) => {
return {filterMenu}
}, (dispatch) => {
return bindActionCreators({
changeType
}, dispatch);
})
export default class filterMenu extends Component {
constructor(props) {
super(props);
this.state = {
curOrder: ''
};
}
static defaultProps = {
tabs: [],
hasFilter: false,
tabClass: '',
}
componentWillMount() {
}
componentWillUnmount() {
console.log('卸载');
let { filterMenu } = this.props;
let params = {
indexType: filterMenu.indexType,
curType: 0
}
this.props.changeType(params);
}
onChangeTab(item) {
let {filterMenu, fromPage} = this.props;
let order = '';
let params = {}
if (fromPage === 'search') {
if (item === 'price') {
order = this.state.curOrder === 'p_asc' ? 'p_desc' : 'p_asc';
item = order;
params.curType = item;
params.indexType = filterMenu.indexType;
} else {
params.curType = item;
params.indexType = filterMenu.indexType;
}
}
if (fromPage === 'index') {
if (item === filterMenu.indexType) {
return;
}
params.indexType = item;
params.curType = filterMenu.curType;
this.props.onSetCurrentTab && this.props.onSetCurrentTab(item);
}
this.props.changeType(params);
event.emit('reset-page-loading', { filterMenu: Object.assign(...filterMenu, params)});
this.setState({
curOrder: order
});
}
goToFilter() {
let { screen } = this.props;
console.log('screen: ', screen);
if (screen && screen.query) {
screen.query = decodeURI(screen.query);
}
router.go('filter', {
...screen
});
}
render() {
let {tabs, hasFilter, tabClass, filterMenu, fromPage} = this.props;
let {curOrder} = this.state;
let curType;
if (fromPage === 'index') {
curType = filterMenu.indexType;
} else {
curType = filterMenu.curType;
}
let sortImg = sort;
if (curOrder === 'p_desc') {
sortImg = sortDown;
}
if (curOrder === 'p_asc') {
sortImg = sortUp;
}
curType = curType === curOrder ? 'price' : curType;
return (
<View className="tabs-nav">
<View className="tabs">
{
tabs.map(item => {
return (
<View key={item.type} className="tab-box" onClick={this.onChangeTab.bind(this, item.type)}>
<Text className={curType == item.type ? `actived tab-item ${tabClass}` : 'tab-item'}>{item.text}</Text>
{
item.type === 'price' && <Image src={sortImg} className="sort-icon"></Image>
}
</View>
)
})
}
</View>
{
hasFilter &&
<View className="filter-btn" onClick={this.goToFilter} hover-class="none">
<Image src={filterIcon} className="filter-icon"></Image>
<Text className="text">筛选</Text>
</View>
}
</View>
)
}
}