index.js 2.68 KB
Newer Older
zhanghaozhe committed
1
import React, { PureComponent } from 'react';
2 3
import {connect} from 'react-redux';
import {getCourses} from './../../detail/actions';
4
import './recommendation.scss'
zhanghaozhe committed
5
import { http } from '@/utils'
6
import { Toast } from "antd-mobile";
zhanghaozhe committed
7
import VList from '@/common/v-list-base';
8 9 10 11 12 13 14 15 16 17 18


const Bottom = ({item}) => {
    return (
        <div className='bottom'>
            <span className='price'>¥{item.price1}</span>
            <span className='stale-price'>¥{item.price0}</span>
        </div>
    )
}

19
@connect()
zhanghaozhe committed
20
class Recommendation extends PureComponent {
21 22
    state = {
        num: 10,
zhanghaozhe committed
23 24
        list: [],
        courseId: null
25 26 27
    }

    componentDidMount() {
28 29 30 31
        this.getRecommendation()
    }

    getRecommendation = () => {
zhanghaozhe committed
32
        http.get(`${API.home}/m/play/recommend_course/${this.props.vCourseId}?num=${this.state.num}`)
33 34 35 36 37
            .then(res => {
                const data = res.data
                if(data.code === 200){

                    this.setState({
xuzhenghua committed
38
                        list: Array.isArray(data.data) ? data.data : []
39 40 41 42 43 44 45 46
                    })

                }else {
                    Toast.info(data.msg)
                }
            })
    }

47 48
    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
49
        // dispatch(getCourses(id, () => {
50
            history.push(`/detail?id=${id}`)
51
        // }));
52 53 54 55
    }

    render() {
        return (
xuzhenghua committed
56 57
            this.state.list.length
            ?
58 59 60 61 62 63 64
            <div className='recommendation'>
                <div className={'title'}>相关推荐</div>
                <ul>
                    {
                        this.state.list.map(item => {
                            const Info = (
                                <div className="info">
xuzhenghua committed
65 66
                                    <p className='title text-overflow-1'>{item.course_title}</p>
                                    <p className='des text-overflow-2'>{item.simpledescription}</p>
67 68 69 70 71 72 73 74 75 76
                                    <Bottom
                                        item={item}
                                    />
                                </div>
                            )

                            return (
                                <VList
                                    key={item.course_id}
                                    img={item.image_name}
77
                                    handleClick={this.toCourseDetail}
78 79 80 81 82 83 84 85
                                    info={Info}
                                    id={item.course_id}
                                />
                            )
                        })
                    }
                </ul>
            </div>
xuzhenghua committed
86
                : null
87 88 89 90 91
        );
    }
}

export default Recommendation;