index.js 7.35 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react'
import {VList} from '../../common'
xuzhenghua committed
3
import {Tabs, WhiteSpace, Toast} from 'antd-mobile'
xuzhenghua committed
4
import './index.scss'
xuzhenghua committed
5
import HeaderSearch from '../../common/HeaderSearch/index'
zhanghaozhe committed
6
import {http} from "@/utils"
xuzhenghua committed
7
import Loading from '@/common/Loading'
8
import {connect} from 'react-redux';
xuzhenghua committed
9

10 11 12
@connect(({user}) => ({
    user
}))
xuzhenghua committed
13 14 15
class Preferential extends Component {
    constructor(props) {
        super(props)
xuzhenghua committed
16 17 18
        this.state = {
            dataList: [],
            courseStatus: 0,
xuzhenghua committed
19
            isLoading: true
xuzhenghua committed
20
        }
xuzhenghua committed
21 22
    }

xuzhenghua committed
23 24
    componentDidMount() {
        this.specialSale()
xuzhenghua committed
25 26
    }

xuzhenghua committed
27
    // 限时特惠
xuzhenghua committed
28
    specialSale = () => {
zhanghaozhe committed
29
        http.get(`${API.home}/m/home/weekDiscounts`).then((res) => {
xuzhenghua committed
30 31
            if (res.data.code === 200) {
                this.setState({
xuzhenghua committed
32 33
                    dataList: res.data.data,
                    isLoading: false
xuzhenghua committed
34
                })
xuzhenghua committed
35 36
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
37
            }
xuzhenghua committed
38

xuzhenghua committed
39 40 41
        })
    }
    // 砍价专区
xuzhenghua committed
42
    bargain = () => {
zhanghaozhe committed
43
        http.get(`${API.home}/m/home/bargainZone`).then((res) => {
xuzhenghua committed
44 45
            if (res.data.code === 200) {
                this.setState({
xuzhenghua committed
46
                    dataList: JSON.stringify(res.data.data) == '{}' ? []:res.data.data,
47
                    isLoading: false,
xuzhenghua committed
48
                })
xuzhenghua committed
49 50
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
51 52 53 54
            }
        })
    }
    // 一键拼团
xuzhenghua committed
55
    group = () => {
zhanghaozhe committed
56
        http.get(`${API.home}/m/home/grouponList`).then((res) => {
xuzhenghua committed
57 58
            if (res.data.code === 200) {
                this.setState({
59 60
                    dataList: res.data.data,
                    isLoading: false,
xuzhenghua committed
61
                })
xuzhenghua committed
62 63
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
64 65 66 67
            }
        })
    }
    // tab 切换
xuzhenghua committed
68
    ontabclick = (tab, index) => {
69 70 71 72
        this.setState({
            courseStatus: index,
            isLoading: true,
        })
xuzhenghua committed
73
        switch (index) {
xuzhenghua committed
74 75 76 77 78 79 80 81 82 83 84
            case 0:
                this.specialSale()
                break
            case 1:
                this.bargain()
                break
            default:
                this.group()
        }
    }

85
    toCourseDetail = (id) => {
xuzhenghua committed
86
        const {dispatch, history} = this.props;
87
        // dispatch(getCourses(id, () => {
xuzhenghua committed
88
        history.push(`/detail?id=${id}`)
89
        // }));
90
    }
xuzhenghua committed
91 92 93 94 95 96

    render() {
        const tabs = [
            {title: '限时特惠'},
            {title: '砍价专区'},
            {title: '一键拼团'}
xuzhenghua committed
97
        ]
xuzhenghua committed
98 99
        const {user = {}} = this.props;
        let isLogin = user.data && user.data.uid ? true : false;
xuzhenghua committed
100 101
        return (
            <div className='preferential'>
xuzhenghua committed
102
                <HeaderSearch isLogin={isLogin}/>
xuzhenghua committed
103 104 105
                <Loading isLoading={this.state.isLoading}>
                    <div className='class-content'>
                        <WhiteSpace/>
xuzhenghua committed
106

xuzhenghua committed
107 108 109 110
                        <Tabs
                            tabs={tabs}
                            animated={false}
                            onChange={(tab, index) => this.ontabclick(tab, index)}
2  
xuzhenghua committed
111
                            swipeable={false}
112
                            page={this.state.courseStatus}
2  
xuzhenghua committed
113 114 115
                            renderTabBar={props => <div className={'custom-tab-bar'}>
                                <Tabs.DefaultTabBar {...props}/>
                            </div>}
xuzhenghua committed
116
                        >
117 118
                        </Tabs>
                        <div className='tabs'>
xuzhenghua committed
119 120 121 122 123 124 125 126 127 128 129
                            {
                                this.state.dataList.length>0?
                                <ul>
                                    {this.state.dataList.map((item, index) => {
                                        const Info = (
                                            <div className="info">
                                                <p className='title'
                                                   onClick={() => this.toCourseDetail(item.course_id)}>
                                                    {/* <Link to={`/detail?id=${item.course_id}`}> */}
                                                    {item.course_title}
                                                    {/* </Link> */}
130
                                                </p>
xuzhenghua committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
                                                <p className='contact text-overflow-2'>{item.course_desc}</p>
                                                <div className='des'>
                                                    {!item.is_buy &&
                                                    <p className="course-price">
                                                        {this.state.courseStatus === 0 &&
                                                        <span className='price'>特惠价:</span>
                                                        }
                                                        <span className="new">¥{item.price1}</span>
                                                        <span className="old">¥{item.price0}</span>
                                                    </p>
                                                    }
                                                    {item.is_buy &&
                                                    <a className="isbuy">已购买</a>
                                                    }
                                                </div>
                                            </div>
                                        )
                                        const status = (
                                            !item.is_buy &&
                                            <div>
                                                {this.state.courseStatus === 1 &&
                                                <p className='course-status'>砍价减{item.bargain_price}</p>
                                                }
                                                {this.state.courseStatus === 2 &&
                                                <p className='course-status'>拼团价{item.price}</p>
xuzhenghua committed
156
                                                }
xuzhenghua committed
157 158
                                                {
                                                    item.is_aist && <span className='return_cash'></span>
159
                                                }
xuzhenghua committed
160
                                            </div>
xuzhenghua committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174
                                        )
                                        return (
                                            <VList
                                                key={index}
                                                img={item.image_name}
                                                id={item.course_id}
                                                status={status}
                                                info={Info}
                                                toDetail={this.toCourseDetail}
                                            />
                                        )
                                    })}
                                </ul>:<div className={'notdata'}>砍价的课程已被设置为双十一活动课程,参加双十一活动购买课程优惠更多哦!</div>
                            }
xuzhenghua committed
175

176
                        </div>
xuzhenghua committed
177 178 179
                        <WhiteSpace/>
                    </div>
                </Loading>
xuzhenghua committed
180 181 182 183 184 185
            </div>
        )
    }

}

186
export default Preferential;