index.js 2.42 KB
Newer Older
zhanghaozhe committed
1
import React, { Component } from "react";
2
import {connect} from 'react-redux';
zhanghaozhe committed
3
import './recommendation.scss'
zhanghaozhe committed
4 5
import { Course } from "src/common";
import { http } from "src/utils";
zhanghaozhe committed
6 7
import { Toast } from 'antd-mobile'
import {withRouter} from 'react-router-dom'
8
import {getCourses} from './../../detail/actions';
zhanghaozhe committed
9

10
@connect()
zhanghaozhe committed
11 12 13 14 15 16 17
class Recommendation extends Component {

    state = {
        courses: []
    }

    componentDidMount() {
zhanghaozhe committed
18
        http.get(`${API['search-api']}/search_hot_word`)
zhanghaozhe committed
19 20 21 22 23 24 25 26 27 28 29 30 31
            .then(res => {
                if (res.data.errno === 0) {
                    this.setState({
                        courses: res.data.data.info.courses
                    })
                } else {
                    Toast.info(res.data.msg)
                }

            })

    }

32 33 34
    // handleClick = (id) => {
    //     this.props.history.push(`/detail?id=${id}`)
    // }
zhanghaozhe committed
35

36 37
    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
38
        // dispatch(getCourses(id, () => {
39
            history.push(`/detail?id=${id}`)
40
        // }));
41
    }
zhanghaozhe committed
42 43 44 45 46 47 48 49 50

    render() {
        const {courses} = this.state
        return (
            <div className="recommendation">
                <div className="title">推荐课程</div>
                <div className="courses">
                    {
                        courses.length > 0 &&
51
                        courses.map((item) => {
zhanghaozhe committed
52 53 54 55 56 57 58 59
                            const Bottom = (
                                <div className='bottom'>
                                    <span className='price'>{item['price1']}</span>
                                    <span className='old-price'>{item['price0']}</span>
                                </div>
                            )
                            return (
                                <Course
xuzhenghua committed
60
                                    className={'text-overflow-2'}
zhanghaozhe committed
61 62 63 64 65
                                    key={item['course_id']}
                                    id={item['course_id']}
                                    img={item['image_name']}
                                    title={item['course_title']}
                                    bottom={Bottom}
66
                                    toDetail={this.toCourseDetail}
zhanghaozhe committed
67 68 69 70 71 72 73 74 75 76 77 78
                                />
                            )
                        })
                    }

                </div>
            </div>
        )
    }
}

export default withRouter(Recommendation)