index.js 11.7 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable eqeqeq, jsx-a11y/alt-text */
zhanghaozhe committed
2 3 4 5 6 7 8 9 10 11 12 13 14
import React, { Component } from "react"
import "./index.scss"
import Description from "./Description/index.js"
import NoWorry from "./NoWorry/index.js"
import Study from "./Study/index.js"
import Test from "./Test/index.js"
import Team from "./Team/index.js"
import Experience from "./Experience/index.js"
import Progream from "./Progream/index.js"
import Mask from "./../poup/index.js"
import { http, getParam, SendMessageToApp } from "src/utils"
import { connect } from "react-redux"
import { Toast } from "antd-mobile"
zhanghaozhe committed
15
import ShareRank from "src/components/detail/shareRank"
FE committed
16

zhanghaozhe committed
17 18
@connect((state) => ({
  user: state.user,
wangshuo committed
19 20
}))
class PythonDes extends Component {
zhanghaozhe committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  constructor(props) {
    super(props)
    this.state = {
      syllabus: [], // 阶梯学习
      allSyllabus: [], // 阶梯学习
      allSyllabusShow: false,
      practice: [], // 课后实操
      allPractice: [], // 课后实操
      allPracticeShow: false,
      toApp: false,
      defineList: [
        {
          titleUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/trophy.png",
          title: "排名第1的编程语言",
          subTitle: "2018世界编程语言排行榜中,Python排名第1",
          subWidth: "180px",
          bottomUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/program_lan.png",
          desInfo: {
            width: "240px",
            height: "170px",
          },
        },
        {
          titleUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/kaifa.png",
          title: "开发快速、简单易掌握",
          subTitle: "严谨的代码编写格式,语法格式简单易理解完成一个相同的任务",
          subWidth: "260px",
          bottomUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/kuaisu.png",
          desInfo: {
            width: "212px",
            height: "106px",
          },
        },
        {
          titleUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/lingyu.png",
          title: "适用领域广",
          subTitle: "Python工程师可从事多领域编程工作,人才年需求增长6倍",
          subWidth: "230px",
          bottomUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/jiandan.png",
          desInfo: {
            width: "234px",
            height: "106px",
          },
        },
      ],
      desList: [
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xingshi.png",
          title: "全新课程形式",
          subTitle: "对话式交互教学,轻松、生动、不无聊",
        },
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/huanjing.png",
          title: "在线编程环境",
          subTitle: "无需安装任何编程软件",
        },
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/rumen.png",
          title: "17天零基础入门",
          subTitle: "降低学习门槛,17天入门人工智能",
        },
      ],
      worryList: [
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/jiechu.png",
          title: "初次接触,担心学不会",
          subTitle:
            "本课程专门为零基础的你打造,全篇通过最白话沟通交流的方式进行讲解,无论你有无编程经验都可以轻松理解并且掌握。",
        },
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xuexi.png",
          title: "想学习,没有坚持下来",
          subTitle:
            "以故事性的方式编写学习内容, 把生硬的知识点有趣化。精美的图片+幽默的文字+代码编写让你越学越想学。",
        },
        {
          url:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/zhishidian.png",
          title: "知识点掌握了,不知如何运用",
          subTitle:
            "每节课的知识点都设有代码编写部分,每节课课后都有课后实操。有多次代码编写练习的机会,助你真正学以致用。",
        },
      ],
      payMoney: 0,
      isOnline: true, //课程是否上架
      courseInfo: {},
xuzhenghua committed
118
    }
zhanghaozhe committed
119
  }
FE committed
120

zhanghaozhe committed
121 122 123 124 125 126 127 128
  // 立即报名
  signUp = () => {
    // 已登录
    if (!this.props.user.hasError) {
      this.toDetail()
    } else {
      // 未登录
      this.toLogin()
wangshuo committed
129
    }
zhanghaozhe committed
130
  }
FE committed
131

zhanghaozhe committed
132 133 134 135 136 137 138 139
  // 立即体验、免费试学
  tryLearn = () => {
    // 已登录
    if (!this.props.user.hasError) {
      this.toLearn()
    } else {
      // 未登录
      this.toLogin()
wangshuo committed
140
    }
zhanghaozhe committed
141
  }
FE committed
142

zhanghaozhe committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  toLearn = () => {
    const { backwardVersion } = this.props
    http
      .post(`${API["home"]}/m/it/user/trialCourse`, {
        course_id: getParam("id"),
      })
      .then((res) => {
        const { code, msg } = res.data
        if (code == 200) {
          if (!getParam("version")) {
            // H5
            this.setState({
              toApp: true,
            })
          } else {
            // APP
            if (backwardVersion) {
              Toast.info(
                "当前版本不支持该课程模式,请升级到最新版本或前往PC端体验",
                2
              )
FE committed
164
            } else {
zhanghaozhe committed
165
              SendMessageToApp("toLearn", getParam("id"))
FE committed
166
            }
zhanghaozhe committed
167 168 169 170 171 172 173 174 175 176 177 178
          }
        } else {
          Toast.info(msg, 2)
        }
      })
  }

  closePop = () => {
    this.setState({
      toApp: false,
    })
  }
FE committed
179

zhanghaozhe committed
180 181 182 183 184 185 186 187 188 189 190 191 192
  toDetail = () => {
    const { backwardVersion } = this.props
    const id = getParam("id")
    if (!getParam("version")) {
      // H5
      http
        .get(`${API["base-api"]}/m/cart/addtopreorder/[${id}]`)
        .then((res) => {
          if (res.data.errno === 0) {
            this.props.history.push(`/order?id=${id}`, { simple: 1 })
          } else {
            Toast.info(res.data.msg, 2)
          }
FE committed
193
        })
zhanghaozhe committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    } else {
      // APP
      if (backwardVersion) {
        Toast.info(
          "当前版本不支持该课程模式,请升级到最新版本或前往PC端购买",
          2
        )
        let onlyoneUse = setTimeout(() => {
          clearTimeout(onlyoneUse)
          onlyoneUse = null
          SendMessageToApp("toPay", id)
        }, 2000)
      } else {
        SendMessageToApp("toPay", id)
      }
wangshuo committed
209
    }
zhanghaozhe committed
210
  }
FE committed
211

zhanghaozhe committed
212 213 214 215 216 217 218
  toLogin = () => {
    if (!getParam("version")) {
      // H5
      this.props.history.push("/passport")
    } else {
      // APP
      SendMessageToApp("toLogin")
wangshuo committed
219
    }
zhanghaozhe committed
220
  }
wangshuo committed
221

zhanghaozhe committed
222 223 224 225 226 227
  showAll = (key) => {
    if (key === 1) {
      this.setState({
        syllabus: this.state.allSyllabus,
        allSyllabusShow: true,
      })
wangshuo committed
228
    }
zhanghaozhe committed
229 230 231 232 233
    if (key === 2) {
      this.setState({
        practice: this.state.allPractice,
        allPracticeShow: true,
      })
wangshuo committed
234
    }
zhanghaozhe committed
235 236 237 238 239 240 241
  }
  hideSome = (key) => {
    if (key === 1) {
      this.setState({
        syllabus: this.state.allSyllabus.slice(0, 2),
        allSyllabusShow: false,
      })
wangshuo committed
242
    }
zhanghaozhe committed
243 244 245 246 247
    if (key === 2) {
      this.setState({
        practice: this.state.allPractice.slice(0, 2),
        allPracticeShow: false,
      })
wangshuo committed
248
    }
zhanghaozhe committed
249
  }
FE committed
250

zhanghaozhe committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  getStatus = () => {
    http
      .get(`${API["home"]}/web/it_detail?course_id=${getParam("id")}`)
      .then((res) => {
        const { code, data, msg } = res.data
        if (code == 200) {
          this.setState({
            syllabus: data.syllabus.slice(0, 2),
            allSyllabus: data.syllabus,
            practice: data.practice.slice(0, 2),
            allPractice: data.practice,
            payMoney: data.course_info.price1,
            courseInfo: data.course_info,
          })
        } else {
          Toast.info(msg)
wangshuo committed
267
        }
zhanghaozhe committed
268 269
      })
  }
wangshuo committed
270

zhanghaozhe committed
271 272
  componentDidMount() {
    this.getStatus()
xuzhenghua committed
273

zhanghaozhe committed
274 275 276 277 278 279 280 281 282 283
    const { backwardVersion, isPay } = this.props
    if (backwardVersion && isPay === 1) {
      Toast.info("当前版本不支持该课程模式,请升级到最新版本或前往PC端学习", 2)
    }
  }

  shouldComponentUpdate(nextProps, nextState, nextContext) {
    if (this.props.isAppUpdate !== nextProps.isAppUpdate) {
      this.getStatus()
      return false
FE committed
284
    }
zhanghaozhe committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    return true
  }

  render() {
    const {
      defineList,
      desList,
      worryList,
      syllabus,
      practice,
      allSyllabusShow,
      allPracticeShow,
      toApp,
      payMoney,
      isOnline,
      courseInfo,
    } = this.state
    console.log(courseInfo)
    return (
      <div className={"python__des"}>
        <div className={"des__start"}></div>
        {!!courseInfo.is_dist && <ShareRank courseInfo={courseInfo} />}
        <div className={"python__define"}>
          <img
            className={"left__decorate"}
            src={
              "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/left__decorate.png"
            }
          ></img>
          <img
            className={"right__decorate"}
            src={
              "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/right__decorate.png"
            }
          ></img>
          <p className={"define__title"}> /  /  / Python</p>
          {defineList.map((item, index) => {
            return <DefineItem item={item} key={index}></DefineItem>
          })}
        </div>
        <div className={"course__introduce"}></div>
        {isOnline ? (
          <div className={"bottom__btn_group"}>
            <div className={"course__price"}>
              <div className={"money"}>
                {payMoney}
                <span style={{ fontSize: "18px" }}></span>
              </div>
              <div className={"discount"}>
                限时特惠
                <div className={"triangle"}></div>
              </div>
            </div>
FE committed
338

zhanghaozhe committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
            <div className={"btn__group"}>
              <div className={"try__study"} onClick={this.tryLearn}>
                免费试学
              </div>
              <div className={"sign__now"} onClick={this.signUp}>
                立即报名
              </div>
            </div>
          </div>
        ) : (
          <div className="bottom__btn_group">
            <p className="online__label">Python人工智能</p>
            <button className="online__button">即将上架 敬请期待</button>
          </div>
        )}
FE committed
354

zhanghaozhe committed
355 356
        {/* 课程介绍 */}
        <Description list={desList} />
FE committed
357

zhanghaozhe committed
358
        <NoWorry list={worryList}></NoWorry>
FE committed
359

zhanghaozhe committed
360 361 362 363 364 365
        <Study
          syllabus={syllabus}
          allSyllabusShow={allSyllabusShow}
          show={this.showAll}
          hide={this.hideSome}
        ></Study>
FE committed
366

zhanghaozhe committed
367 368 369 370 371 372 373 374
        {/* 课后实操 */}
        <Test
          practice={practice}
          allPracticeShow={allPracticeShow}
          show={this.showAll}
          hide={this.hideSome}
        />
        <Team />
FE committed
375

zhanghaozhe committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
        {/* 试学体验 */}
        <Experience tryLearn={this.tryLearn} isOnline={isOnline} />
        <img
          style={{
            display: "block",
            width: "100%",
            height: "8px",
          }}
          src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/changjian.png"
          alt=""
        />

        {/* 常见问题 */}
        <Progream />
        {toApp && <Mask type={1} closePop={this.closePop} />}
      </div>
    )
  }
xuzhenghua committed
394 395 396
}

function DefineItem(props) {
zhanghaozhe committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  const {
    item,
    item: { desInfo },
  } = props
  return (
    <div className={"number_one"}>
      <img className={"trophy"} src={item.titleUrl}></img>
      <p className={"item__title"}>{item.title}</p>
      <p className={"item__subtitle"} style={{ width: item.subWidth }}>
        {item.subTitle}
      </p>
      <img
        style={{ width: desInfo.width, height: desInfo.height }}
        src={item.bottomUrl}
      ></img>
    </div>
  )
xuzhenghua committed
414 415
}

wangshuo committed
416
export default PythonDes