index.js 5.91 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 {Link} from 'react-router-dom'
xuzhenghua committed
8
import Loading from '@/common/Loading'
xuzhenghua committed
9 10 11 12

class Preferential extends Component {
    constructor(props) {
        super(props)
xuzhenghua committed
13 14 15
        this.state = {
            dataList: [],
            courseStatus: 0,
xuzhenghua committed
16
            isLoading: true
xuzhenghua committed
17
        }
xuzhenghua committed
18 19
    }

xuzhenghua committed
20 21
    componentDidMount() {
        this.specialSale()
xuzhenghua committed
22 23
    }

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

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

xuzhenghua committed
77 78 79 80 81 82

    render() {
        const tabs = [
            {title: '限时特惠'},
            {title: '砍价专区'},
            {title: '一键拼团'}
xuzhenghua committed
83
        ]
xuzhenghua committed
84 85
        return (
            <div className='preferential'>
xuzhenghua committed
86
                <HeaderSearch></HeaderSearch>
xuzhenghua committed
87 88 89
                <Loading isLoading={this.state.isLoading}>
                    <div className='class-content'>
                        <WhiteSpace/>
xuzhenghua committed
90

xuzhenghua committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104
                        <Tabs
                            tabs={tabs}
                            animated={false}
                            onChange={(tab, index) => this.ontabclick(tab, index)}
                        >
                            <div className='tabs'>
                                <ul>
                                    {this.state.dataList.map((item, index) => {
                                        const Info = (
                                            <div className="info">
                                                <p className='title'>
                                                    <Link to={`/detail?id=${item.course_id}`}>
                                                        {item.course_title}
                                                    </Link>
xuzhenghua committed
105
                                                </p>
xuzhenghua committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
                                                <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 href="/#" className="isbuy">已购买</a>
                                                    }
                                                </div>
                                            </div>
                                        )
                                        const status = (
                                            <div>
                                                {this.state.courseStatus === 1 &&
                                                <p className='course-status'>砍价减{item.price1}</p>
xuzhenghua committed
127
                                                }
xuzhenghua committed
128 129
                                                {this.state.courseStatus === 2 &&
                                                <p className='course-status'>拼团减{item.price}</p>
xuzhenghua committed
130
                                                }
131 132 133
                                                {
                                                    item.is_aist && <span className='return_cash'></span>
                                                }
xuzhenghua committed
134
                                            </div>
xuzhenghua committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148
                                        )
                                        return (
                                            <VList key={index} img={item.image_name}
                                                   id={item.course_id} status={status}
                                                   info={Info}></VList>
                                        )
                                    })}
                                </ul>

                            </div>
                        </Tabs>
                        <WhiteSpace/>
                    </div>
                </Loading>
xuzhenghua committed
149 150 151 152 153 154
            </div>
        )
    }

}

xuzhenghua committed
155
export default Preferential