index.js 5.76 KB
Newer Older
xuzhenghua committed
1
import React, {Component} from 'react';
xuzhenghua committed
2
import {http, getParam, SendMessageToApp} from '@/utils';
xuzhenghua committed
3 4
import listFrame from './../listFrame/index';
import './index.scss';
xuzhenghua committed
5 6 7 8
import {Toast} from "antd-mobile"
import {connect} from "react-redux";
import {Link, withRouter} from "react-router-dom"

xuzhenghua committed
9 10

class ReserveCourse extends Component {
xuzhenghua committed
11 12 13
    constructor(props) {
        super(props);
        this.state = {
xuzhenghua committed
14 15
            courseData: [],
            isShowMore: false
xuzhenghua committed
16 17
        };
    }
xuzhenghua committed
18

xuzhenghua committed
19 20 21 22 23 24 25 26 27
    componentDidMount() {
        this.fetchAICourse();
    }

    fetchAICourse = () => {
        http.get(`${API.home}/sys/pre_coursee`).then(res => {
            const {code, data, msg} = res.data;
            if (code === 200) {
                this.setState({
xuzhenghua committed
28 29
                    courseData: data.filter((item, index) => index < 4),
                    courseDataAll: data
xuzhenghua committed
30 31 32 33 34 35 36
                })
            } else {
                Toast.info(msg, 2);
            }
        });
    }

xuzhenghua committed
37

xuzhenghua committed
38 39 40 41 42
    // 立即付定金
    expandPaydj = (courseId) => {
        const {user, history} = this.props;
        const uid = user && user.data && user.data.uid;
        if (!uid) {
xuzhenghua committed
43 44 45 46 47 48
            if (!getParam('version')) {
                this.props.history.push('/passport/login')
            } else {
                SendMessageToApp("toLogin");
            }

xuzhenghua committed
49
        } else {
xuzhenghua committed
50 51 52 53 54 55 56 57 58 59 60 61
            if (!getParam('version')) {
                this.props.history.push(
                    `/deposit-order?oid=${courseId}&source=${2}`,
                    {
                        id: courseId,
                        isexpand: 1,
                        sourcenum: 2
                    }
                )
            } else {
                SendMessageToApp("earnestMoney", courseId);
            }
xuzhenghua committed
62 63 64 65
        }
    }
    // 立即付尾款
    expandPaywk = (courseId, day) => {
xuzhenghua committed
66
        Toast.info("付尾款时间将在" + day + "开启", 2);
xuzhenghua committed
67 68 69
    }
    // 去学习
    tostudy = (courseId) => {
xuzhenghua committed
70 71 72 73 74 75 76 77 78
        if (!getParam('version')) {
            this.props.history.push(`/getDetail?id=${courseId}`)
        } else {
            let data = {
                courseId: courseId,
                type: 0 // 正常跳课程详情页type:0,积福气浏览课程详情页-没有浏览过type:1 已浏览过type:2
            }
            SendMessageToApp("toCourse", data);
        }
xuzhenghua committed
79
    }
xuzhenghua committed
80 81 82
    // 查看更多
    showMoreData = () => {
        this.setState({
xuzhenghua committed
83
            isShowMore: !this.state.isShowMore,
xuzhenghua committed
84 85 86
            courseData: this.state.isShowMore ? this.state.courseDataAll.filter((item, index) => index < 4) : this.state.courseDataAll,
        })
    }
xuzhenghua committed
87 88

    render() {
xuzhenghua committed
89
        const {courseData, isShowMore} = this.state;
xuzhenghua committed
90 91 92 93 94 95
        return (
            <div className='reserve-course-module'>
                <CourseList courseData={courseData}
                            expandPaydj={this.expandPaydj}
                            expandPaywk={this.expandPaywk}
                            tostudy={this.tostudy}/>
xuzhenghua committed
96 97 98 99 100

                <button className="more-button" onClick={this.showMoreData}>
                    {isShowMore ? '收起' : '展开更多'}
                </button>

xuzhenghua committed
101 102 103
            </div>
        )
    }
xuzhenghua committed
104 105
}

xuzhenghua committed
106 107 108 109 110 111 112 113 114
function CourseList(props) {
    const {courseData, expandPaydj, expandPaywk, tostudy} = props
    return (
        <div className="course-list">
            <ul>
                {
                    courseData.map((item, index) => {
                        return (
                            <li className="course-item-box" key={index}>
xuzhenghua committed
115
                                <a onClick={() => tostudy(item.course_id)}>
xuzhenghua committed
116 117 118 119 120 121 122 123
                                    <div className="top">
                                        <div className="square">
                                            <p className="circular">
                                                到手最低¥<span>{Number(item.price) - Number(item.deduction_amount) - Number(item.limit_amount)}</span>
                                            </p>
                                        </div>
                                        <img className="course-img" src={item.image_name} alt=""/>
                                    </div>
xuzhenghua committed
124
                                </a>
xuzhenghua committed
125 126 127 128 129 130

                                <p className="count-price">
                                    =原价¥{item.price}
                                    <span>-抵扣¥<i>{item.deduction_amount}</i></span>
                                    <span>-膨胀券¥<i>{item.limit_amount}</i></span>
                                </p>
xuzhenghua committed
131

xuzhenghua committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
                                <div className="btn">
                                    {
                                        item.is_buy === 0 &&
                                        <button className="to-expand-buy1"
                                                onClick={() => expandPaydj(item.course_id)}>立即付定金</button>
                                    }
                                    {
                                        item.is_buy === 1 &&
                                        <button className="to-expand-buy2"
                                                onClick={() => expandPaywk(item.course_id, item.final_start_time)}>立即付尾款</button>
                                    }
                                    {
                                        item.is_buy === 2 &&
                                        <button className="to-study"
                                                onClick={() => tostudy(item.course_id)}>开始学习</button>
                                    }

                                </div>
                            </li>
                        )
                    })
                }
            </ul>
        </div>
    )
xuzhenghua committed
157 158
}

xuzhenghua committed
159 160 161 162
export default listFrame(connect(
    state => ({
        user: state.user
    }),
zhanghaozhe committed
163
)(withRouter(ReserveCourse)))