index.js 8.93 KB
Newer Older
zhanghaozhe committed
1
/* eslint-disable eqeqeq */
zhanghaozhe committed
2 3
import React, { Component } from "react"
import "./index.scss"
zhanghaozhe committed
4
import { getParam } from "src/utils"
zhanghaozhe committed
5
import { Flex } from "antd-mobile"
xuzhenghua committed
6 7

class Group extends Component {
zhanghaozhe committed
8 9 10 11 12 13 14 15 16 17
  constructor(props) {
    super(props)
    this.state = {
      isShowMore: false,
      alreadyIn: false,
      pdd_price: 0,
      number: 0,
      data: {},
      countdown: props.countdown,
      now_groupon_list: [],
xuzhenghua committed
18
    }
zhanghaozhe committed
19
  }
xuzhenghua committed
20

zhanghaozhe committed
21 22 23 24 25 26
  // 查看更多
  getMore = () => {
    this.setState({
      isShowMore: true,
    })
  }
xuzhenghua committed
27

zhanghaozhe committed
28 29 30 31 32 33
  // 关闭更多窗口
  closeMore = () => {
    this.setState({
      isShowMore: false,
    })
  }
xuzhenghua committed
34

zhanghaozhe committed
35 36 37 38 39 40 41 42 43 44 45 46
  toPay = (pdd_order_id) => {
    const { courseInfo, history } = this.props
    if (courseInfo.group_status === 3) {
      history.push(`/order?id=${getParam("id")}`, {
        group: 1,
        pdd_order_id,
      })
    } else {
      this.setState({
        isShowMore: false,
        alreadyIn: true,
      })
47
    }
zhanghaozhe committed
48
  }
49

zhanghaozhe committed
50 51 52 53 54 55 56
  invitedFriends = () => {
    this.setState({
      isShowMore: false,
      alreadyIn: false,
    })
    this.props.invitedFriends()
  }
wangshuo committed
57

zhanghaozhe committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  componentWillReceiveProps(nextProps) {
    if (
      nextProps.courseInfo &&
      nextProps.courseInfo.courseInfo &&
      nextProps.courseInfo.courseInfo.course_info &&
      nextProps.courseInfo.courseInfo.course_info.pdd_group_info
    ) {
      let now_groupon_list =
        nextProps.courseInfo.courseInfo.course_info.pdd_group_info
          .now_groupon_list
      if (now_groupon_list && now_groupon_list.length > 0) {
        now_groupon_list.map((item) => {
          item.end_time -= 1
          return item
        })
wangshuo committed
73
        this.setState({
zhanghaozhe committed
74
          now_groupon_list,
wangshuo committed
75
        })
zhanghaozhe committed
76
      }
wangshuo committed
77
    }
zhanghaozhe committed
78 79 80 81
    this.setState({
      countdown: nextProps.countdown,
    })
  }
wangshuo committed
82

zhanghaozhe committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  componentDidMount() {
    const { courseInfo = {} } = this.props
    if (courseInfo.pdd_group_info) {
      let now_groupon_list = courseInfo.pdd_group_info.now_groupon_list
      if (now_groupon_list && now_groupon_list.length > 0) {
        setInterval(() => {
          now_groupon_list.map((item) => {
            item.end_time -= 1
            return item
          })
          this.setState({
            now_groupon_list,
          })
        }, 1000)
      }
wangshuo committed
98
    }
zhanghaozhe committed
99
  }
wangshuo committed
100

zhanghaozhe committed
101 102 103 104 105
  hideMbc = () => {
    this.setState({
      alreadyIn: false,
    })
  }
xuzhenghua committed
106

zhanghaozhe committed
107 108 109 110 111 112 113
  formatTimeByMillisecond = (millisecond) => {
    let date = millisecond * 1000,
      day = 0,
      hours = 0,
      minutes = 0,
      seconds = 0
    date -= 1000
xuzhenghua committed
114

zhanghaozhe committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    if (millisecond > 86400) {
      day = `${parseInt(date / (3600000 * 24))}`.padStart(2, 0)
      hours = `${parseInt((date - day * 3600000 * 24) / 3600000)}`.padStart(
        2,
        0
      )
      minutes = `${parseInt(
        (date - day * 3600000 * 24 - hours * 3600000) / 60000
      )}`.padStart(2, 0)
      return `${day}${hours}${minutes}分`
    } else {
      hours = `${parseInt(date / (60 * 60 * 1000))}`.padStart(2, 0)
      minutes = `${parseInt((date - hours * 3600000) / 60000)}`.padStart(2, 0)
      seconds = `${parseInt(
        (date - hours * 3600000 - minutes * 60000) / 1000
      )}`.padStart(2, 0)
      return `${hours}:${minutes}:${seconds}`
wangshuo committed
132
    }
zhanghaozhe committed
133
  }
wangshuo committed
134

zhanghaozhe committed
135 136
  render() {
    const { courseInfo } = this.props
zhanghaozhe committed
137
    const { alreadyIn, countdown } = this.state
zhanghaozhe committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    let groupInfo = "",
      groupon_member = "",
      group_status = -1,
      groupSuccessMbc = null
    if (courseInfo) {
      groupInfo = courseInfo.pdd_group_info
      groupon_member = groupInfo.groupon_member
      group_status = courseInfo.group_status
    }
    if (group_status === 4) {
      if (groupon_member.member) {
        const { number } = groupon_member
        let ary = [],
          num = number
        while (num != 0) {
          ary.push(num)
          num--
155
        }
zhanghaozhe committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        let groupTip = (
          <div className="group-user-list">
            <Flex justify="center" className="imgList">
              {groupon_member.member.map((item) => {
                return (
                  <div className="imgContainer" key={Math.random()}>
                    <img className="imgname" src={item.avatar} alt="" />
                    {item.user_type === 1 ? (
                      <div className="leaderFlag">
                        <span>团长</span>
                      </div>
                    ) : null}
                  </div>
                )
              })}
              {ary.map((item) => {
                return (
                  <div className="imgContainer" key={Math.random()}>
                    <div className="imgname">
                      <i className="iconfont iconwode-xianxing no-body"></i>
wangshuo committed
176
                    </div>
zhanghaozhe committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                  </div>
                )
              })}
            </Flex>
          </div>
        )
        groupSuccessMbc = (
          <div className="groupSuccessMbc" onClick={this.hideMbc}>
            <div className="content">
              <p>你已参团</p>
              {groupTip}
              <div className="group-btn" onClick={this.invitedFriends}>
                邀请好友参团 {countdown} 后结束
              </div>
              <p className="dec">分享到3个群后,成团率高达98%</p>
            </div>
          </div>
        )
      }
    }
197

zhanghaozhe committed
198 199 200 201 202 203 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 237 238 239 240
    return (
      <div className="group-box">
        {courseInfo.is_force == 0 && (
          <>
            <div className="group-title">
              <span>{groupInfo.now_groupon_total}人正在开团,可直接参与</span>
              <span className="more" onClick={this.getMore}>
                查看更多
                <i className="iconfont iconiconfront-70"></i>
              </span>
            </div>
            <ul className="group-list">
              {groupInfo.now_groupon_list &&
                groupInfo.now_groupon_list.length > 0 &&
                groupInfo.now_groupon_list.map((item, index) => {
                  return (
                    <li key={index} className="group-item">
                      <img className="avatar" src={item.avatar} alt="" />
                      <div className="user-name text-overflow-one">
                        {item.user_name}
                      </div>
                      <div className="group-status">
                        <p>
                          还差<span className="red">{item.number}</span>拼
                        </p>
                        <p>
                          剩余 {this.formatTimeByMillisecond(item.end_time)}
                        </p>
                      </div>
                      <span
                        onClick={() => {
                          this.toPay(item.pdd_order_id)
                        }}
                        className="topay"
                      >
                        去参团
                      </span>
                    </li>
                  )
                })}
            </ul>
          </>
        )}
wangshuo committed
241

zhanghaozhe committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        <div className="group-dec">
          <span>
            <i className="iconfont iconiconfront-1"></i>
            ·好友参团 ·人满成交 ·人不满退款
          </span>
          <span className="allNum">{`累计${groupInfo.person_num}人成团`}</span>
        </div>
        {alreadyIn && group_status === 4 && <>{groupSuccessMbc}</>}
        {/*更多*/}
        {this.state.isShowMore && (
          <div className="moreMbc">
            <div className="content">
              <div className="title-box">正在拼团</div>
              <ul className="more-group-list">
                {groupInfo.now_groupon_list &&
                  groupInfo.now_groupon_list.length > 0 &&
                  groupInfo.now_groupon_list.map((item, index) => {
                    return (
                      <li key={index} className="group-item">
                        <img className="avatar" src={item.avatar} alt="" />
                        <div className="user-name">
                          <p className="name text-overflow-one">
                            {item.user_name}
                          </p>
                          <p className="time">
                            剩余 {this.formatTimeByMillisecond(item.end_time)}
                          </p>
xuzhenghua committed
269
                        </div>
zhanghaozhe committed
270 271 272 273 274 275 276 277 278 279
                        <p className="group-status">还差{item.number}</p>
                        <span
                          onClick={() => {
                            this.toPay(item.pdd_order_id)
                          }}
                          className="topay"
                        >
                          去参团
                        </span>
                      </li>
280
                    )
zhanghaozhe committed
281 282 283 284 285 286 287
                  })}
              </ul>
              <div className="more-group-dec">仅显示10个正在开团的人</div>
              <i
                onClick={this.closeMore}
                className={"iconfont iconiconfront-2 close"}
              ></i>
xuzhenghua committed
288
            </div>
zhanghaozhe committed
289 290 291 292 293
          </div>
        )}
      </div>
    )
  }
xuzhenghua committed
294 295
}

296 297 298 299 300
// export default connect(
//     state => ({ courseInfo: state }),
//     null
// )(Group)

zhanghaozhe committed
301
export default Group