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

class PythonStudy extends Component {
xuzhenghua committed
11 12 13
    constructor(props) {
        super(props);
        this.state = {
wangshuo committed
14
            toApp: false,
xuzhenghua committed
15 16 17 18 19
            courseInfo: '',
            syllabus: '',
            learning: ''
        };
    }
xuzhenghua committed
20

xuzhenghua committed
21 22 23
    componentDidMount() {
        this.fetchCourseDetail();
    }
xuzhenghua committed
24

xuzhenghua committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38
    fetchCourseDetail = () => {
        http.get(`${API['home']}/web/it_detail?course_id=${getParam('id')}&is_pay=1`).then(res => {
            const {data, code, msg} = res.data;
            if (code === 200) {
                this.setState({
                    courseInfo: data.course_info,
                    syllabus: data.syllabus,
                    learning: data.learning
                })
            } else {
                Toast.info(msg, 2)
            }
        });
    }
xuzhenghua committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    Change = (data) => {
        let cn = ["一", "二", "三", "四", "五", "六", "七", "八", "九", '十'];
        let newStr = ''
        let str = data.toString()
        let ci = Number(str) % 10
        let cs = Math.floor(Number(str) / 10)
        let cv = ''
        if (str.length > 1) {
            if (cs == 1) {
                cv = ci >= 1 ? cn[9] + cn[ci - 1] : cn[9]
            } else {
                cv = ci > 1 ? cn[cs - 1] + cn[9] + cn[ci - 1] : cn[cs - 1] + cn[9]
            }
        } else {
            cv = cn[ci - 1]
        }
        newStr = str.replace(str, cv)
        return newStr;
    }

xuzhenghua committed
60 61 62
    onChange = (key) => {
        console.log(key);
    }
xuzhenghua committed
63

xuzhenghua committed
64
    toPythonHome = (isUnlock) => {
xuzhenghua committed
65
        if (isUnlock == 1) {
xuzhenghua committed
66 67 68
            this.setState({
                toApp: true
            })
xuzhenghua committed
69 70
        }
    }
xuzhenghua committed
71

wangshuo committed
72 73 74 75 76 77 78 79 80 81 82
    toLearn = () => {
        this.setState({
            toApp: true
        })
    }
    closePop = () => {
        this.setState({
            toApp: false,
        })
    }

xuzhenghua committed
83 84 85
    render() {
        const {user} = this.props;
        const uid = user && user.data && user.data.uid
wangshuo committed
86
        const {courseInfo, syllabus, learning, toApp} = this.state;
xuzhenghua committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        return (
            <div className="python-study">
                <HeaderBar title='Python基础语法' arrow={true}/>
                <div className="python-study__header">
                    <div className="python-study__course">
                        <h2 className="python-study__course-name">Python人工智能</h2>
                        <p className="python-study__course-contact">
                            <span>{courseInfo.contact_type == 1 ? '上课请加QQ学习群' : '添加助教微信入群'}{courseInfo.course_qq}</span>
                            <span>并备注您的学号:{uid}</span>
                        </p>
                    </div>
                    {
                        learning.schedule == 0 &&
                        <div className="python-study__progress">
                            <h2 className="python-study__progress-title">学习进度</h2>
                            <div className="python-study__progress-bar">
                                <i style={{width: learning.schedule + '%'}}/>
                                <span className="python-study__progress-tip"
                                      style={{left: learning.schedule + '%'}}>{learning.schedule + '%'}</span>
                            </div>
                        </div>
                    }
xuzhenghua committed
109

xuzhenghua committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                </div>
                <Accordion
                    defaultActiveKey="0"
                    className="python-study__stage"
                    onChange={this.onChange}
                >
                    {
                        syllabus && syllabus.length > 0 && syllabus.map((syllabusItem, index) => {
                            let header = `第${this.Change(syllabusItem.stage)}阶段:${syllabusItem.name}`
                            return (
                                <Accordion.Panel header={header} className="pad" key={index}>
                                    {
                                        syllabusItem.lessons && syllabusItem.lessons.length > 0 && syllabusItem.lessons.map((lessonsItem, index) => {
                                            return (
                                                <div key={index}>
                                                    <h2 className="python-study__pass">
                                                        {lessonsItem.shut} {lessonsItem.name}
                                                        {
                                                            lessonsItem.complete == 1 &&
                                                            <i className="python-study__pass-tag">闯关完成</i>
                                                        }
                                                    </h2>
xuzhenghua committed
132

xuzhenghua committed
133 134 135
                                                    <div className="python-study__subject"
                                                         style={{opacity: lessonsItem.info.is_unlock == 0 ? '.6' : '1'}}
                                                         onClick={() => {
xuzhenghua committed
136
                                                             this.toPythonHome(lessonsItem.info.is_unlock)
xuzhenghua committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
                                                         }}
                                                         key={index}>
                                                        <img className="python-study__subject-icon"
                                                             src={lessonsItem.info.img_url} alt=""/>
                                                        {
                                                            lessonsItem.info.is_unlock == 1 && lessonsItem.info.complete == 1 &&
                                                            <i className="python-study__subject-status"
                                                               data-status="complete"/>
                                                        }
                                                        {
                                                            lessonsItem.info.is_unlock == 0 &&
                                                            <i className="python-study__subject-status"
                                                               data-status="lock"/>
                                                        }
                                                        <div className="python-study__subject-content">
                                                            <h2 className="python-study__subject-title text-overflow-1">{lessonsItem.info.name}</h2>
                                                        </div>
                                                    </div>
xuzhenghua committed
155

xuzhenghua committed
156 157 158 159 160 161
                                                    {
                                                        lessonsItem.questions && lessonsItem.questions.length > 0 && lessonsItem.questions.map((item, index) => {
                                                            return (
                                                                <div className="python-study__subject"
                                                                     style={{opacity: item.is_unlock == 0 ? '.6' : '1'}}
                                                                     onClick={() => {
xuzhenghua committed
162
                                                                         this.toPythonHome(item.is_unlock)
xuzhenghua committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                                                                     }}
                                                                     key={index}>
                                                                    <img className="python-study__subject-icon"
                                                                         src={item.icon} alt=""/>
                                                                    {
                                                                        item.is_unlock == 1 && item.complete == 1 &&
                                                                        <i className="python-study__subject-status"
                                                                           data-status="complete"/>
                                                                    }
                                                                    {
                                                                        item.is_unlock == 1 && item.complete == 0 &&
                                                                        <i className="python-study__subject-status"
                                                                           data-status="lock"/>
                                                                    }
                                                                    <div className="python-study__subject-content">
                                                                        <h2 className="python-study__subject-title text-overflow-1">{item.name}</h2>
                                                                        {
                                                                            item.is_must == 1 &&
                                                                            <span
                                                                                className="python-study__subject-tag">必做练习</span>
                                                                        }
                                                                    </div>
                                                                </div>
                                                            )
                                                        })
                                                    }
                                                </div>
                                            )
                                        })
                                    }
                                </Accordion.Panel>
                            )
                        })
                    }
                </Accordion>
                {
                    learning.schedule == 0 &&
wangshuo committed
200
                    <span onClick={this.toLearn} className="python-study__button">开始学习</span>
xuzhenghua committed
201 202 203
                }
                {
                    learning.schedule != 0 && learning.schedule != 100 &&
wangshuo committed
204
                    <span onClick={this.toLearn} className="python-study__button">继续学习</span>
xuzhenghua committed
205 206 207 208 209
                }
                {
                    learning.schedule == 100 &&
                    <button className="python-study__button python-study__over">已学完全部课时</button>
                }
wangshuo committed
210 211 212 213

                {
                    toApp && <Mask closePop={this.closePop} type={2} />
                }
xuzhenghua committed
214 215 216
            </div>
        )
    }
xuzhenghua committed
217 218 219 220 221 222
}


export default connect(
    state => ({user: state.user}),
    null
xuzhenghua committed
223
)(PythonStudy);