index.js 7.78 KB
Newer Older
zhanghaozhe committed
1 2
import React from "react"
import { Link, withRouter } from "react-router-dom"
zhanghaozhe committed
3
import { Course } from "src/common/index"
zhanghaozhe committed
4
import "./index.scss"
5 6 7 8

// 课程模块儿公共组件
// 课程数量是奇数第一个课程需要横着展示沾满一行,课程数量是偶数一行显示两个

zhanghaozhe committed
9 10
const HomeCourseList = function ({ modules, history }) {
  const toDetail = (id) => {
11 12 13
    history.push(`/detail?id=${id}`)
  }

zhanghaozhe committed
14 15 16 17 18 19 20 21 22 23 24
  return (
    modules.length > 0 &&
    modules.map((module, i) => {
      return (
        <div key={i}>
          <Module module={module} toDetail={toDetail} />
          <p className="borderTop" />
        </div>
      )
    })
  )
25 26
}

zhanghaozhe committed
27
const Module = function CourseList({ module, toDetail }) {
28 29 30
  let filterList = []
  let isOdd = module.list.length % 2 === 0

zhanghaozhe committed
31
  if (module.name === "限时免费") {
32 33 34 35 36 37 38
    filterList = module.list
  } else {
    // 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图

    if (isOdd) {
      filterList = module.list
    } else {
zhanghaozhe committed
39 40 41 42
      filterList =
        module.list[0].course_img === module.list[0].course_img_small
          ? module.list
          : module.list.slice(1)
43 44 45
    }
  }

zhanghaozhe committed
46 47
  return (
    <div className="category home-course-list">
dazhou committed
48 49 50 51 52 53 54 55
      {module.name !== "双11秒杀课" ? (
        <h2 className="title">{module.name}</h2>
      ) : (
        <h2 className="bq">
          <img className="hot2" src={require("./../image/11.png")} alt="" />
        </h2>
      )}
      {module.name === "限时免费" && <span className={"hot"}>hot</span>}
zhanghaozhe committed
56 57 58 59 60 61

      {module.show_more === 1 && (
        <Link className="more" to="/classify">
          查看更多 &gt;
        </Link>
      )}
dazhou committed
62

zhanghaozhe committed
63 64 65 66 67 68 69 70 71 72 73
      {module.show_more === 2 ? (
        module.name === "限时免费" ? (
          <Link className="more" to={"/free"}>
            查看更多 &gt;
          </Link>
        ) : (
          <Link className="more" to={module.more_page}>
            查看更多 &gt;
          </Link>
        )
      ) : null}
dazhou committed
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
      {module.name === "初级入门课" ? (
        <ul className="index-course-detail">
          {module.name !== "限时免费" &&
            !isOdd &&
            module.list[0].course_img !== module.list[0].course_img_small && (
              <div
                className="category-vip"
                onClick={() => toDetail(module.list[0].course_id)}
              >
                <img src={module.list[0].course_img} alt="" />
              </div>
            )}
          {filterList.map((item, index) => {
            const top = item.is_limit_free ? null : (
              <div>
                {item.is_audition === true && (
                  <span className="audition">
                    <i className={"iconfont iconerji"}></i>试
                  </span>
                )}
                {item.is_aist && <span className="return_bash"></span>}
              </div>
            )

            const bottom = <Bottom course={item} course1={module} />

            const status = item.is_limit_free ? null : (
              <div>
                {item.is_bargain && (
                  <p className="course-status">砍价减{item.bargain_price}</p>
                )}
                {item.is_groupon && (
                  <p className="course-status">拼团价{item.groupon_price}</p>
                )}
              </div>
            )
            return (
              <Course
                key={index}
                top={top}
                data={item}
                bottom={bottom}
                status={status}
                img={item.course_img_small}
                title={item.course_title}
                id={item.course_id}
                toDetail={toDetail}
                className="text-overflow-2"
              />
            )
          })}
          <div className="vip">
            <Link to={"/vip/newvip"}>
              <img
                src="https://julyedu-img.oss-cn-beijing.aliyuncs.com/huiyuanganggaowei.png"
                alt=""
              />
            </Link>
            <a
              href="https://live.easyliao.com/live/chat.do?c=27526&g=53481&config=81372"
              className="consult"
              target="_blank"
zhanghaozhe committed
136
            >
dazhou committed
137 138 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
              <img
                className="govip"
                src={require("./../image/kt.png")}
                alt=""
              />
            </a>
          </div>
        </ul>
      ) : (
        <ul className="index-course-detail">
          {module.name !== "限时免费" &&
            !isOdd &&
            module.list[0].course_img !== module.list[0].course_img_small && (
              <div
                className="category-vip"
                onClick={() => toDetail(module.list[0].course_id)}
              >
                <img src={module.list[0].course_img} alt="" />
              </div>
            )}
          {filterList.map((item, index) => {
            const top = item.is_limit_free ? null : (
              <div>
                {item.is_audition === true && (
                  <span className="audition">
                    <i className={"iconfont iconerji"}></i>试
                  </span>
                )}
                {item.is_aist && <span className="return_bash"></span>}
              </div>
            )
wangshuo committed
168

dazhou committed
169
            const bottom = <Bottom course={item} course1={module} />
wangshuo committed
170

dazhou committed
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
            const status = item.is_limit_free ? null : (
              <div>
                {item.is_bargain && (
                  <p className="course-status">砍价减{item.bargain_price}</p>
                )}
                {item.is_groupon && (
                  <p className="course-status">拼团价{item.groupon_price}</p>
                )}
              </div>
            )
            return (
              <Course
                key={index}
                top={top}
                data={item}
                bottom={bottom}
                status={status}
                img={item.course_img_small}
                title={item.course_title}
                id={item.course_id}
                toDetail={toDetail}
                className="text-overflow-2"
              />
            )
          })}
        </ul>
      )}
wangshuo committed
198 199
      {/* <LazyLoad offset={50}> */}

zhanghaozhe committed
200 201 202
      {/* </LazyLoad> */}
    </div>
  )
203 204
}
//限时免费
zhanghaozhe committed
205
function LimitFree({ course }) {
206
  /*
zhanghaozhe committed
207 208 209 210
   *
   * limit_free_status: 0-未领取 1-已领取 2-已过期
   *
   * */
211 212
  switch (course.limit_free_status) {
    case 0:
zhanghaozhe committed
213 214 215 216 217 218 219 220
      return (
        <Link to={`/detail?id=${course.course_id}`}>
          <p className={"course-price"}>
            <span className={"free"}>免费领取</span>
            <span className={"old"}>¥{course.price}</span>
          </p>
        </Link>
      )
221
    case 1:
zhanghaozhe committed
222
      return <div className={"isbuy"}>已领取</div>
223
    default:
zhanghaozhe committed
224 225 226 227 228 229
      return (
        <p className="course-price">
          <span className="new">¥{course.discounts_price}</span>
          <span className="old">¥{course.price}</span>
        </p>
      )
230 231 232 233
  }
}

//课程底部
dazhou committed
234
function Bottom({ course, course1 }) {
235 236
  if (course.is_buy) {
    if (course.is_limit_free && course.limit_free_status === 1) {
wangshuo committed
237
      return <div className={"isbuy"}>已领取</div>
238
    } else {
zhanghaozhe committed
239
      return <div className={"isbuy"}>已购买</div>
240 241
    }
  } else {
zhanghaozhe committed
242 243 244
    return course.is_limit_free ? (
      <LimitFree course={course} />
    ) : (
wangshuo committed
245
      <div>
246
        {course1.name === "1分起购课" ? (
dazhou committed
247 248 249 250 251 252 253 254 255 256
          <p className="course-price">
            <span className="new">特惠价:¥{course.discounts_price}</span>
            <span className="old">¥{course.price}</span>
          </p>
        ) : (
          <p className="course-price">
            <span className="new">¥{course.discounts_price}</span>
            <span className="old">¥{course.price}</span>
          </p>
        )}
wangshuo committed
257
      </div>
zhanghaozhe committed
258
    )
259 260 261
  }
}

zhanghaozhe committed
262
export default withRouter(HomeCourseList)