index.js 2.31 KB
Newer Older
zhanghaozhe committed
1
import React, { PureComponent } from 'react'
zhanghaozhe committed
2 3 4
import './coupon.scss'
import classnames from 'classnames'

zhanghaozhe committed
5
class Coupon extends PureComponent {
zhanghaozhe committed
6

zhanghaozhe committed
7
    pick = () => {
zhanghaozhe committed
8 9
        let {useCoupon, invalid} = this.props
        !invalid && useCoupon && useCoupon(this.props.id)
zhanghaozhe committed
10 11 12
    }

    GoToUse = () => {
zhanghaozhe committed
13
        this.props.useCoupon(this.props.id)
zhanghaozhe committed
14 15 16 17
    }

    render() {
        let {
zhanghaozhe committed
18 19 20 21
            ctype,
            amount,
            format_expire_time,
            limit_course,
zhanghaozhe committed
22
            invalid,
zhanghaozhe committed
23
            course_title,
zhanghaozhe committed
24
            id,
zhanghaozhe committed
25 26
            selectedCouponId,
            showUseButton
zhanghaozhe committed
27 28 29 30
        } = this.props

        return (
            <li className='coupon' onClick={this.pick}>
zhanghaozhe committed
31 32 33 34 35 36 37 38
                <div className={classnames('coupon-info', invalid ? 'invalid' : `coupon-type${ctype}`)}>
                    <p className='type'>{ctype === 1 ? '代金券' : '课程券'}</p>
                    {
                        ctype === 1 ? <p className='denomination'>{amount} <span></span></p>
                            : <p className='course-title'>{course_title}</p>

                    }
                    <p className='expire'>有效期至:{format_expire_time}</p>
zhanghaozhe committed
39
                    {
zhanghaozhe committed
40
                        selectedCouponId === id &&
zhanghaozhe committed
41
                        <i className={classnames('iconfont icondanseshixintubiao-5', {
zhanghaozhe committed
42
                            check: !invalid
zhanghaozhe committed
43 44
                        })}
                        />
zhanghaozhe committed
45 46 47 48
                    }
                    <ul>
                        {
                            new Array(19).fill('a').map((item, index) => {
zhanghaozhe committed
49
                                return <li key={index}/>
zhanghaozhe committed
50 51 52 53 54
                            })
                        }
                    </ul>
                </div>
                <div className="coupon-des">
zhanghaozhe committed
55 56 57
                    <span className='limit'>{
                        limit_course === 0 ? '可用于大于代金券金额的课程' : `仅适用于《${course_title}》`
                    }</span>
zhanghaozhe committed
58
                    {
zhanghaozhe committed
59
                        showUseButton &&
zhanghaozhe committed
60 61 62 63 64
                        <button
                            className='use'
                            onClick={this.GoToUse}
                        >立即使用
                        </button>
zhanghaozhe committed
65
                    }
zhanghaozhe committed
66 67 68 69 70 71

                </div>
            </li>
        );
    }
}
zhanghaozhe committed
72 73

export default Coupon