index.js 1.92 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6
import React, { PureComponent } from "react"
import { connect } from "react-redux"
import "./recommendation.scss"
import { http } from "src/utils"
import { Toast } from "antd-mobile"
import VList from "src/common/v-list-base"
7

zhanghaozhe committed
8 9 10 11 12 13 14
const Bottom = ({ item }) => {
  return (
    <div className="bottom">
      <span className="price">¥{item.price1}</span>
      <span className="stale-price">¥{item.price0}</span>
    </div>
  )
15 16
}

17
@connect()
zhanghaozhe committed
18
class Recommendation extends PureComponent {
zhanghaozhe committed
19 20 21 22 23
  state = {
    num: 10,
    list: [],
    courseId: null,
  }
24

zhanghaozhe committed
25 26 27
  componentDidMount() {
    this.getRecommendation()
  }
28

zhanghaozhe committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  getRecommendation = () => {
    http
      .get(
        `${API.home}/m/play/recommend_course/${this.props.vCourseId}?num=${this.state.num}`
      )
      .then((res) => {
        const data = res.data
        if (data.code === 200) {
          this.setState({
            list: Array.isArray(data.data) ? data.data : [],
          })
        } else {
          Toast.info(data.msg)
        }
      })
  }
45

zhanghaozhe committed
46
  toCourseDetail = (id) => {
zhanghaozhe committed
47
    const { history } = this.props
zhanghaozhe committed
48 49
    history.push(`/detail?id=${id}`)
  }
50

zhanghaozhe committed
51 52 53 54 55 56 57 58 59 60 61 62 63
  render() {
    return this.state.list.length ? (
      <div className="recommendation">
        <div className={"title"}>相关推荐</div>
        <ul>
          {this.state.list.map((item) => {
            const Info = (
              <div className="info">
                <p className="title text-overflow-1">{item.course_title}</p>
                <p className="des text-overflow-2">{item.simpledescription}</p>
                <Bottom item={item} />
              </div>
            )
64

zhanghaozhe committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78
            return (
              <VList
                key={item.course_id}
                img={item.image_name}
                handleClick={this.toCourseDetail}
                info={Info}
                id={item.course_id}
              />
            )
          })}
        </ul>
      </div>
    ) : null
  }
79 80
}

zhanghaozhe committed
81
export default Recommendation