index.js 34.4 KB
Newer Older
FE committed
1
import React, {Component} from 'react'
zhanghaozhe committed
2
import './bargain-middle-page.scss'
zhanghaozhe committed
3 4 5
import {HeaderBar, VList} from 'src/common'
import {Course} from 'src/common'
import {api, getParam, http, browser, wxShare} from "src/utils"
FE committed
6 7
import {Toast} from "antd-mobile"
import {Link, withRouter} from "react-router-dom"
xuzhenghua committed
8
import Ranking from './ranking'
FE committed
9
import {differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays} from "date-fns"
xuzhenghua committed
10
import Overlay from '../detail/overlay'
FE committed
11 12
import {compose} from "redux"
import {connect} from "react-redux";
13
import {getCourses} from './../detail/actions';
14
import classnames from 'classnames';
FE committed
15
import FollowBarcode from './barcode/index';
xuzhenghua committed
16

17 18 19
@connect(state => ({
    user: state.user
}))
xuzhenghua committed
20
class BargainMiddlePage extends Component {
zhanghaozhe committed
21

zhanghaozhe committed
22 23
    timer

xuzhenghua committed
24 25 26
    constructor(props) {
        super(props)
        this.state = {
xuzhenghua committed
27
            isShowOverlay: false,
xuzhenghua committed
28
            isOriginator: '',
xuzhenghua committed
29
            kanjiaIcon: require('./image/kanjia_icon.png'),
FE committed
30
            course: {}, // 当前砍价课程
FE committed
31
            courseList: [],  // 所有砍价课程
xuzhenghua committed
32 33 34 35 36 37
            data: '',
            bargainData: '',
            limitPeople: 0,
            outList: [],
            list: [],
            width: '0',
xuzhenghua committed
38
            isShowMore: '',
FE committed
39
            status: '',
xuzhenghua committed
40 41
            hour: '',
            min: '',
xuzhenghua committed
42 43
            sec: '',
            day: '',
44
            amount: '', // 每次砍掉的价格
xuzhenghua committed
45 46
            firendBaigainPrice: true,
            isshowYindao: false,
FE committed
47 48
            isLoaidng: true,
            imglink: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/',
xuzhenghua committed
49 50 51 52
        }
    }

    componentDidMount() {
xuzhenghua committed
53
        this.getBargainRankList(getParam('id'), 1)
xuzhenghua committed
54 55 56 57
        this.getBargainCourse()
        this.getBargainInfo()
    }

FE committed
58 59 60 61 62 63 64 65 66 67 68
    componentDidUpdate(prevProps) {
        let {user} = this.props
        let {user: prevUser} = prevProps
        if(!user.hasError && user.hasError !== prevUser.hasError){
            this.getBargainRankList(getParam('id'), 1)
            this.getBargainCourse()
            this.getBargainInfo()
        }
    }


xuzhenghua committed
69 70
    // 获取砍价信息
    getBargainInfo = () => {
FE committed
71
        // is_originator 来源,0-PC端扫码 1-M端分享 2-APP端分享
zhanghaozhe committed
72
        http.get(`${API.home}/m/bargain/info?bargaincode=${getParam('bargaincode')}&is_originator=${getParam('is_originator')}`).then((res) => {
xuzhenghua committed
73
            if (res.data.code === 200) {
FE committed
74 75 76 77 78 79 80 81 82
                this.setState(
                    {
                        data: res.data.data,
                        isOriginator: res.data.data.is_originator,
                        originatorUid: res.data.data.originator_uid,
                        course: res.data.data.course,
                        limitPeople: res.data.data.course.limit_people,
                        bargainData: res.data.data.bargain,
                        width: (res.data.data.bargain.bargain_price / res.data.data.bargain.total_price).toFixed(2) * 100 + '%'
xuzhenghua committed
83
                    },
FE committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
                    () => {
                        if (this.state.bargainData.expire_time) {
                            let date = this.state.bargainData.expire_time * 1000
                            let now = Date.now()
                            clearInterval(this.timer)
                            this.timer = setInterval(() => {
                                date -= 1000
                                let _d = new Date(date)
                                let s = differenceInSeconds(_d, now) % 60,
                                    m = differenceInMinutes(_d, now) % 60,
                                    h = differenceInHours(_d, now) % 24,
                                    d = differenceInDays(_d, now) % 24
                                this.setState({
                                    hour: h,
                                    min: m,
                                    sec: s,
                                    day: d
                                })
zhanghaozhe committed
102

FE committed
103 104
                            }, 1000)
                        }
zhanghaozhe committed
105
                    }
FE committed
106
                )
xuzhenghua committed
107 108 109 110 111 112 113 114
            } else {
                Toast.info(res.data.msg, 2)
            }
        })
    }

    // 获取砍价课程
    getBargainCourse = () => {
zhanghaozhe committed
115
        http.get(`${API.home}/m/bargain/courseList`).then((res) => {
xuzhenghua committed
116 117 118 119 120 121 122 123 124 125 126
            if (res.data.code === 200) {
                this.setState({
                    courseList: res.data.data
                })
            } else {
                Toast.info(res.data.msg, 2)
            }
        })
    }

    // 获取助理好友
127
    getBargainRankList = (id = '', type) => {
FE committed
128
        const bargain_code = getParam('bargaincode') || '';
xuzhenghua committed
129 130
        let data = {
            courseId: id,
FE committed
131 132
            type: type,
            bargain_code
xuzhenghua committed
133
        }
zhanghaozhe committed
134
        http.post(`${API.home}/m/bargain/rankList`, data).then((res) => {
xuzhenghua committed
135 136 137 138 139 140 141 142 143 144 145 146
            if (res.data.code === 200) {
                let arr = ['刀神', '刀王', '刀霸']
                let newList = res.data.data.out_list.map((item, i) => {
                    return {
                        ...item,
                        rank: arr[i]
                    }
                })
                this.setState({
                    list: res.data.data.list,
                    outList: newList
                })
FE committed
147
            } else if (res.data.code == 4030 || res.data.code == 4040) {
xuzhenghua committed
148 149 150 151 152 153
            } else {
                Toast.info(res.data.msg, 2)
            }
        })
    }

xuzhenghua committed
154
    // 直接支付
xuzhenghua committed
155
    toCart = () => {
FE committed
156 157 158 159
        const { history } = this.props;
        http.get(`${API['base-api']}/m/cart/addtopreorder/[${getParam('id')}]`).then((res) =>{
            const { errno, msg } = res.data;
            if (errno === 0) {
xuzhenghua committed
160
                this.props.history.push(`/order?id=[${getParam('id')}]`, {bargain: 1});
FE committed
161 162
            }else if(errno === 4030 || errno === 4040) {
                history.push('/passport');
xuzhenghua committed
163
            } else {
FE committed
164
                Toast.info(msg, 2);
xuzhenghua committed
165 166
            }
        })
xuzhenghua committed
167 168 169 170 171 172 173 174 175 176
        // let data = {
        //     course_id: getParam('id')
        // }
        // http.post(`${API.home}/m/cart/add`, data).then((res) => {
        //     if (res.data.code === 200 || res.data.code === 15001) {
        //         this.props.history.push('/shopcart')
        //     } else {
        //         Toast.info(res.data.msg, 2);
        //     }
        // })
xuzhenghua committed
177
    }
FE committed
178

xuzhenghua committed
179
    // 我要砍价列表的去支付
FE committed
180
    toCartBottom = (id) => {
xuzhenghua committed
181 182 183
        http.get(`${API['base-api']}/m/cart/addtopreorder/[${id}]`).then((res) => {
            if (res.data.errno === 0) {
                this.props.history.push(`/order?id=[${getParam('id')}]`, {bargain: 1});
xuzhenghua committed
184 185 186 187
            } else {
                Toast.info(res.data.msg, 2);
            }
        })
xuzhenghua committed
188 189 190 191 192 193 194
        // http.post(`${API.home}/m/cart/add`, data).then((res) => {
        //     if (res.data.code === 200 || res.data.code === 15001) {
        //         this.props.history.push('/shopcart')
        //     } else {
        //         Toast.info(res.data.msg, 2);
        //     }
        // })
xuzhenghua committed
195
    }
xuzhenghua committed
196 197 198 199 200 201 202

    // 查看更多
    getMore = () => {
        this.setState({
            isShowMore: true
        })
    }
FE committed
203

xuzhenghua committed
204 205 206 207
    // 自组件传给父组件的boxHide
    boxHide = (val) => {
        this.setState({isShowMore: val})
    }
zhanghaozhe committed
208

xuzhenghua committed
209 210
    // 领取砍价神器
    toArtifact = () => {
FE committed
211
        const { history } = this.props;
FE committed
212
        const { course: { course_id = '' } } = this.state;
xuzhenghua committed
213
        let data = {
FE committed
214
            courseId: getParam('id')? getParam('id') : course_id
xuzhenghua committed
215
        }
zhanghaozhe committed
216
        http.post(`${API.home}/m/bargain/receiveLimit`, data).then((res) => {
FE committed
217 218
            const { code, msg } = res.data;
            if (code === 200) {
xuzhenghua committed
219 220 221
                this.setState({
                    isShowOverlay: true,
                    status: 5,
FE committed
222 223
                });
                this.getBargainInfo();
FE committed
224 225
            }else if(code === 4030 || code === 4040) {
                history.push('/passport');
xuzhenghua committed
226
            } else {
FE committed
227
                Toast.info(msg, 2)
xuzhenghua committed
228 229 230 231 232 233
            }
        })
    }

    // 使用砍价神器
    useArtifact = () => {
FE committed
234 235 236
        const { course: { course_id = '' } } = this.state;
        const id = getParam('id')? getParam('id') : course_id;
        this.toKanjia(id, 2, 0);
xuzhenghua committed
237
    }
zhanghaozhe committed
238

xuzhenghua committed
239 240 241 242 243 244 245
    // 砍价接口
    toKanjia = (id, type, uid) => {
        let data = {
            course_id: id,
            type: type,  // 1 用户自己砍价 2 使用砍价神器 3 好友助力砍价 4 好友第二次助力
            parent_uid: uid // 被助力人id 【自己本人操作传0】
        }
zhanghaozhe committed
246
        http.post(`${API.home}/m/bargain/toBargain`, data).then((res) => {
xuzhenghua committed
247
            if (res.data.code === 200) {
248

xuzhenghua committed
249 250 251 252
                // is_success =0一切正常 =1 不能在砍了 =2关注公众号,可以再砍一刀!
                this.setState({
                    amount: res.data.data.amount
                })
xuzhenghua committed
253 254 255 256
                if (type === 2) {
                    this.setState({
                        isShowOverlay: true,
                        status: 6
257 258 259
                    });
                    this.getBargainInfo();
                    this.getBargainRankList('', 1);
xuzhenghua committed
260
                }
xuzhenghua committed
261 262

                if (res.data.data.is_success === 1) {
xuzhenghua committed
263 264
                    this.setState({
                        isShowOverlay: true,
xuzhenghua committed
265
                        status: 4
xuzhenghua committed
266
                    })
xuzhenghua committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
                } else if (res.data.data.is_success === 2) {
                    if (type === 3) {
                        this.setState({
                            isShowOverlay: true,
                            status: 2
                        })
                    } else if (type === 4) {
                        this.setState({
                            isShowOverlay: true,
                            status: 1,
                            firendBaigainPrice: false
                        })
                    }
                } else if (res.data.data.is_success === 0) {
                    if (type === 3) {
                        this.setState({
                            isShowOverlay: true,
                            status: 2
                        })
                    } else if (type === 4) {
                        this.setState({
                            isShowOverlay: true,
                            status: 3
                        })
                    }
xuzhenghua committed
292 293
                }

xuzhenghua committed
294
                this.getBargainInfo()
xuzhenghua committed
295
                this.getBargainRankList(getParam('id'), 1)
xuzhenghua committed
296 297


FE committed
298 299 300 301 302 303 304 305 306 307 308 309
            } else if (res.data.code == 4030 || res.data.code == 4040) {
                if (browser.isWeixin) {
                    let redirectURI = window.location.href
                    if (redirectURI.includes('code=') && redirectURI.includes('state=STATE')) {
                        let index = redirectURI.lastIndexOf('code=');
                        redirectURI = redirectURI.substr(0, index - 1);
                    }
                    window.location.assign(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=${encodeURIComponent(redirectURI)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`)
                } else {
                    this.props.history.push('/passport')
                }

xuzhenghua committed
310 311 312 313 314 315 316 317 318
            } else {
                Toast.info(res.data.msg, 2)
            }
        })
    }


    // 帮好友砍价第一刀
    friendBargainFirst = () => {
FE committed
319 320 321
        const { course: { course_id = '' } } = this.state;
        const id = getParam('id')? getParam('id') : course_id;
        this.toKanjia(id, 3, this.state.originatorUid);
xuzhenghua committed
322 323 324 325
    }

    // 帮好友砍价第二刀
    friendBargainSecond = () => {
FE committed
326 327 328
        const { course: { course_id = '' } } = this.state;
        const id = getParam('id')? getParam('id') : course_id;
        this.toKanjia(id, 4, this.state.originatorUid);
xuzhenghua committed
329 330
    }

xuzhenghua committed
331 332
    // 邀请好友砍价
    shareFriendBargain = () => {
FE committed
333
        const { history } = this.props;
FE committed
334
        history.push(`/bargain-middle-page?id=${getParam('id')}&bargaincode=${getParam('bargaincode')}&is_originator=1`);
xuzhenghua committed
335 336 337 338
        this.setState({
            isShowOverlay: true,
            status: 7,
            isshowYindao: browser.isWeixin ? true : false
FE committed
339
        });
FE committed
340 341 342 343 344 345 346

        wxShare({
            title: `我发现一门好课,快来帮我砍价吧!`,
            desc: `我已经砍了${this.state.bargainData.bargain_price}元,看看你能砍多少`,
            link: encodeURI(location.href),
            imgUrl: this.state.course.course_img,
        });
xuzhenghua committed
347
    }
xuzhenghua committed
348 349 350 351 352 353

    // 关闭弹窗
    close = () => {
        this.setState({
            isShowOverlay: false,
            status: '',
FE committed
354
        });
xuzhenghua committed
355 356
    }

357
    toCourseDetail = (id) => {
FE committed
358
        const {dispatch, history} = this.props;
359
        // dispatch(getCourses(id, () => {
FE committed
360 361
        history.push(`/detail?id=${id}`);
        return false;
362
        // }));
363 364
    }

zhanghaozhe committed
365
    render() {
FE committed
366
        // console.log(this.props);
xuzhenghua committed
367 368 369 370 371 372 373 374
        let thirdRow, btn
        // is_artifact	 0-再邀请多少人可以使用 1-可以使用未领取 2-已领取 3-已使用
        if (this.state.bargainData.is_artifact === 0) {
            thirdRow =
                <div>再邀请<span className={'indicator'}>{this.state.bargainData.invite_num}</span>位好友助力即可获得<span
                    className={'indicator'}>【砍价神器】</span></div>
        } else if (this.state.bargainData.is_artifact === 1) {
            thirdRow = <div>恭喜你获得<span className={'indicator'}>【砍价神器】</span></div>
xuzhenghua committed
375
            btn = <button className={'artifact-btn'} onClick={this.toArtifact}>立即领取</button>
xuzhenghua committed
376 377
        } else if (this.state.bargainData.is_artifact === 2) {
            thirdRow = <div>恭喜你获得<span className={'indicator'}>【砍价神器】</span></div>
xuzhenghua committed
378
            btn = <button className={'artifact-btn'} onClick={this.useArtifact}>立即使用</button>
xuzhenghua committed
379 380
        }

FE committed
381 382 383 384 385 386 387 388 389
        const { data: { is_originator = 0, assist_status = 0, bargain_status = 0 } } = this.state;
        let bargainBtn = '';
        // assist_status 助力状态 0-未助力,1-已助力一次 2-已助力两次,不能再助力
        // is_originator 是否发起人 0-否 1-是
        // bargain_status 砍价状态 0-砍价中,1砍价结束,待支付,2砍价过期(没有砍价记录没有砍价信息),3已购买
        if(is_originator) {
            if(bargain_status === 0) {
                bargainBtn = <button className='active-btn' onClick={this.shareFriendBargain}>邀请好友砍价</button>
            }
xuzhenghua committed
390 391 392
            else {
                bargainBtn = <button className={'invalid-btn'}>砍价结束</button>
            }
FE committed
393 394 395 396 397 398 399 400 401 402
        }else {
            if(assist_status === 0 && bargain_status === 0) {
                bargainBtn = <button className='active-btn' onClick={this.friendBargainFirst}>帮好友砍一刀</button>
            }else if (assist_status === 1 && bargain_status === 0) {
                bargainBtn = <button className='active-btn' onClick={this.friendBargainSecond}>再砍一刀</button>
            }else if (assist_status === 2 && bargain_status === 0) {
                bargainBtn = <button className={'invalid-btn'}>已帮好友助力</button>
            }else if (bargain_status !== 0) {
                bargainBtn = <button className={'invalid-btn'}>砍价结束</button>
            }
xuzhenghua committed
403
        }
FE committed
404 405 406 407 408 409 410 411 412 413 414 415

        // if (this.state.isOriginator !== 1 && this.state.data.assist_status === 0 && this.state.data.bargain_status === 0) {
        //     bargainBtn = <button className='active-btn' onClick={this.friendBargainFirst}>帮好友砍一刀</button>
        // } else if (this.state.isOriginator !== 1 && this.state.data.assist_status === 1) {
        //     bargainBtn = <button className='active-btn' onClick={this.friendBargainSecond}>再砍一刀1</button>
        // } else if (this.state.isOriginator !== 1 && this.state.data.assist_status === 2) {
        //     bargainBtn = <button className={'invalid-btn'}>已帮好友助力</button>
        // } else if (this.state.data.bargain_status === 1 || this.state.data.bargain_status === 2) {
        //     bargainBtn = <button className={'invalid-btn'}>砍价结束</button>
        // } else if (this.state.isOriginator === 1 && this.state.data.bargain_status === 0) {
        //     bargainBtn = <button className='active-btn' onClick={this.shareFriendBargain}>邀请好友砍价</button>
        // }
zhanghaozhe committed
416 417
        return (
            <div className={'bargain-middle-page'}>
FE committed
418
                <HeaderBar title='砍价详情' arrow={true} cart={true} toHref={'/'}></HeaderBar>
xuzhenghua committed
419
                {/*<Loading isLoading={this.state.isLoaidng}>*/}
zhanghaozhe committed
420 421
                <div className="top">
                    <div className="bargain-area">
xuzhenghua committed
422
                        {
xuzhenghua committed
423
                            this.state.isOriginator !== 1 &&
xuzhenghua committed
424 425 426
                            <p className='bargain-tip'>你的好友发现一门精品课程,快来一起帮他砍价:</p>
                        }

zhanghaozhe committed
427 428
                        <ul>
                            <VList
FE committed
429 430
                                img={this.state.course.course_img}
                                info={
FE committed
431 432 433 434
                                    <CourseDes
                                        isOriginator={this.state.isOriginator}
                                        data={this.state.data}
                                        toCart={this.toCart}/>
FE committed
435
                                }
zhanghaozhe committed
436 437 438
                            />
                        </ul>
                        <div className="bargain-detail">
xuzhenghua committed
439 440
                            {
                                (this.state.data.bargain_status == 0 || this.state.data.bargain_status == 1) &&
zhanghaozhe committed
441
                                <div>
xuzhenghua committed
442 443 444 445 446 447 448
                                    <div className="top">
                                        <div>
                                            已砍<span className={'reduced-price'}>{this.state.bargainData.bargain_price}</span>
                                        </div>
                                        {
                                            this.state.data.bargain_status === 0 &&
                                            <div>
xuzhenghua committed
449 450
                                        <span
                                            className={'time hour'}>{String(this.state.hour).padStart(2, 0)}</span> :&nbsp;
xuzhenghua committed
451 452 453 454 455 456 457 458 459 460
                                                <span
                                                    className={'time min'}>{String(this.state.min).padStart(2, 0)}</span> :&nbsp;
                                                <span className={'time sec'}>{String(this.state.sec).padStart(2, 0)}</span>
                                                <span className={'inactive'}> 后砍价结束</span>
                                            </div>
                                        }
                                        {
                                            this.state.data.bargain_status === 1 && this.state.isOriginator === 1 &&
                                            <span className={'inactive'}>砍价结束</span>
                                        }
xuzhenghua committed
461

xuzhenghua committed
462 463 464 465 466 467
                                    </div>
                                    <div className="middle">
                                        <span style={{width: this.state.width}}></span>
                                    </div>
                                </div>
                            }
xuzhenghua committed
468
                            {
xuzhenghua committed
469
                                this.state.isOriginator === 1 && this.state.data.bargain_status === 0 &&
xuzhenghua committed
470
                                <div>
xuzhenghua committed
471 472
                                    {thirdRow}
                                    {btn}
xuzhenghua committed
473 474
                                </div>
                            }
xuzhenghua committed
475 476

                            {
xuzhenghua committed
477
                                this.state.isOriginator === 1 && this.state.data.bargain_status === 1 &&
xuzhenghua committed
478 479
                                <div>
                                    砍价金额将于
xuzhenghua committed
480 481 482 483 484 485
                                    <span className={'time hour'}>{String(this.state.day).padStart(2, 0)}</span><span
                                    className={'unit'}>  </span>
                                    <span className={'time min'}>{String(this.state.hour).padStart(2, 0)}</span><span
                                    className={'unit'}>  </span>
                                    <span className={'time sec'}>{String(this.state.min).padStart(2, 0)}</span><span
                                    className={'unit'}></span>
xuzhenghua committed
486 487 488 489
                                    后清零,请尽快完成支付
                                </div>
                            }

zhanghaozhe committed
490
                            <div className={'button'}>
xuzhenghua committed
491
                                {bargainBtn}
zhanghaozhe committed
492
                            </div>
xuzhenghua committed
493

zhanghaozhe committed
494 495 496 497 498 499
                        </div>
                    </div>
                    <div className="bargain-records">
                        <div className="title">砍价记录</div>
                        <ul>
                            {
xuzhenghua committed
500
                                this.state.outList && this.state.outList.length > 0 && this.state.outList.map((item, index) => {
zhanghaozhe committed
501 502 503
                                    return (
                                        <li key={index}>
                                            <div className="left">
xuzhenghua committed
504 505
                                                <img className='avatar' src={item.avatar_file} alt=""/>
                                                <span className={'nickname'}>{item.user_name}</span>
zhanghaozhe committed
506 507 508
                                                <span className="rank-tag">{item.rank}</span>
                                            </div>
                                            <div className="right">
xuzhenghua committed
509 510
                                                <img className='kanjia-icon' src={this.state.kanjiaIcon} alt=""/>
                                                砍掉<span className={'price'}>{item.amount}</span>
zhanghaozhe committed
511 512 513 514 515 516 517 518
                                            </div>
                                        </li>
                                    )
                                })

                            }

                        </ul>
zhanghaozhe committed
519
                        <div className="more" onClick={this.getMore}>查看更多&gt;&gt;</div>
zhanghaozhe committed
520 521
                    </div>
                </div>
xuzhenghua committed
522
                <div className="bargain-course-list" id='bargainCourse'>
zhanghaozhe committed
523 524
                    <div className="title-wrapper">
                        <div className="title">我要砍价</div>
xuzhenghua committed
525
                        <div className="subtitle">邀请{this.state.limitPeople}位以上好友帮忙砍价可获得【砍价神器】</div>
zhanghaozhe committed
526 527 528
                    </div>
                    <ul>
                        {
xuzhenghua committed
529
                            this.state.courseList && this.state.courseList.length > 0 && this.state.courseList.map((item, index) => {
zhanghaozhe committed
530
                                return <Course
xuzhenghua committed
531
                                    className={'text-overflow-2'}
zhanghaozhe committed
532
                                    key={index}
xuzhenghua committed
533 534 535
                                    id={item.course_id}
                                    img={item.image_name}
                                    title={item.course_title}
536 537
                                    toDetail={this.toCourseDetail}
                                    bottom={
FE committed
538
                                        <CourseBottom
FE committed
539
                                            user={this.props.user}
FE committed
540 541 542 543
                                            item={item}
                                            toCartBottom={this.toCartBottom.bind(this, item.course_id)}
                                            toDetail={this.toCourseDetail}
                                        />
xuzhenghua committed
544
                                    }
zhanghaozhe committed
545 546 547 548 549
                                />
                            })
                        }
                    </ul>
                </div>
zhanghaozhe committed
550
                <Link to={'/classify'} className={'preferential'}>查看更多精品课程 &gt;&gt;</Link>
xuzhenghua committed
551 552 553


                {/*更多好友砍价*/}
xuzhenghua committed
554 555 556 557 558
                <Ranking list={this.state.list} icon={this.state.kanjiaIcon} limitPeople={this.state.limitPeople}
                         isShowMore={this.state.isShowMore} boxHide={this.boxHide}></Ranking>


                {
FE committed
559
                    this.state.isShowOverlay &&
xuzhenghua committed
560
                    <Overlay>
FE committed
561 562
                        <div className="bargain-popup__content">

xuzhenghua committed
563

xuzhenghua committed
564

xuzhenghua committed
565 566 567 568 569 570 571 572
                        {/*砍价成功去分享*/}
                        {
                            this.state.status === 7 &&
                            <BargainSuccess isshowYindao={this.state.isshowYindao} limitPeople={this.state.limitPeople}
                                            close={this.close}/>
                        }


xuzhenghua committed
573
                        {/*引导关注公众号*/}
FE committed
574
                        {/* {
xuzhenghua committed
575
                            this.state.status === 1 &&
xuzhenghua committed
576 577 578 579
                            <PublicNumber
                                money={this.state.amount}
                                avatar={this.props.user.data.avatar}
                                firendBaigainPrice={this.state.firendBaigainPrice}/>
FE committed
580 581 582
                        } */}
                        {
                            this.state.status === 1 &&
xuzhenghua committed
583
                            <FollowBarcode
FE committed
584 585 586 587
                                userInfo={this.props.user.data}
                                money={this.state.amount}
                                firendBaigainPrice={this.state.firendBaigainPrice}
                            />
xuzhenghua committed
588 589 590 591 592
                        }

                        {/*好友成功砍第一刀*/}
                        {
                            this.state.status === 2 &&
xuzhenghua committed
593 594 595 596
                            <BargainFirst
                                bargainSecond={this.friendBargainSecond}
                                money={this.state.amount}
                            />
xuzhenghua committed
597 598 599 600
                        }
                        {/*好友成功砍第二刀*/}
                        {
                            this.state.status === 3 &&
xuzhenghua committed
601
                            <BargainSecond close={this.close} money={this.state.amount}/>
xuzhenghua committed
602 603 604 605
                        }
                        {/*不能在砍了*/}
                        {
                            this.state.status === 4 &&
xuzhenghua committed
606
                            <NotBargain close={this.close} limitPeople={this.state.limitPeople}/>
xuzhenghua committed
607
                        }
xuzhenghua committed
608 609 610 611 612 613 614 615
                        {/*领取砍价神器*/}
                        {
                            this.state.status === 5 &&
                            <Artifact useArtifact={this.useArtifact}/>
                        }
                        {/*使用砍价神器*/}
                        {
                            this.state.status === 6 &&
xuzhenghua committed
616 617
                            <UseArtifact toCart={this.toCart} money={this.state.amount}
                                         allMoney={this.state.bargainData.bargain_price}/>
xuzhenghua committed
618
                        }
xuzhenghua committed
619 620

                        {
xuzhenghua committed
621
                            this.state.status !== 7 &&
FE committed
622
                            <i onClick={this.close} className={'iconfont iconiconfront-2 bargain-popup__button--close'}></i>
xuzhenghua committed
623
                        }
FE committed
624
                        </div>
xuzhenghua committed
625 626 627
                    </Overlay>

                }
xuzhenghua committed
628
                {/*</Loading>*/}
xuzhenghua committed
629

zhanghaozhe committed
630 631 632 633 634
            </div>
        );
    }
}

FE committed
635
// 课程信息 -- 右侧
xuzhenghua committed
636
function CourseDes(props) {
FE committed
637
    const { data: { bargain_status = 0, course = {}, is_originator = 0 }, toCart } = props;
zhanghaozhe committed
638 639
    return (
        <div className={'des'}>
xuzhenghua committed
640
            <div className="course-title text-overflow-2">
FE committed
641
                {course.course_title}
zhanghaozhe committed
642 643
            </div>
            <div className="price-bar">
FE committed
644 645
                <span className={'discount-price'}>{course.course_price}</span>
                {/* is_originator 是否发起人 0-否 1-是 */}
xuzhenghua committed
646
                {
xuzhenghua committed
647
                    (is_originator == 1 && bargain_status !=3) &&
FE committed
648 649
                    <button className={'purchase-btn'} onClick={toCart}>
                        ¥{course.pay_price}去支付
xuzhenghua committed
650 651
                    </button>
                }
FE committed
652
                {
xuzhenghua committed
653
                    (is_originator == 1 && bargain_status == 3) &&
FE committed
654 655
                    <span className="course-button__buy--done">已购买</span>
                }
zhanghaozhe committed
656 657
            </div>
        </div>
FE committed
658
    );
zhanghaozhe committed
659 660
}

xuzhenghua committed
661
function CourseBottom(props) {
xuzhenghua committed
662

663
    // bargain_status 砍价状态 0-砍价中,1砍价结束,待支付,2砍价过期(没有砍价记录没有砍价信息),3已购买
FE committed
664 665
    const {course_id = '', bargain_status = '', price1 = '', pay_price = '' } = props.item || {};
    const { user: { data = {} } } = props;
666
    const price = bargain_status === 2? price1 : pay_price;
zhanghaozhe committed
667
    let Buttons
FE committed
668 669 670
    if(data.uid) {
        if (props.item.bargain_status === 2) {
            // Buttons = <Link to={`/detail?id=${props.item.course_id}`} className={'bargain'}>我要砍价</Link>
671
            Buttons = (
FE committed
672 673 674
                <div className="">
                    <a onClick={() => props.toDetail(props.item.course_id)} className={'bargain bargian-study'}>我要砍价</a>
                </div>
xuzhenghua committed
675

FE committed
676 677 678 679
            )
        } else if (bargain_status === 3) {
            if(course_id === 139) {
                Buttons = (
xuzhenghua committed
680 681
                    <a
                        onClick={() => props.toDetail(props.item.course_id)}
FE committed
682 683 684 685 686
                        className={'bargain bargian-study'}
                    >我要砍价</a>
                );
            }else {
                Buttons = (
xuzhenghua committed
687
                    <Link
FE committed
688 689 690 691 692 693
                        to={`/play/video?id=${props.item.v_course_id}`}
                        className={classnames('bargain', 'button--study')}
                    >去学习</Link>
                );
            }
        } else {
694
            Buttons = (
FE committed
695 696 697 698 699 700 701 702 703 704 705 706
                <div className="btns">
                    {/*<button className={classnames('bargain-btn', {invalid: props.item.bargain_status === 2})}>*/}
                    {/*{props.item.bargain_status === 2 ? '砍价结束' : '继续砍价'}*/}
                    {/*</button>*/}
                    {
                        bargain_status === 1 &&
                        <button className='invalid'>砍价结束</button>
                    }
                    {
                        bargain_status === 0 &&
                        <a onClick={() => props.toDetail(props.item.course_id)} className={'bargain-btn'}>继续砍价</a>
                    }
xuzhenghua committed
707
                    <button
FE committed
708 709 710 711 712 713 714
                        onClick={() => props.toCartBottom(props.item.course_id)}
                        className={'purchase-btn'}
                    >
                        ¥{price}去支付
                    </button>
                </div>
            )
715
        }
xuzhenghua committed
716

FE committed
717
    }else {
zhanghaozhe committed
718
        Buttons = (
xuzhenghua committed
719 720
            <a
                onClick={() => props.toDetail(props.item.course_id)}
FE committed
721 722 723
                className={'bargain bargian-study'}
            >我要砍价</a>
        );
zhanghaozhe committed
724
    }
xuzhenghua committed
725

zhanghaozhe committed
726 727 728
    return (
        <div className="course-bottom">
            <div className={'course-price'}>
xuzhenghua committed
729 730
                <span className={'discount-price'}>¥{props.item.price1}</span>
                <span className={'original-price'}>¥{props.item.price0}</span>
zhanghaozhe committed
731 732 733 734 735 736
            </div>
            {Buttons}
        </div>
    )
}

xuzhenghua committed
737

xuzhenghua committed
738
function PublicNumber(props) {
xuzhenghua committed
739 740
    return (
        <div className='bargain-public-number'>
FE committed
741
            <img className='avait' src={props.avatar} alt="" />
xuzhenghua committed
742 743 744 745
            {
                props.firendBaigainPrice &&
                <p className='status-title ff4'>谢谢你帮我砍了{props.money}元!</p>
            }
xuzhenghua committed
746
            <p className='status-dec'>关注公众号,可以再砍一刀哦~</p>
xuzhenghua committed
747
            <img
FE committed
748
                className='public-number-img'
xuzhenghua committed
749
                src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/tinypng-common/right_weixin.png"
FE committed
750 751
                alt=""
            />
xuzhenghua committed
752 753 754 755
        </div>
    )
}

xuzhenghua committed
756
function BargainFirst(props) {
xuzhenghua committed
757 758 759
    return (
        <div className='bargain-first'>
            <img className='top-img' src={require('./image/kanjia_cg_icon.png')} alt=""/>
xuzhenghua committed
760
            <p className='status-title'>谢谢你帮我砍了<span className='ff4'>{props.money}</span>!</p>
xuzhenghua committed
761
            <p className='status-dec'>你还可以帮我再砍一刀哦~</p>
xuzhenghua committed
762
            <button className='bargain-href' onClick={props.bargainSecond}>再砍一刀</button>
xuzhenghua committed
763 764 765 766
        </div>
    )
}

xuzhenghua committed
767
function BargainSecond(props) {
xuzhenghua committed
768 769 770
    return (
        <div className='bargain-second'>
            <img className='top-img' src={require('./image/kanjia_cg_icon.png')} alt=""/>
xuzhenghua committed
771
            <p className='status-title'>厉害了,又帮好友砍掉<span className='ff4'>{props.money}</span>!</p>
FE committed
772
            <a className='bargain-href' href='#bargainCourse' onClick={props.close}>我也要砍价</a>
xuzhenghua committed
773 774 775 776
        </div>
    )
}

xuzhenghua committed
777
function NotBargain(props) {
xuzhenghua committed
778 779 780 781
    return (
        <div className='not-bargain'>
            <img className='middle-img' src={require('./image/kanjia_no_iccon.png')} alt=""/>
            <p className='status-title'>你的好友用【砍价神器】把我砍蒙圈了<br/>不能再砍了哦~</p>
xuzhenghua committed
782
            <p className='status-dec'>邀请{props.limitPeople}位以上好友帮忙砍价可获得【砍价神器】</p>
FE committed
783
            <a className='bargain-href' href='#bargainCourse' onClick={props.close}>我也要砍价</a>
xuzhenghua committed
784 785 786 787
        </div>
    )
}

xuzhenghua committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
function Artifact(props) {
    return (
        <div className='artifact-box'>
            <p className='top-tip'>恭喜你获得【砍价神器】!</p>
            <p className='middle-tip'>
                您可以使用
                <span className={'indicator'}>【砍价神器】</span>
                再砍一刀
            </p>
            <button className='use-artifact' onClick={props.useArtifact}>立即使用</button>
        </div>
    )
}

function UseArtifact(props) {
    return (
        <div className='use-artifact-box'>
            <img className='top-img' src={require('./image/kanjia_cg_icon.png')} alt=""/>
xuzhenghua committed
806
            <p className='top-tip'>厉害了,又砍掉了{props.money}元!</p>
xuzhenghua committed
807 808
            <p className='middle-tip'>
                你已经砍了
xuzhenghua committed
809
                <span className={'indicator'}>{props.allMoney}</span>
xuzhenghua committed
810 811 812 813 814 815 816 817 818 819 820
                没见过你这么能砍的人...
            </p>
            <p className='btm-tip'>
                不能再砍了哦~
            </p>
            <button className='tubuy' onClick={props.toCart}>去支付</button>
        </div>
    )
}


xuzhenghua committed
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
function BargainSuccess(props) {
    return (
        <div>
            <div className='close-bargain-success' onClick={props.close}></div>

            <div className="bargain-success">
                {
                    props.isshowYindao &&
                    <i className='iconfont iconyindao'></i>
                }
                <p>分享到微信群邀请更多好友帮忙砍价</p>
                <p>超过{props.limitPeople}位好友助力可获得<span className={'indicator'} style={{color: '#FF4000'}}>【砍价神器】</span>
                </p>
            </div>
        </div>
    )
}


840
export default withRouter(BargainMiddlePage);