index.js 4.36 KB
Newer Older
xuzhenghua committed
1
import React, {Component} from 'react';
xuzhenghua committed
2
import {WithTab} from '@/HOCs'
xuzhenghua committed
3
import './index.scss';
zhanghaozhe 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'
xuzhenghua committed
9

baiguangyao committed
10 11

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

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

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

xuzhenghua committed
49
        })
xuzhenghua committed
50
    }
xuzhenghua committed
51

baiguangyao committed
52
    render() {
xuzhenghua committed
53
        return (
xuzhenghua committed
54
            <div className='class-box'>
xuzhenghua committed
55
                <HeaderBar title='分类' arrow={false} cart={false}></HeaderBar>
xuzhenghua committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
                <Loading isLoading={this.state.isLoading}>
                    <ClassCourseBox data={this.state.camp.list} title={this.state.camp.name} type={1}/>
                    <ClassCourseBox data={this.state.employment.list} title={this.state.employment.name} type={1}/>
                    <ClassCourseBox data={this.state.basics.list} title={this.state.basics.name} type={2}/>
                    <ClassCourseBox data={this.state.advanced.list} title={this.state.advanced.name} type={2}/>
                    <div className="vip">
                        {this.state.special.list && this.state.special.list.length > 0 && this.state.special.list.map((item, index) => {
                            return (
                                <Link key={index} to={`/detail?id=${item.course_id}`}>
                                    <img src={item.course_img} alt=""/>
                                </Link>
                            )
                        })
                        }
                    </div>
                </Loading>
baiguangyao committed
72 73 74
            </div>
        )
    }
xuzhenghua committed
75
}
baiguangyao committed
76

xuzhenghua committed
77
// 课程图片形式展示 点击图片直接跳转课程详情页面
xuzhenghua committed
78
function ClassCourseA({data}) {
xuzhenghua committed
79
    return (
xuzhenghua committed
80 81
        <div className='items-box'>
            {
xuzhenghua committed
82
                data && data.length > 0 && data.map((item, index) => {
xuzhenghua committed
83
                    return (
wangshuo committed
84 85 86 87 88 89 90
                        <Link to={`/detail?id=${item.course_id}`} key={index} className='item-banner'>
                            <img src={item.course_img} alt=""/>
                            {
                                (item.is_aist &&
                                    <span className='return_cash'></span>)
                            }
                        </Link>
xuzhenghua committed
91 92 93 94 95
                    )
                })
            }
        </div>
    )
baiguangyao committed
96 97
}

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

xuzhenghua committed
115
function ClassCourseBox(props) {
xuzhenghua committed
116
    return (
xuzhenghua committed
117
        <div className="class-course">
xuzhenghua committed
118 119
            <p className='course-items-title'>
                <img src={require('./image/tips.png')} alt=""/>
xuzhenghua committed
120
                {props.title}
xuzhenghua committed
121
            </p>
xuzhenghua committed
122
            {props.type === 1 &&
xuzhenghua committed
123
            <ClassCourseA data={props.data}/>
xuzhenghua committed
124
            }
xuzhenghua committed
125
            {props.type === 2 &&
xuzhenghua committed
126
            <ClassCourseB data={props.data}/>
xuzhenghua committed
127 128 129 130
            }
        </div>
    )
}
xuzhenghua committed
131

xuzhenghua committed
132
export default WithTab(Classify);