index.js 6.83 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 46 47
            if (res.data.code === 200) {
                this.setState({
                    dataList: res.data.data
                })
xuzhenghua committed
48 49
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
50 51 52 53
            }
        })
    }
    // 一键拼团
xuzhenghua committed
54
    group = () => {
zhanghaozhe committed
55
        http.get(`${API.home}/m/home/grouponList`).then((res) => {
xuzhenghua committed
56 57 58 59
            if (res.data.code === 200) {
                this.setState({
                    dataList: res.data.data
                })
xuzhenghua committed
60 61
            } else {
                Toast.info(res.data.msg, 2)
xuzhenghua committed
62 63 64 65
            }
        })
    }
    // tab 切换
xuzhenghua committed
66
    ontabclick = (tab, index) => {
xuzhenghua committed
67
        this.state.courseStatus = index
xuzhenghua committed
68
        switch (index) {
xuzhenghua committed
69 70 71 72 73 74 75 76 77 78 79
            case 0:
                this.specialSale()
                break
            case 1:
                this.bargain()
                break
            default:
                this.group()
        }
    }

80 81
    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
82
        // dispatch(getCourses(id, () => {
xuzhenghua committed
83
            history.push(`/detail?id=${id}`)
84
        // }));
85
    }
xuzhenghua committed
86 87 88 89 90 91

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

xuzhenghua committed
102 103 104 105
                        <Tabs
                            tabs={tabs}
                            animated={false}
                            onChange={(tab, index) => this.ontabclick(tab, index)}
2  
xuzhenghua committed
106 107 108 109
                            swipeable={false}
                            renderTabBar={props => <div className={'custom-tab-bar'}>
                                <Tabs.DefaultTabBar {...props}/>
                            </div>}
xuzhenghua committed
110 111 112 113 114 115
                        >
                            <div className='tabs'>
                                <ul>
                                    {this.state.dataList.map((item, index) => {
                                        const Info = (
                                            <div className="info">
116 117
                                                <p className='title' onClick={() => this.toCourseDetail(item.course_id)}>
                                                    {/* <Link to={`/detail?id=${item.course_id}`}> */}
xuzhenghua committed
118
                                                        {item.course_title}
119
                                                    {/* </Link> */}
xuzhenghua committed
120
                                                </p>
xuzhenghua committed
121 122 123 124 125 126 127 128 129 130 131 132
                                                <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 &&
xuzhenghua committed
133
                                                    <a className="isbuy">已购买</a>
xuzhenghua committed
134 135 136 137 138
                                                    }
                                                </div>
                                            </div>
                                        )
                                        const status = (
2  
xuzhenghua committed
139
                                            !item.is_buy &&
xuzhenghua committed
140 141
                                            <div>
                                                {this.state.courseStatus === 1 &&
FE committed
142
                                                <p className='course-status'>砍价减{item.bargain_price}</p>
xuzhenghua committed
143
                                                }
xuzhenghua committed
144
                                                {this.state.courseStatus === 2 &&
xuzhenghua committed
145
                                                <p className='course-status'>拼团价{item.price}</p>
xuzhenghua committed
146
                                                }
147 148 149
                                                {
                                                    item.is_aist && <span className='return_cash'></span>
                                                }
xuzhenghua committed
150
                                            </div>
xuzhenghua committed
151 152
                                        )
                                        return (
xuzhenghua committed
153 154
                                            <VList
                                                key={index}
155
                                                img={item.image_name}
xuzhenghua committed
156
                                                id={item.course_id}
157 158 159 160
                                                status={status}
                                                info={Info}
                                                toDetail={this.toCourseDetail}
                                            />
xuzhenghua committed
161 162 163 164 165 166 167 168 169
                                        )
                                    })}
                                </ul>

                            </div>
                        </Tabs>
                        <WhiteSpace/>
                    </div>
                </Loading>
xuzhenghua committed
170 171 172 173 174 175
            </div>
        )
    }

}

176
export default Preferential;