index.js 1.74 KB
import Taro, { Component } from '@tarojs/taro';
import { View, Text, Navigator } 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';

@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(this.props.filterData).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);
	}

	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>
                    <Navigator className="confirm-btn" open-type="navigateBack" delta="1">确认</Navigator>
                </View>
            </View>
		)
	}
}