index.js 4.16 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, api} 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
xuzhenghua 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 (
xuzhenghua committed
84 85
                        <Link to={`/detail?id=${item.course_id}`} key={index} className='item-banner'><img
                            src={item.course_img} alt=""/></Link>
xuzhenghua committed
86 87 88 89 90
                    )
                })
            }
        </div>
    )
baiguangyao committed
91 92
}

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

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

xuzhenghua committed
127
export default WithTab(Classify);