index.js 4.82 KB
Newer Older
xuzhenghua committed
1
import React, {Component} from 'react';
xuzhenghua committed
2
import {WithTab} from '@/HOCs'
xuzhenghua committed
3
import './index.scss';
xuzhenghua committed
4
import {http} from "@/utils";
xuzhenghua committed
5 6
import {Link} from 'react-router-dom'
import {Toast} from 'antd-mobile'
xuzhenghua committed
7 8
import {HeaderBar} from "@/common"
import Loading from '@/common/Loading'
FE committed
9
import {connect} from 'react-redux';
xuzhenghua committed
10

FE committed
11
@connect()
baiguangyao committed
12
class Classify extends Component {
xuzhenghua committed
13 14 15 16 17 18 19
    constructor(props) {
        super(props)
        this.state = {
            camp: [],
            employment: [],
            basics: [],
            advanced: [],
xuzhenghua committed
20 21
            special: [],
            isLoading: true
xuzhenghua committed
22 23 24 25 26
        }
    }

    componentDidMount() {
        let data = 1
zhanghaozhe committed
27
        http.get(`${API.home}/m/course/classify/${data}`,).then((res) => {
xuzhenghua committed
28
            if (res.data.code === 200) {
xuzhenghua committed
29 30 31 32
                this.setState({
                    isLoading: false
                })

xuzhenghua committed
33
                if (res.data.data.common.length > 0) {
xuzhenghua committed
34 35
                    this.setState({
                        basics: res.data.data.common[0],
xuzhenghua committed
36
                        advanced: res.data.data.common[1] || [],
xuzhenghua committed
37 38
                    })
                }
xuzhenghua committed
39
                if (res.data.data.special.length > 0) {
xuzhenghua committed
40
                    this.setState({
xuzhenghua committed
41
                        camp: res.data.data.special[0],
xuzhenghua committed
42 43
                        employment: res.data.data.special[1] || [],
                        special: res.data.data.special[2] || [],
xuzhenghua committed
44
                    })
xuzhenghua committed
45

xuzhenghua committed
46
                }
xuzhenghua committed
47 48
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
49
            }
xuzhenghua committed
50

xuzhenghua committed
51
        })
xuzhenghua committed
52
    }
xuzhenghua committed
53

FE committed
54 55 56 57 58 59
    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
            history.push(`/detail?id=${id}`);
            return false;
    }

baiguangyao committed
60
    render() {
xuzhenghua committed
61
        return (
xuzhenghua committed
62
            <div className='class-box'>
xuzhenghua committed
63
                <HeaderBar title='分类' arrow={false} cart={false}></HeaderBar>
xuzhenghua committed
64
                <Loading isLoading={this.state.isLoading}>
FE committed
65 66 67 68
                    <ClassCourseBox toDetail={this.toCourseDetail} data={this.state.camp.list} title={this.state.camp.name} type={1}/>
                    <ClassCourseBox toDetail={this.toCourseDetail} data={this.state.employment.list} title={this.state.employment.name} type={1}/>
                    <ClassCourseBox toDetail={this.toCourseDetail} data={this.state.basics.list} title={this.state.basics.name} type={2}/>
                    <ClassCourseBox toDetail={this.toCourseDetail} data={this.state.advanced.list} title={this.state.advanced.name} type={2}/>
xuzhenghua committed
69 70 71
                    <div className="vip">
                        {this.state.special.list && this.state.special.list.length > 0 && this.state.special.list.map((item, index) => {
                            return (
xuzhenghua committed
72
                                <a onClick={() => this.toCourseDetail(item.course_id)} key={index}>
xuzhenghua committed
73
                                    <img src={item.course_img} alt=""/>
FE committed
74
                                </a>
xuzhenghua committed
75 76 77 78 79
                            )
                        })
                        }
                    </div>
                </Loading>
baiguangyao committed
80 81 82
            </div>
        )
    }
xuzhenghua committed
83
}
baiguangyao committed
84

xuzhenghua committed
85
// 课程图片形式展示 点击图片直接跳转课程详情页面
FE committed
86
function ClassCourseA({data, toDetail}) {
xuzhenghua committed
87
    return (
xuzhenghua committed
88 89
        <div className='items-box'>
            {
xuzhenghua committed
90
                data && data.length > 0 && data.map((item, index) => {
xuzhenghua committed
91
                    return (
xuzhenghua committed
92
                        <a onClick={() => toDetail(item.course_id)} key={index} className='item-banner'>
wangshuo committed
93 94 95 96 97
                            <img src={item.course_img} alt=""/>
                            {
                                (item.is_aist &&
                                    <span className='return_cash'></span>)
                            }
FE committed
98
                        </a>
xuzhenghua committed
99 100 101 102 103
                    )
                })
            }
        </div>
    )
baiguangyao committed
104 105
}

xuzhenghua committed
106
// 课程标签的形式展示  点击标签跳转分类详情页面
xuzhenghua committed
107
function ClassCourseB(props) {
xuzhenghua committed
108
    return (
xuzhenghua committed
109 110
        <div className='items-box'>
            {
xuzhenghua committed
111
                props.data && props.data.length > 0 && props.data.map((item, index) => {
xuzhenghua committed
112
                    return (
xuzhenghua committed
113
                        <Link to={`/courselist?id=${item.c_id}&name=${item.c_name}`} key={index} className='item-label'>
xuzhenghua committed
114 115
                            {item.c_name}
                        </Link>
xuzhenghua committed
116 117 118 119 120 121 122
                    )
                })
            }
        </div>
    )
}

xuzhenghua committed
123
function ClassCourseBox(props) {
xuzhenghua committed
124
    return (
xuzhenghua committed
125
        <div className="class-course">
xuzhenghua committed
126
            <p className='course-items-title'>
xuzhenghua committed
127 128 129 130
                {
                    props.title &&
                    <img src={require('./image/tips.png')} alt=""/>
                }
xuzhenghua committed
131
                {props.title}
xuzhenghua committed
132
            </p>
xuzhenghua committed
133
            {props.type === 1 &&
FE committed
134
            <ClassCourseA data={props.data} toDetail={props.toDetail} />
xuzhenghua committed
135
            }
xuzhenghua committed
136
            {props.type === 2 &&
xuzhenghua committed
137
            <ClassCourseB data={props.data}/>
xuzhenghua committed
138 139 140 141
            }
        </div>
    )
}
xuzhenghua committed
142

xuzhenghua committed
143
export default WithTab(Classify);