index.js 11.9 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7
import React, { Component } from "react"
import { connect } from "react-redux"
import { http, getParam, SendMessageToApp } from "src/utils"
import { Toast } from "antd-mobile"
import ListFrame from "./../listFrame/index"
import ListHeader from "./../listHeader"
import "./index.scss"
FE committed
8

zhanghaozhe committed
9 10
@connect(({ user }) => ({
  uid: user && user.data && user.data.uid ? user.data.uid : "",
FE committed
11
}))
FE committed
12 13
class CollectBlessing extends Component {
  constructor(props) {
zhanghaozhe committed
14
    super(props)
FE committed
15 16
    this.state = {
      rules: [
zhanghaozhe committed
17 18 19 20 21 22
        "app/h5/pc端活动页签到+5点福气值(每天一次)",
        "关注七月在线微信服务号+30点福气值(仅限一次)",
        "分享活动页到朋友圈、qq、微博,分别+2点福气值(每个平台每天一次)",
        "浏览指定课程详情页,一门课程+2点福气值(每天一次)",
        "邀请好友注册,+10点福气值/人(无上限)",
        "活动期间每购买一门课程+20点福气值",
wangshuo committed
23 24 25
      ],
      welfareRuleList: [
        {
zhanghaozhe committed
26
          range: "50~100",
wangshuo committed
27
          rules: [
zhanghaozhe committed
28 29 30 31 32 33 34 35
            { id: 1, text: "1.每天一次抽奖机会;" },
            {
              id: 2,
              text: "2.中奖概率翻2倍",
              des: "(福气值越高,中奖概率越大);",
            },
            { id: 3, text: "3.满111减11、满1111减111。" },
          ],
wangshuo committed
36 37
        },
        {
zhanghaozhe committed
38
          range: "101~190",
wangshuo committed
39
          rules: [
zhanghaozhe committed
40 41 42 43 44 45 46 47 48
            { id: 1, text: "1.每天两次抽奖机会;" },
            {
              id: 2,
              text: "2.中奖概率翻3倍",
              des: "(福气值越高,中奖概率越大);",
            },
            { id: 3, text: "3.满111减31、满1111减211;" },
            { id: 4, text: "4.AI水平测试增加1次。" },
          ],
wangshuo committed
49 50
        },
        {
zhanghaozhe committed
51
          range: ">190",
wangshuo committed
52
          rules: [
zhanghaozhe committed
53 54 55 56 57 58 59 60 61 62
            { id: 1, text: "1.每天三次抽奖机会;" },
            {
              id: 2,
              text: "2.中奖概率翻4倍",
              des: "(福气值越高,中奖概率越大);",
            },
            { id: 3, text: "3.满111减51、满1111减411;" },
            { id: 4, text: "4.AI水平测试增加2次。" },
          ],
        },
wangshuo committed
63
      ],
xuzhenghua committed
64
      seconds: 5,
zhanghaozhe committed
65
    }
FE committed
66
  }
FE committed
67

xuzhenghua committed
68
  qqToShare = () => {
zhanghaozhe committed
69 70 71 72 73
    const { uid, history } = this.props
    if (getParam("version")) {
      if (!uid) {
        SendMessageToApp("toLogin")
      } else {
xuzhenghua committed
74
        SendMessageToApp("QQshare", {
zhanghaozhe committed
75 76 77 78 79 80 81
          title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
          desc:
            "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
          link: "https://m.julyedu.com/blessingPreheat",
          imgUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
        })
FE committed
82
      }
zhanghaozhe committed
83 84 85 86 87 88 89
    } else {
      if (!uid) {
        history.push("/passport")
      } else {
        history.push(
          "/blessingPreheat?utm_source=qq&utm_medium=11&utm_campaign=QQ11&utm_content=11&utm_term=11"
        )
FE committed
90
        this.fetchUserBlessing(3, () => {
zhanghaozhe committed
91 92
          this.handleToAddBlessing(3)
        })
FE committed
93
      }
FE committed
94 95 96 97
    }
  }

  wechatToShare = () => {
zhanghaozhe committed
98 99 100 101 102
    const { uid, history } = this.props
    if (getParam("version")) {
      if (!uid) {
        SendMessageToApp("toLogin")
      } else {
xuzhenghua committed
103
        SendMessageToApp("WXshare", {
zhanghaozhe committed
104 105 106 107 108 109 110
          title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
          desc:
            "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
          link: "https://m.julyedu.com/blessingPreheat",
          imgUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
        })
FE committed
111
      }
zhanghaozhe committed
112 113 114 115 116 117 118
    } else {
      if (!uid) {
        history.push("/passport")
      } else {
        history.push(
          "/blessingPreheat?utm_source=1&utm_medium=1&utm_campaign=11&utm_content=1&utm_term=1"
        )
FE committed
119
        this.fetchUserBlessing(1, () => {
zhanghaozhe committed
120 121
          this.handleToAddBlessing(1)
        })
FE committed
122
      }
FE committed
123 124 125
    }
  }

FE committed
126
  weiboToShare = () => {
zhanghaozhe committed
127 128 129 130 131 132 133 134 135 136 137 138 139
    const { uid, history } = this.props
    if (getParam("version")) {
      if (!uid) {
        SendMessageToApp("toLogin")
      } else {
        SendMessageToApp("WBshare", {
          title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
          desc:
            "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
          link: "https://m.julyedu.com/blessingPreheat",
          imgUrl:
            "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
        })
FE committed
140
      }
zhanghaozhe committed
141 142 143 144 145 146 147
    } else {
      if (!uid) {
        history.push("/passport")
      } else {
        history.push(
          "/blessingPreheat?utm_source=sina&utm_medium=11&utm_campaign=sina11&utm_content=1&utm_term=11"
        )
FE committed
148
        this.fetchUserBlessing(2, () => {
zhanghaozhe committed
149 150
          this.handleToAddBlessing(2)
        })
FE committed
151
      }
FE committed
152 153
    }
  }
xuzhenghua committed
154

FE committed
155
  fetchUserBlessing(key, cb) {
zhanghaozhe committed
156 157 158 159 160 161 162 163 164 165 166
    const { handleToShowShare } = this.props
    let { seconds } = this.state
    http.get(`${API.home}/sys/user/blessing`).then((res) => {
      const { code, data } = res.data
      if (code === 200) {
        if (data.today_shared_platforms.some((item) => item === key)) {
          handleToShowShare()
          Toast.info("今日已+2点福气值”~", 2, null, false)
        } else {
          handleToShowShare()
          this.shareTimer && clearInterval(this.shareTimer)
FE committed
167 168
          this.shareTimer = setInterval(() => {
            this.setState(
xuzhenghua committed
169
              {
zhanghaozhe committed
170
                seconds: --seconds,
xuzhenghua committed
171
              },
FE committed
172 173
              () => {
                if (seconds === 0) {
xuzhenghua committed
174
                  this.setState({
zhanghaozhe committed
175 176 177 178
                    seconds: 5,
                  })
                  typeof cb === "function" && cb()
                  clearInterval(this.shareTimer)
FE committed
179 180
                }
              }
zhanghaozhe committed
181 182
            )
          }, 1000)
FE committed
183 184
        }
      }
zhanghaozhe committed
185
    })
FE committed
186 187 188
  }

  handleToAddBlessing = (key) => {
zhanghaozhe committed
189 190 191 192 193 194 195 196 197 198 199
    http
      .post(`${API.home}/sys/add/blessing`, {
        share_platform: key, // 1 朋友圈 2 微博 3 qq
        type: 3, // 1:签到;3:分享;4:浏览课程;
      })
      .then((res) => {
        const { code } = res.data
        if (code === 200) {
          Toast.info("+2点福气值~", 2, null, false)
        }
      })
FE committed
200
  }
xuzhenghua committed
201

FE committed
202
  handleToInvite = () => {
zhanghaozhe committed
203 204 205 206 207 208
    const { uid, history } = this.props
    if (!uid) {
      if (getParam("version")) {
        SendMessageToApp("toLogin")
      } else {
        history.push("/passport")
FE committed
209
      }
zhanghaozhe committed
210 211 212 213 214 215 216 217
    } else {
      if (getParam("version")) {
        history.push(
          "/invite?version=" +
            getParam("version") +
            "&plat_form=" +
            getParam("plat_form")
        )
xuzhenghua committed
218
      } else {
zhanghaozhe committed
219
        history.push("/invite")
xuzhenghua committed
220
      }
FE committed
221 222 223
    }
  }

FE committed
224
  render() {
xuzhenghua committed
225
    const {
FE committed
226
      isSign,
zhanghaozhe committed
227 228 229 230 231 232
      userInfo: {
        blessingVal = 0,
        buyBlessing = 0,
        inviteBlessing = 0,
        isFollow = 0,
      },
xuzhenghua committed
233
      isLogin,
xuzhenghua committed
234 235
      handleToShowNotice,
      handleToShowList,
wangshuo committed
236
      toLogin,
zhanghaozhe committed
237 238
      toSection,
    } = this.props
zhanghaozhe committed
239
    const { rules, welfareRuleList } = this.state
FE committed
240
    return (
wangshuo committed
241
      <div className="collect-blessing">
zhanghaozhe committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
        {isLogin ? (
          <ListHeader
            text={`我的福气值: ${blessingVal}分`}
            size="middle"
            styles={{ margin: "20px 0 0 0" }}
          />
        ) : (
          <ListHeader size="middle" styles={{ margin: "20px 0 0 0" }}>
            <span className="text_nologin">我的福气值:</span>
            <span onClick={toLogin} className="login__btn">
              登录
            </span>
          </ListHeader>
        )}
        <p className="activity__over">活动结束前福气榜前50名可获奖品一份</p>
        {welfareRuleList.map((item, index) => (
          <div className="rules__item" key={index}>
            <div className="item__left">
              <div className="tip__bubble">
                <div className="tip__text">福气值</div>
                <div className="tip__style"></div>
FE committed
263
              </div>
zhanghaozhe committed
264
              <div className="range__number">{item.range}</div>
FE committed
265
            </div>
zhanghaozhe committed
266 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
            <div className="item__right">
              {item.rules.map((item) => {
                return (
                  <p key={item.id}>
                    {item.text}
                    <span>{item.des}</span>
                  </p>
                )
              })}
            </div>
          </div>
        ))}
        <ListHeader
          text="福气值积攒规则"
          size="middle"
          styles={{ margin: "30px 0 0" }}
        />
        {rules.map((item, index) => (
          <div className="collect-blessing__item" key={index}>
            <i className="collect-blessing__num">{index + 1}</i>
            <p className="collect-blessing__title">{item}</p>
            {index === 0 && (
              <>
                {isLogin && isSign ? (
                  <button
                    className="collect-blessing__content"
                    data-status="done"
                  >
                    已加5
                  </button>
                ) : (
                  <button
                    onClick={toLogin}
                    className="collect-blessing__content"
                  >
                    点击
                    <br />
                    签到
                  </button>
                )}
              </>
            )}
            {index === 1 && (
              <>
                {isFollow === 1 ? (
                  <button
                    className="collect-blessing__content"
                    data-status="done"
                    onClick={handleToShowNotice}
                  >
                    已加30
                  </button>
                ) : (
                  <button
                    className="collect-blessing__content"
                    onClick={handleToShowNotice}
                  >
                    关注
                    <br />
                    二维码
                  </button>
                )}
              </>
            )}
            {index === 2 && (
              <div className="collect-blessing__content" data-layout="column">
                <p className="collect-blessing__label">去分享</p>
                <div className="collect-blessing__share">
                  <button
xuzhenghua committed
335
                    className="collect-blessing__share-button"
FE committed
336
                    data-type="qq"
xuzhenghua committed
337
                    onClick={this.qqToShare}
zhanghaozhe committed
338 339 340 341 342 343 344 345 346 347 348
                  ></button>
                  <button
                    className="collect-blessing__share-button"
                    data-type="wechat"
                    onClick={this.wechatToShare}
                  ></button>
                  <button
                    className="collect-blessing__share-button"
                    data-type="weibo"
                    onClick={this.weiboToShare}
                  ></button>
FE committed
349
                </div>
zhanghaozhe committed
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 378
              </div>
            )}
            {index === 3 && (
              <button
                className="collect-blessing__content"
                onClick={handleToShowList}
              >
                浏览课程
                <br />
                详情页
              </button>
            )}
            {index === 4 && (
              <button
                className="collect-blessing__content"
                onClick={this.handleToInvite}
              >
                <span>邀请链接</span>
                {inviteBlessing > 0 && <i>已加{inviteBlessing}</i>}
              </button>
            )}
            {index === 5 && (
              <button className="collect-blessing__content" onClick={toSection}>
                <span>去选课</span>
                {buyBlessing > 0 && <i>已加{buyBlessing}</i>}
              </button>
            )}
          </div>
        ))}
FE committed
379 380 381 382 383
      </div>
    )
  }
}

zhanghaozhe committed
384
export default ListFrame(CollectBlessing)