Commit 903baf13 by zhanghaozhe

限时免费

parent 98f84208
...@@ -2,17 +2,30 @@ import React, { Component } from 'react' ...@@ -2,17 +2,30 @@ import React, { Component } from 'react'
import { http } from "@/utils" import { http } from "@/utils"
import './index.scss' import './index.scss'
import { HeaderBar } from "@common/index" import { HeaderBar } from "@common/index"
import { WhiteSpace } from "antd-mobile"; import { WhiteSpace, Toast } from "antd-mobile";
import VList from '@/common/v-list-base' import VList from '@/common/v-list-base'
import WithFullSize from "@/HOCs/WithFullSize"
function showToast(msg) {
Toast.info(msg, 2, null, false)
}
class LimitFree extends Component { class LimitFree extends Component {
nav nav
state = { state = {
tabs: new Array(10).fill('a').map((item, i) => ({ tab: {
title: `${i + 1}th Tab` 0: 'tab0',
})), 1: 'tab1',
2: 'tab2',
3: 'tab3',
4: 'tab4',
5: 'tab5',
6: 'tab6',
7: 'tab7',
8: 'tab8',
9: 'tab9',
},
courses: [ courses: [
{ {
img: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/20a86c1353.jpg', img: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/20a86c1353.jpg',
...@@ -39,44 +52,68 @@ class LimitFree extends Component { ...@@ -39,44 +52,68 @@ class LimitFree extends Component {
price1: 199, price1: 199,
}, },
], ],
navItemStyle: {} navItemStyle: {},
tabActiveIndex: 0
} }
componentDidMount() { componentDidMount() {
this.initializeNav() this.getData()
}
getData = () => {
Promise.all([http.get(`${API.home}/sys/category`), http.get(`${API.home}/sys/course`)])
.then(res => {
const [tab, courses] = res
const {data: tabData, code: tabCode, msg: tabMsg} = tab.data
const {data: coursesData, code: coursesCode, msg: coursesMsg} = courses.data
if (tabCode == 200) {
this.setState({
tab: tabData
})
} else {
showToast(tabMsg)
}
if (coursesCode === 200) {
this.setState({
courses: coursesData
})
} else {
showToast(coursesMsg)
}
})
} }
handleClick = id => { handleClick = id => {
} }
initializeNav = () => { changeTab = (e, index) => {
const {tabs} = this.state const {tabActiveIndex} = this.state
const navItemNum = 5 if (tabActiveIndex !== index) {
const navItemLen = tabs.length this.setState({
console.log(getComputedStyle(this.nav).paddingLeft) tabActiveIndex: index
if(navItemLen <= navItemNum){ }
return )
} }
} }
render() { render() {
const {tabs, courses, navItemStyle} = this.state const {tab, courses, navItemStyle, tabActiveIndex} = this.state
return ( return (
<div className='limit-free'> <div className='limit-free'>
<HeaderBar arrow={true} title={'限时免费'}></HeaderBar> <HeaderBar arrow={true} title={'限时免费'}></HeaderBar>
<div className="banner"> <div className="banner">
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/time_limited_free/M/banner.png" alt=""/> <img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/time_limited_free/M/banner.png" alt=""/>
</div> </div>
<nav ref={el => this.nav = el}> <nav>
<div className="prev-cover"></div> <div className="prev-cover"></div>
<ul> <ul ref={el => this.nav = el}>
{ {
tabs && !!tabs.length && tabs.map((item, index) => { tab && !!Object.keys(tab).length && Object.keys(tab).map((item, index) => {
return ( return (
<li key={index} className={index === 0 ? 'active' : ''} style={navItemStyle}> <li key={index} className={index === tabActiveIndex ? 'active' : ''} style={navItemStyle}
{item.title} onClick={e => this.changeTab(e, index)}>
<a href={`#category${item}`} target={'_self'}>{tab[item]}</a>
</li> </li>
) )
}) })
...@@ -87,56 +124,63 @@ class LimitFree extends Component { ...@@ -87,56 +124,63 @@ class LimitFree extends Component {
<WhiteSpace/> <WhiteSpace/>
<div className="course-list"> <div className="course-list">
<ul> <ul>
<li> {
<h2> tab && !!Object.keys(tab).length && Object.keys(tab).map(key => {
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/time_limited_free/M/category-icon.png" return (
alt=""/> <li key={key}>
<span>分类1</span> <h2 id={`category${key}`}>
</h2> <img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/time_limited_free/M/category-icon.png"
<ul className={'courses'}> alt=""/>
{ <span>{tab[key]}</span>
courses && courses.length && courses.map((item, index) => { </h2>
let des, bottom <ul className={'courses'}>
switch (item.status) { {
case 1: courses && courses.length && courses.map((item, index) => {
des = <div className={'learner'}> let des, bottom
<i className='iconfont iconRectangleCopy4'/> switch (item.status) {
<span>{item.count}人学习</span> case 1:
</div> des = <div className={'learner'}>
bottom = <div className={'bottom'}> <i className='iconfont iconRectangleCopy4'/>
<span className={'red'}>限时免费</span> <span>{item.play_times}人学习</span>
<span className={'origin-price'}>¥{item.price1}</span> </div>
<button>免费领取</button> bottom = <div className={'bottom'}>
</div> <span className={'red'}>限时免费</span>
break <span className={'origin-price'}>¥{item.price1}</span>
case 2: <button>免费领取</button>
des = <div className={'remain-time'}> </div>
<i className={'iconfont iconiconfront-21'}/> break
<span>125555分后过期</span> case 2:
</div> des = <div className={'remain-time'}>
break <i className={'iconfont iconiconfront-21'}/>
case 3: <span>125555分后过期</span>
</div>
break
case 3:
}
} const info = (
<div className='info'>
<div className='title'>{item.course_title}</div>
{des}
{bottom}
</div>
)
return (
<VList img={item.image_name}
handleClick={this.handleClick}
info={info}
key={index}
/>
)
})
}
</ul>
</li>
const info = ( )
<div className='info'> })
<div className='title'>{item.title}</div> }
{des}
{bottom}
</div>
)
return (
<VList img={item.img}
handleClick={this.handleClick}
info={info}
key={index}
/>
)
})
}
</ul>
</li>
</ul> </ul>
</div> </div>
<div className="no-more"> <div className="no-more">
...@@ -147,4 +191,4 @@ class LimitFree extends Component { ...@@ -147,4 +191,4 @@ class LimitFree extends Component {
} }
} }
export default LimitFree export default WithFullSize(LimitFree)
\ No newline at end of file \ No newline at end of file
.limit-free { .limit-free {
background: #F9F9FB; background: #F9F9FB;
min-height: 100%;
.banner { .banner {
font-size: 0; font-size: 0;
...@@ -10,18 +11,22 @@ ...@@ -10,18 +11,22 @@
} }
nav { nav {
position: relative; position: sticky;
top: 0;
left: 0;
display: flex; display: flex;
align-items: center; align-items: center;
height: 39px; height: 39px;
padding: 0 18px;
background: #fff; background: #fff;
overflow: hidden;
z-index: 999;
.prev-cover, .next-cover { .prev-cover, .next-cover {
position: absolute; position: absolute;
top: 0; top: 0;
width: 44px; width: 44px;
height: 39px; height: 39px;
pointer-events: none;
} }
.prev-cover { .prev-cover {
...@@ -38,15 +43,22 @@ ...@@ -38,15 +43,22 @@
ul { ul {
width: 100%; width: 100%;
height: 100%; height: 100%;
padding: 0 18px;
display: flex; display: flex;
align-items: center; align-items: center;
overflow-x: auto;
&::-webkit-scrollbar {
display: none;
}
} }
li { li {
margin-right: 23px; width: 20%;
text-align: center; text-align: center;
height: 100%; height: 100%;
line-height: 39px; line-height: 39px;
flex-shrink: 0;
&.active { &.active {
color: #09f; color: #09f;
...@@ -62,6 +74,10 @@ ...@@ -62,6 +74,10 @@
} }
.course-list li{
scroll-margin-top: 100px;
}
.courses li:nth-last-child(1) { .courses li:nth-last-child(1) {
margin-bottom: 0; margin-bottom: 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment