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

zhanghaozhe committed
18 19
@connect((state) => ({
  user: state.user,
zhanghaozhe committed
20 21
}))
class PythonDes extends Component {
zhanghaozhe committed
22 23 24 25 26 27 28 29 30 31 32 33 34
  constructor(props) {
    super(props)
    this.state = {
      syllabus: [], // 阶梯学习
      allSyllabus: [], // 阶梯学习
      allSyllabusShow: false,
      allPractice: [], // 课后实操
      toApp: false,
      payMoney: 0,
      isOnline: true, //课程是否上架
      courseInfo: {},
      isShowChannel: window.sessionStorage.getItem("isShowSiteWindowByChannel"),
      orderId: "",
zhanghaozhe committed
35
    }
zhanghaozhe committed
36
  }
zhanghaozhe committed
37

zhanghaozhe committed
38 39 40 41 42 43 44 45 46 47
  // 立即报名
  // signUp = () => {
  //   this.statistics(3)
  //   // 已登录
  //   if (!this.props.user.hasError) {
  //     this.toDetail()
  //   } else {// 未登录
  //     this.toLogin()
  //   }
  // }
zhanghaozhe committed
48

zhanghaozhe committed
49 50 51 52 53 54 55 56 57
  // 立即体验type=1、立即报名type=3、9.9特价试学type=2
  tryLearn = (type) => {
    this.statistics(type)
    // 已登录
    if (!this.props.user.hasError) {
      this.creatOid(type)
    } else {
      // 未登录
      this.toLogin()
zhanghaozhe committed
58
    }
zhanghaozhe committed
59 60 61
  }
  creatOid = (type) => {
    let url = ""
zhanghaozhe committed
62
    if (Number(type) === 3) {
zhanghaozhe committed
63 64 65
      url = `${API["base-api"]}/sys/it_baoming/create`
    } else {
      url = `${API["base-api"]}/sys/trial_create`
xuzhenghua committed
66
    }
zhanghaozhe committed
67 68 69
    http.post(url, { course_id: getParam("id") }).then((res) => {
      const { errno, data, msg } = res.data
      if (errno === 200) {
xuzhenghua committed
70
        this.setState({
zhanghaozhe committed
71 72 73 74 75 76 77 78 79 80 81 82 83
          orderId: data.oid,
        })
        this.weixinPay(data.oid)
      } else {
        Toast.info(msg, 2)
      }
    })
  }
  // 微信支付
  weixinPay = (orderId) => {
    // 微信内部-支付
    if (browser.isWeixin) {
      let url =
zhanghaozhe committed
84 85 86 87
        window.location.origin +
        window.location.pathname +
        "?id=" +
        getParam("id")
zhanghaozhe committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      window.location.href =
        "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" +
        encodeURIComponent(url + "&aa=bb&oid=" + orderId).toLowerCase() +
        "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
    } else {
      // 微信外部-支付
      http
        .get(`${API["base-api"]}/pay/wxpay/wap_charge/oid/${orderId}`)
        .then((res) => {
          if (res.data.errno === 0) {
            window.location.href =
              res.data.data.url +
              "&redirect_url=" +
              encodeURIComponent(
                window.location.href + "&weixinpay=1&oid=" + orderId
              ).toLowerCase()
          } else {
            Toast.info(res.data.msg, 2)
          }
xuzhenghua committed
107 108
        })
    }
zhanghaozhe committed
109
  }
xuzhenghua committed
110

zhanghaozhe committed
111 112 113 114 115 116 117 118
  toLearn = () => {
    const { backwardVersion } = this.props
    http
      .post(`${API["home"]}/m/it/user/trialCourse`, {
        course_id: getParam("id"),
      })
      .then((res) => {
        const { code, msg } = res.data
zhanghaozhe committed
119
        if (code === 200) {
zhanghaozhe committed
120 121 122 123
          if (!getParam("version")) {
            // H5
            this.setState({
              toApp: true,
xuzhenghua committed
124
            })
zhanghaozhe committed
125 126
          } else {
            // APP
xuzhenghua committed
127
            if (backwardVersion) {
zhanghaozhe committed
128 129 130 131
              Toast.info(
                "当前版本不支持该课程模式,请升级到最新版本或前往PC端体验",
                2
              )
xuzhenghua committed
132
            } else {
zhanghaozhe committed
133
              SendMessageToApp("toLearn", getParam("id"))
xuzhenghua committed
134
            }
zhanghaozhe committed
135 136 137
          }
        } else {
          Toast.info(msg, 2)
zhanghaozhe committed
138
        }
zhanghaozhe committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
      })
  }

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

  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)
          }
        })
    } else {
      // APP
      if (backwardVersion) {
        Toast.info(
          "当前版本不支持该课程模式,请升级到最新版本或前往PC端购买",
          2
        )
        let onlyoneUse = setTimeout(() => {
          clearTimeout(onlyoneUse)
          onlyoneUse = null
          SendMessageToApp("toPay", id)
        }, 2000)
      } else {
        SendMessageToApp("toPay", id)
      }
xuzhenghua committed
177
    }
zhanghaozhe committed
178
  }
zhanghaozhe committed
179

zhanghaozhe committed
180 181 182 183 184 185 186 187 188 189 190
  toLogin = () => {
    if (!getParam("version")) {
      // H5
      if (browser.isWeixin) {
        this.props.isWxloginFun(true)
      } else {
        this.props.history.push("/passport")
      }
    } else {
      // APP
      SendMessageToApp("toLogin")
zhanghaozhe committed
191
    }
zhanghaozhe committed
192
  }
zhanghaozhe committed
193

zhanghaozhe committed
194 195 196 197 198 199
  showAll = (key) => {
    if (key === 1) {
      this.setState({
        syllabus: this.state.allSyllabus,
        allSyllabusShow: true,
      })
zhanghaozhe committed
200
    }
zhanghaozhe committed
201 202 203 204 205
    if (key === 2) {
      this.setState({
        practice: this.state.allPractice,
        allPracticeShow: true,
      })
zhanghaozhe committed
206
    }
zhanghaozhe committed
207 208 209 210 211 212 213
  }
  hideSome = (key) => {
    if (key === 1) {
      this.setState({
        syllabus: this.state.allSyllabus.slice(0, 2),
        allSyllabusShow: false,
      })
xuzhenghua committed
214
    }
zhanghaozhe committed
215 216 217 218 219 220 221
    if (key === 2) {
      this.setState({
        practice: this.state.allPractice.slice(0, 2),
        allPracticeShow: false,
      })
    }
  }
zhanghaozhe committed
222

zhanghaozhe committed
223 224
  getStatus = () => {
    const { buyTry } = this.props
zhanghaozhe committed
225

zhanghaozhe committed
226 227 228 229 230 231 232 233
    http
      .get(
        `${API["home"]}/web/it_detail?course_id=${getParam(
          "id"
        )}&buy_try=${buyTry}`
      )
      .then((res) => {
        const { code, data, msg } = res.data
zhanghaozhe committed
234
        if (code === 200) {
zhanghaozhe committed
235 236 237 238 239 240 241 242 243
          this.setState({
            syllabus: data.syllabus.slice(0, 2),
            allSyllabus: data.syllabus,
            allPractice: data.practice,
            payMoney: data.course_info.price1,
            courseInfo: data.course_info,
          })
        } else {
          Toast.info(msg)
xuzhenghua committed
244
        }
zhanghaozhe committed
245 246 247 248 249
      })
  }

  componentDidMount() {
    this.getStatus()
xuzhenghua committed
250

zhanghaozhe committed
251 252 253
    const { backwardVersion, isPay } = this.props
    if (backwardVersion && isPay === 1) {
      Toast.info("当前版本不支持该课程模式,请升级到最新版本或前往PC端学习", 2)
xuzhenghua committed
254
    }
zhanghaozhe committed
255
  }
zhanghaozhe committed
256

zhanghaozhe committed
257 258 259 260
  // 统计
  statistics = (type) => {
    http.post(`${API.home}/web/it_click_num/${getParam("id")}`, { type })
  }
zhanghaozhe committed
261

zhanghaozhe committed
262 263 264 265
  shouldComponentUpdate(nextProps, nextState, nextContext) {
    if (this.props.isAppUpdate !== nextProps.isAppUpdate) {
      this.getStatus()
      return false
zhanghaozhe committed
266
    }
zhanghaozhe committed
267 268
    return true
  }
zhanghaozhe committed
269

zhanghaozhe committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
  render() {
    const {
      syllabus,
      allSyllabusShow,
      toApp,
      payMoney,
      isOnline,
      courseInfo,
    } = this.state
    return (
      <div className={"python__des"}>
        <div className={"des__start"}></div>
        {!!courseInfo.is_dist && <ShareRank courseInfo={courseInfo} />}
        <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>
zhanghaozhe committed
296

zhanghaozhe committed
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
            <div className={"btn__group"}>
              <div
                className={"try__study"}
                onClick={() => {
                  this.tryLearn(3)
                }}
              >
                立即报名
              </div>
              <div
                className={"sign__now"}
                onClick={() => {
                  this.tryLearn(2)
                }}
              >
                9.9特价试学
              </div>
            </div>
          </div>
        ) : (
          <div className="bottom__btn_group">
            <p className="online__label">Python人工智能</p>
            <button className="online__button">即将上架 敬请期待</button>
          </div>
        )}
zhanghaozhe committed
322

zhanghaozhe committed
323 324 325
        {Number(this.state.isShowChannel) === 1 && (
          <CallApp className="toapp" />
        )}
zhanghaozhe committed
326 327
        {/* 课程介绍 */}
        <Description />
zhanghaozhe committed
328

zhanghaozhe committed
329 330 331 332 333 334
        <Study
          syllabus={syllabus}
          allSyllabusShow={allSyllabusShow}
          show={this.showAll}
          hide={this.hideSome}
        ></Study>
zhanghaozhe committed
335

zhanghaozhe committed
336 337
        {/*精选习题*/}
        <Selection />
zhanghaozhe committed
338

zhanghaozhe committed
339 340
        {/*项目实战*/}
        <InAction />
zhanghaozhe committed
341

zhanghaozhe committed
342
        <Team />
zhanghaozhe committed
343

zhanghaozhe committed
344 345 346 347 348 349 350 351 352 353 354
        {/* 试学体验 */}
        <Experience tryLearn={this.tryLearn} isOnline={isOnline} />
        <img
          style={{
            display: "block",
            width: "100%",
            height: "8px",
          }}
          src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/mlCourse/m/di.png"
          alt=""
        />
zhanghaozhe committed
355

zhanghaozhe committed
356 357 358 359 360 361
        {/* 常见问题 */}
        <Progream />
        {toApp && <Mask type={1} closePop={this.closePop} />}
      </div>
    )
  }
zhanghaozhe committed
362 363 364
}

export default PythonDes