searchHead.js 1.47 KB
Newer Older
zhanghaozhe committed
1
import React, { PureComponent } from 'react'
baiguangyao committed
2
import { SearchBar } from 'antd-mobile'
zhanghaozhe committed
3
import { withRouter } from 'react-router-dom'
baiguangyao committed
4 5 6

import './search_header.scss'

zhanghaozhe committed
7 8
class SearchHead extends PureComponent {

zhanghaozhe committed
9
    returnPage = () => {
zhanghaozhe committed
10
        this.props.history.go(-1)
baiguangyao committed
11
    }
zhanghaozhe committed
12

baiguangyao committed
13 14 15
    componentDidMount() {
        this.refs.search.focus();
    }
zhanghaozhe committed
16

zhanghaozhe committed
17 18 19 20 21 22
    search = () => {
        this.storeKeyword()
        this.props.handleSearch()
    }

    storeKeyword = () => {
zhanghaozhe committed
23 24
        let {searchHistory = [], value} = this.props
        value && localStorage.setItem('searchHistory', JSON.stringify([...searchHistory, value]))
zhanghaozhe committed
25 26 27
    }


baiguangyao committed
28 29 30
    render() {
        return (
            <div className="search-head">
zhanghaozhe committed
31

zhanghaozhe committed
32
                <div className="left" onClick={this.returnPage}>
zhanghaozhe committed
33
                    <i className="iconfont iconiconfront-68"/>
zhanghaozhe committed
34 35
                </div>

baiguangyao committed
36 37
                <div className="center">
                    <SearchBar
zhanghaozhe committed
38
                        value={this.props.value}
baiguangyao committed
39 40 41 42
                        showCancelButton
                        cancelText={" "}
                        ref="search"
                        focus={true}
zhanghaozhe committed
43
                        onChange={this.props.handleChange}
zhanghaozhe committed
44
                        placeholder="搜索课程"/>
baiguangyao committed
45
                </div>
zhanghaozhe committed
46 47
                <div className="right right-btn" onClick={this.search}>
                    <div className="submit-btn">搜索
zhanghaozhe committed
48
                    </div>
baiguangyao committed
49 50 51 52 53
                </div>
            </div>
        )
    }
}
zhanghaozhe committed
54

zhanghaozhe committed
55
export default withRouter(SearchHead)