index.js 29.9 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable jsx-a11y/anchor-is-valid */
zhanghaozhe committed
2 3 4 5
import React, { Component } from "react"
import "./bargain-middle-page.scss"
import { HeaderBar, VList } from "src/common"
import { Course } from "src/common"
zhanghaozhe committed
6
import { getParam, http, browser, wxShare } from "src/utils"
zhanghaozhe committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { Toast } from "antd-mobile"
import { Link, withRouter } from "react-router-dom"
import Ranking from "./ranking"
import {
  differenceInSeconds,
  differenceInMinutes,
  differenceInHours,
  differenceInDays,
} from "date-fns"
import Overlay from "../detail/overlay"
import { connect } from "react-redux"
import classnames from "classnames"
import FollowBarcode from "./barcode/index"

@connect((state) => ({
  user: state.user,
23
}))
xuzhenghua committed
24
class BargainMiddlePage extends Component {
zhanghaozhe committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  timer

  constructor(props) {
    super(props)
    this.state = {
      isShowOverlay: false,
      isOriginator: "",
      kanjiaIcon: require("./image/kanjia_icon.png"),
      course: {}, // 当前砍价课程
      courseList: [], // 所有砍价课程
      data: "",
      bargainData: "",
      limitPeople: 0,
      outList: [],
      list: [],
      width: "0",
      isShowMore: "",
      status: "",
      hour: "",
      min: "",
      sec: "",
      day: "",
      amount: "", // 每次砍掉的价格
      firendBaigainPrice: true,
      isshowYindao: false,
      isLoaidng: true,
      imglink:
        "https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/",
xuzhenghua committed
53
    }
zhanghaozhe committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  }

  componentDidMount() {
    this.getBargainRankList(getParam("id"), 1)
    this.getBargainCourse()
    this.getBargainInfo()
  }

  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
    }
zhanghaozhe committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  }

  // 获取砍价信息
  getBargainInfo = () => {
    // is_originator 来源,0-PC端扫码 1-M端分享 2-APP端分享
    http
      .get(
        `${API.home}/m/bargain/info?bargaincode=${getParam(
          "bargaincode"
        )}&is_originator=${getParam("is_originator")}`
      )
      .then((res) => {
        if (res.data.code === 200) {
          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 +
                "%",
            },
            () => {
              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,
                  })
                }, 1000)
              }
xuzhenghua committed
119
            }
zhanghaozhe committed
120 121 122
          )
        } else {
          Toast.info(res.data.msg, 2)
xuzhenghua committed
123
        }
zhanghaozhe committed
124 125
      })
  }
xuzhenghua committed
126

zhanghaozhe committed
127 128 129 130 131 132
  // 获取砍价课程
  getBargainCourse = () => {
    http.get(`${API.home}/m/bargain/courseList`).then((res) => {
      if (res.data.code === 200) {
        this.setState({
          courseList: res.data.data,
xuzhenghua committed
133
        })
zhanghaozhe committed
134 135 136 137 138 139 140 141 142 143 144 145 146
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }

  // 获取助理好友
  getBargainRankList = (id = "", type) => {
    const bargain_code = getParam("bargaincode") || ""
    let data = {
      courseId: id,
      type: type,
      bargain_code,
xuzhenghua committed
147
    }
zhanghaozhe committed
148 149 150 151 152 153 154 155
    http.post(`${API.home}/m/bargain/rankList`, data).then((res) => {
      if (res.data.code === 200) {
        let arr = ["刀神", "刀王", "刀霸"]
        let newList = res.data.data.out_list.map((item, i) => {
          return {
            ...item,
            rank: arr[i],
          }
xuzhenghua committed
156
        })
xuzhenghua committed
157
        this.setState({
zhanghaozhe committed
158 159
          list: res.data.data.list,
          outList: newList,
xuzhenghua committed
160
        })
zhanghaozhe committed
161
      } else if (res.data.code === 4030 || res.data.code === 4040) {
zhanghaozhe committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }

  // 直接支付
  toCart = () => {
    const { history } = this.props
    http
      .get(`${API["base-api"]}/m/cart/addtopreorder/[${getParam("id")}]`)
      .then((res) => {
        const { errno, msg } = res.data
        if (errno === 0) {
          this.props.history.push(`/order?id=[${getParam("id")}]`, {
            bargain: 1,
          })
        } else if (errno === 4030 || errno === 4040) {
          history.push("/passport")
        } else {
          Toast.info(msg, 2)
xuzhenghua committed
183
        }
zhanghaozhe committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
      })
    // 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);
    //     }
    // })
  }

  // 我要砍价列表的去支付
  toCartBottom = (id) => {
    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
203
        })
zhanghaozhe committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
    // 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);
    //     }
    // })
  }

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

  // 自组件传给父组件的boxHide
  boxHide = (val) => {
    this.setState({ isShowMore: val })
  }

  // 领取砍价神器
  toArtifact = () => {
    const { history } = this.props
    const {
      course: { course_id = "" },
    } = this.state
    let data = {
      courseId: getParam("id") ? getParam("id") : course_id,
xuzhenghua committed
237
    }
zhanghaozhe committed
238 239 240 241 242 243
    http.post(`${API.home}/m/bargain/receiveLimit`, data).then((res) => {
      const { code, msg } = res.data
      if (code === 200) {
        this.setState({
          isShowOverlay: true,
          status: 5,
xuzhenghua committed
244
        })
zhanghaozhe committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        this.getBargainInfo()
      } else if (code === 4030 || code === 4040) {
        history.push("/passport")
      } else {
        Toast.info(msg, 2)
      }
    })
  }

  // 使用砍价神器
  useArtifact = () => {
    const {
      course: { course_id = "" },
    } = this.state
    const id = getParam("id") ? getParam("id") : course_id
    this.toKanjia(id, 2, 0)
  }

  // 砍价接口
  toKanjia = (id, type, uid) => {
    let data = {
      course_id: id,
      type: type, // 1 用户自己砍价 2 使用砍价神器 3 好友助力砍价 4 好友第二次助力
      parent_uid: uid, // 被助力人id 【自己本人操作传0】
xuzhenghua committed
269
    }
zhanghaozhe committed
270 271 272
    http.post(`${API.home}/m/bargain/toBargain`, data).then((res) => {
      if (res.data.code === 200) {
        // is_success =0一切正常 =1 不能在砍了 =2关注公众号,可以再砍一刀!
xuzhenghua committed
273
        this.setState({
zhanghaozhe committed
274 275 276 277
          amount: res.data.data.amount,
        })
        if (type === 2) {
          this.setState({
xuzhenghua committed
278
            isShowOverlay: true,
zhanghaozhe committed
279 280 281 282 283
            status: 6,
          })
          this.getBargainInfo()
          this.getBargainRankList("", 1)
        }
284

zhanghaozhe committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        if (res.data.data.is_success === 1) {
          this.setState({
            isShowOverlay: true,
            status: 4,
          })
        } 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
315 316
        }

zhanghaozhe committed
317 318
        this.getBargainInfo()
        this.getBargainRankList(getParam("id"), 1)
zhanghaozhe committed
319
      } else if (res.data.code === 4030 || res.data.code === 4040) {
zhanghaozhe committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
        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
336
        }
zhanghaozhe committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }

  // 帮好友砍价第一刀
  friendBargainFirst = () => {
    const {
      course: { course_id = "" },
    } = this.state
    const id = getParam("id") ? getParam("id") : course_id
    this.toKanjia(id, 3, this.state.originatorUid)
  }

  // 帮好友砍价第二刀
  friendBargainSecond = () => {
    const {
      course: { course_id = "" },
    } = this.state
    const id = getParam("id") ? getParam("id") : course_id
    this.toKanjia(id, 4, this.state.originatorUid)
  }

  // 邀请好友砍价
  shareFriendBargain = () => {
    const { history } = this.props
    history.push(
      `/bargain-middle-page?id=${getParam("id")}&bargaincode=${getParam(
        "bargaincode"
      )}&is_originator=1`
    )
    this.setState({
      isShowOverlay: true,
      status: 7,
      isshowYindao: browser.isWeixin ? true : false,
    })

    wxShare({
      title: `我发现一门好课,快来帮我砍价吧!`,
      desc: `我已经砍了${this.state.bargainData.bargain_price}元,看看你能砍多少`,
zhanghaozhe committed
378
      link: encodeURI(window.location.href),
zhanghaozhe committed
379 380 381 382 383 384 385 386 387 388 389 390 391
      imgUrl: this.state.course.course_img,
    })
  }

  // 关闭弹窗
  close = () => {
    this.setState({
      isShowOverlay: false,
      status: "",
    })
  }

  toCourseDetail = (id) => {
zhanghaozhe committed
392
    const { history } = this.props
zhanghaozhe committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    history.push(`/detail?id=${id}`)
    return false
  }

  render() {
    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>
      )
      btn = (
        <button className={"artifact-btn"} onClick={this.toArtifact}>
          立即领取
        </button>
      )
    } else if (this.state.bargainData.is_artifact === 2) {
      thirdRow = (
        <div>
          恭喜你获得<span className={"indicator"}>【砍价神器】</span>
        </div>
      )
      btn = (
        <button className={"artifact-btn"} onClick={this.useArtifact}>
          立即使用
        </button>
      )
    }
FE committed
433

zhanghaozhe committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    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>
        )
      } else {
        bargainBtn = <button className={"invalid-btn"}>砍价结束</button>
      }
    } 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>
      }
    }

    // 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>
    // }
    return (
      <div className={"bargain-middle-page"}>
        <HeaderBar
          title="砍价详情"
          arrow={true}
          cart={true}
          toHref={"/"}
        ></HeaderBar>
        {/*<Loading isLoading={this.state.isLoaidng}>*/}
        <div className="top">
          <div className="bargain-area">
            {this.state.isOriginator !== 1 && (
              <p className="bargain-tip">
                你的好友发现一门精品课程,快来一起帮他砍价:
              </p>
            )}

            <ul>
              <VList
                img={this.state.course.course_img}
                info={
                  <CourseDes
                    isOriginator={this.state.isOriginator}
                    data={this.state.data}
                    toCart={this.toCart}
                  />
                }
              />
            </ul>
            <div className="bargain-detail">
zhanghaozhe committed
512 513
              {(Number(this.state.data.bargain_status) === 0 ||
                Number(this.state.data.bargain_status) === 1) && (
zhanghaozhe committed
514 515 516 517 518 519 520
                <div>
                  <div className="top">
                    <div>
                      已砍
                      <span className={"reduced-price"}>
                        {this.state.bargainData.bargain_price}
                      </span>
zhanghaozhe committed
521
                    </div>
zhanghaozhe committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
                    {this.state.data.bargain_status === 0 && (
                      <div>
                        <span className={"time hour"}>
                          {String(this.state.hour).padStart(2, 0)}
                        </span>{" "}
                        :&nbsp;
                        <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>
                      )}
                  </div>
                  <div className="middle">
                    <span style={{ width: this.state.width }}></span>
                  </div>
zhanghaozhe committed
546
                </div>
zhanghaozhe committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
              )}
              {this.state.isOriginator === 1 &&
                this.state.data.bargain_status === 0 && (
                  <div>
                    {thirdRow}
                    {btn}
                  </div>
                )}

              {this.state.isOriginator === 1 &&
                this.state.data.bargain_status === 1 && (
                  <div>
                    砍价金额将于
                    <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>
                    后清零,请尽快完成支付
                  </div>
                )}

              <div className={"button"}>{bargainBtn}</div>
            </div>
          </div>
          <div className="bargain-records">
            <div className="title">砍价记录</div>
            <ul>
              {this.state.outList &&
                this.state.outList.length > 0 &&
                this.state.outList.map((item, index) => {
                  return (
                    <li key={index}>
                      <div className="left">
                        <img className="avatar" src={item.avatar_file} alt="" />
                        <span className={"nickname"}>{item.user_name}</span>
                        <span className="rank-tag">{item.rank}</span>
                      </div>
                      <div className="right">
                        <img
                          className="kanjia-icon"
                          src={this.state.kanjiaIcon}
                          alt=""
                        />
                        砍掉<span className={"price"}>{item.amount}</span>
                      </div>
                    </li>
                  )
                })}
            </ul>
            <div className="more" onClick={this.getMore}>
              查看更多&gt;&gt;
            </div>
          </div>
        </div>
        <div className="bargain-course-list" id="bargainCourse">
          <div className="title-wrapper">
            <div className="title">我要砍价</div>
            <div className="subtitle">
              邀请{this.state.limitPeople}位以上好友帮忙砍价可获得【砍价神器】
            </div>
          </div>
          <ul>
            {this.state.courseList &&
              this.state.courseList.length > 0 &&
              this.state.courseList.map((item, index) => {
                return (
                  <Course
                    className={"text-overflow-2"}
                    key={index}
                    id={item.course_id}
                    img={item.image_name}
                    title={item.course_title}
                    toDetail={this.toCourseDetail}
                    bottom={
                      <CourseBottom
                        user={this.props.user}
                        item={item}
                        toCartBottom={this.toCartBottom.bind(
                          this,
                          item.course_id
                        )}
                        toDetail={this.toCourseDetail}
                      />
                    }
                  />
                )
              })}
          </ul>
        </div>
        <Link to={"/classify"} className={"preferential"}>
          查看更多精品课程 &gt;&gt;
        </Link>

        {/*更多好友砍价*/}
        <Ranking
          list={this.state.list}
          icon={this.state.kanjiaIcon}
          limitPeople={this.state.limitPeople}
          isShowMore={this.state.isShowMore}
          boxHide={this.boxHide}
        ></Ranking>

        {this.state.isShowOverlay && (
          <Overlay>
            <div className="bargain-popup__content">
              {/*砍价成功去分享*/}
              {this.state.status === 7 && (
                <BargainSuccess
                  isshowYindao={this.state.isshowYindao}
                  limitPeople={this.state.limitPeople}
                  close={this.close}
                />
              )}

              {/*引导关注公众号*/}
              {/* {
xuzhenghua committed
671
                            this.state.status === 1 &&
xuzhenghua committed
672 673 674 675
                            <PublicNumber
                                money={this.state.amount}
                                avatar={this.props.user.data.avatar}
                                firendBaigainPrice={this.state.firendBaigainPrice}/>
FE committed
676
                        } */}
zhanghaozhe committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
              {this.state.status === 1 && (
                <FollowBarcode
                  userInfo={this.props.user.data}
                  money={this.state.amount}
                  firendBaigainPrice={this.state.firendBaigainPrice}
                />
              )}

              {/*好友成功砍第一刀*/}
              {this.state.status === 2 && (
                <BargainFirst
                  bargainSecond={this.friendBargainSecond}
                  money={this.state.amount}
                />
              )}
              {/*好友成功砍第二刀*/}
              {this.state.status === 3 && (
                <BargainSecond close={this.close} money={this.state.amount} />
              )}
              {/*不能在砍了*/}
              {this.state.status === 4 && (
                <NotBargain
                  close={this.close}
                  limitPeople={this.state.limitPeople}
                />
              )}
              {/*领取砍价神器*/}
              {this.state.status === 5 && (
                <Artifact useArtifact={this.useArtifact} />
              )}
              {/*使用砍价神器*/}
              {this.state.status === 6 && (
                <UseArtifact
                  toCart={this.toCart}
                  money={this.state.amount}
                  allMoney={this.state.bargainData.bargain_price}
                />
              )}

              {this.state.status !== 7 && (
                <i
                  onClick={this.close}
                  className={
                    "iconfont iconiconfront-2 bargain-popup__button--close"
                  }
                ></i>
              )}
zhanghaozhe committed
724
            </div>
zhanghaozhe committed
725 726 727 728 729 730
          </Overlay>
        )}
        {/*</Loading>*/}
      </div>
    )
  }
zhanghaozhe committed
731 732
}

FE committed
733
// 课程信息 -- 右侧
xuzhenghua committed
734
function CourseDes(props) {
zhanghaozhe committed
735 736 737 738 739 740 741 742 743 744
  const {
    data: { bargain_status = 0, course = {}, is_originator = 0 },
    toCart,
  } = props
  return (
    <div className={"des"}>
      <div className="course-title text-overflow-2">{course.course_title}</div>
      <div className="price-bar">
        <span className={"discount-price"}>{course.course_price}</span>
        {/* is_originator 是否发起人 0-否 1-是 */}
zhanghaozhe committed
745
        {Number(is_originator) === 1 && Number(bargain_status) !== 3 && (
zhanghaozhe committed
746 747 748 749
          <button className={"purchase-btn"} onClick={toCart}>
            ¥{course.pay_price}去支付
          </button>
        )}
zhanghaozhe committed
750
        {Number(is_originator) === 1 && Number(bargain_status) === 3 && (
zhanghaozhe committed
751 752 753 754 755
          <span className="course-button__buy--done">已购买</span>
        )}
      </div>
    </div>
  )
zhanghaozhe committed
756 757
}

xuzhenghua committed
758
function CourseBottom(props) {
zhanghaozhe committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
  // bargain_status 砍价状态 0-砍价中,1砍价结束,待支付,2砍价过期(没有砍价记录没有砍价信息),3已购买
  const { course_id = "", bargain_status = "", price1 = "", pay_price = "" } =
    props.item || {}
  const {
    user: { data = {} },
  } = props
  const price = bargain_status === 2 ? price1 : pay_price
  let Buttons
  if (data.uid) {
    if (props.item.bargain_status === 2) {
      // Buttons = <Link to={`/detail?id=${props.item.course_id}`} className={'bargain'}>我要砍价</Link>
      Buttons = (
        <div className="">
          <a
            onClick={() => props.toDetail(props.item.course_id)}
            className={"bargain bargian-study"}
          >
            我要砍价
          </a>
        </div>
      )
    } else if (bargain_status === 3) {
      if (course_id === 139) {
zhanghaozhe committed
782
        Buttons = (
zhanghaozhe committed
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
          <a
            onClick={() => props.toDetail(props.item.course_id)}
            className={"bargain bargian-study"}
          >
            我要砍价
          </a>
        )
      } else {
        Buttons = (
          <Link
            to={`/play/video?id=${props.item.v_course_id}`}
            className={classnames("bargain", "button--study")}
          >
            去学习
          </Link>
        )
      }
    } else {
      Buttons = (
        <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 && (
xuzhenghua committed
810
            <a
zhanghaozhe committed
811 812 813 814 815 816 817 818 819 820 821 822
              onClick={() => props.toDetail(props.item.course_id)}
              className={"bargain-btn"}
            >
              继续砍价
            </a>
          )}
          <button
            onClick={() => props.toCartBottom(props.item.course_id)}
            className={"purchase-btn"}
          >
            ¥{price}去支付
          </button>
zhanghaozhe committed
823
        </div>
zhanghaozhe committed
824 825 826 827 828 829 830 831 832 833
      )
    }
  } else {
    Buttons = (
      <a
        onClick={() => props.toDetail(props.item.course_id)}
        className={"bargain bargian-study"}
      >
        我要砍价
      </a>
zhanghaozhe committed
834
    )
zhanghaozhe committed
835 836 837 838 839 840 841 842 843 844 845
  }

  return (
    <div className="course-bottom">
      <div className={"course-price"}>
        <span className={"discount-price"}>¥{props.item.price1}</span>
        <span className={"original-price"}>¥{props.item.price0}</span>
      </div>
      {Buttons}
    </div>
  )
zhanghaozhe committed
846 847
}

xuzhenghua committed
848
function BargainFirst(props) {
zhanghaozhe committed
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
  return (
    <div className="bargain-first">
      <img
        className="top-img"
        src={require("./image/kanjia_cg_icon.png")}
        alt=""
      />
      <p className="status-title">
        谢谢你帮我砍了<span className="ff4">{props.money}</span>
      </p>
      <p className="status-dec">你还可以帮我再砍一刀哦~</p>
      <button className="bargain-href" onClick={props.bargainSecond}>
        再砍一刀
      </button>
    </div>
  )
xuzhenghua committed
865 866
}

xuzhenghua committed
867
function BargainSecond(props) {
zhanghaozhe committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
  return (
    <div className="bargain-second">
      <img
        className="top-img"
        src={require("./image/kanjia_cg_icon.png")}
        alt=""
      />
      <p className="status-title">
        厉害了,又帮好友砍掉<span className="ff4">{props.money}</span>
      </p>
      <a className="bargain-href" href="#bargainCourse" onClick={props.close}>
        我也要砍价
      </a>
    </div>
  )
xuzhenghua committed
883 884
}

xuzhenghua committed
885
function NotBargain(props) {
zhanghaozhe committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
  return (
    <div className="not-bargain">
      <img
        className="middle-img"
        src={require("./image/kanjia_no_iccon.png")}
        alt=""
      />
      <p className="status-title">
        你的好友用【砍价神器】把我砍蒙圈了
        <br />
        不能再砍了哦~
      </p>
      <p className="status-dec">
        邀请{props.limitPeople}位以上好友帮忙砍价可获得【砍价神器】
      </p>
      <a className="bargain-href" href="#bargainCourse" onClick={props.close}>
        我也要砍价
      </a>
    </div>
  )
xuzhenghua committed
906 907
}

xuzhenghua committed
908
function Artifact(props) {
zhanghaozhe committed
909 910 911 912 913 914 915 916 917 918 919 920 921
  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>
  )
xuzhenghua committed
922 923 924
}

function UseArtifact(props) {
zhanghaozhe committed
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
  return (
    <div className="use-artifact-box">
      <img
        className="top-img"
        src={require("./image/kanjia_cg_icon.png")}
        alt=""
      />
      <p className="top-tip">厉害了,又砍掉了{props.money}元!</p>
      <p className="middle-tip">
        你已经砍了
        <span className={"indicator"}>{props.allMoney}</span>
        没见过你这么能砍的人...
      </p>
      <p className="btm-tip">不能再砍了哦~</p>
      <button className="tubuy" onClick={props.toCart}>
        去支付
      </button>
    </div>
  )
xuzhenghua committed
944 945
}

xuzhenghua committed
946
function BargainSuccess(props) {
zhanghaozhe committed
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
  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>
  )
xuzhenghua committed
964 965
}

zhanghaozhe committed
966
export default withRouter(BargainMiddlePage)