index.js 1.96 KB
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 './index.scss';
import wx from '../../libs/wx';

@connect(({ filterData }) => ({
    filterData
}), (dispatch) => {
	return bindActionCreators({
		setFilter
    }, dispatch);
})

export default class Search extends Component {
	constructor() {
		super(...arguments);
		this.state = {
            filter: []
		};
	}

	config = {
		navigationBarTitleText: '筛选'
	}

	componentDidMount () {
		searchModel.getFilterData().then(ret => {
			if (ret && ret.code === 200) {
				this.setState({
					filter: ret.data && ret.data.filter || []
				});
			}
		});
	}

	onResetFilter() {
		let {setFilter} = this.props;
		let filter = {};

		this.state.filter.map(item => {
			filter[item.filterId] = {};
		});

		setFilter(filter);
	}

	onConfirmSearch() {
		console.log('====================================');
		console.log(this.props.filterData);
		console.log('====================================');
		wx.navigateBack({
			delta: 1
		})
	}

	render () {
        let {filter} = this.state;

		return (
			<View className="filter-page">
                <PageTitle pageTitle="筛选"></PageTitle>

                {
                    filter.map((item, index) => {
                        return (
                            <FilterGroup list={item} 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>
		)
	}
}