index.js 11.2 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react';
import {InputItem, List} from "antd-mobile";
zhanghaozhe committed
3
import './bargain-info.scss'
xuzhenghua committed
4 5
import {validateTel} from "@/utils";
import {Toast} from 'antd-mobile'
FE committed
6
import { http, getParam } from "@/utils";
xuzhenghua committed
7
import {Link} from "react-router-dom";
FE committed
8
import classnames from 'classnames';
zhanghaozhe committed
9 10


zhanghaozhe committed
11 12 13 14
class BargainInfo extends Component {

    state = {
        mobile: '',
xuzhenghua committed
15
        code: '',
FE committed
16 17 18 19
        num: '86',
        isBargain: true,
        isFocus: false,
        bindInfo: {},
FE committed
20 21 22
        isTip: false,
        seconds: 60,
        isTimer: false, // 是否开始倒计时
zhanghaozhe committed
23 24 25 26 27 28 29 30 31 32 33
    }

    handleChange = e => {

        let {name, value} = e.target

        this.setState({
            [name]: value
        })
    }

FE committed
34
    // 获取短信验证码
zhanghaozhe committed
35
    sendCode = () => {
FE committed
36
        const { country } = this.props;
FE committed
37 38 39 40 41
        let { mobile, isTimer, seconds } = this.state;
        if(!isTimer) {
            if(!/^\d+$/.test(mobile)){
                Toast.info('请输入正确的手机号');
                return;
FE committed
42 43
            }

FE committed
44 45 46 47
            // 获取验证码
            http.post(
                `${API['passport-api']}/m/personal/bindPhoneSendCode`,
                {
FE committed
48 49
                    area_code: `00${country}`,
                    phone_num: mobile
FE committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
                }
            ).then(res => {
                const { errno, msg } = res.data;
                if(errno === 200) {
                    Toast.info('验证码发送成功', 2, null, false);
                    
                    // 倒计时
                    this.timer = window.setInterval(() => {
                        console.log(seconds);
                        if (seconds <= 0) {
                            window.clearInterval(this.timer);
                            this.setState({
                                isTimer: false,
                                seconds: 60
                            });
                        }else {
                            this.setState({
                                isTimer: true,
                                seconds: --seconds
                            });
                        }
                    }, 1000);
                }else {
                    Toast.info(msg);
                }
            });
        }
FE committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

        // http.post(`${API['base-api']}/sys/bind_send_sms`, {
        //     phone_num: this.state.mobile
        // }).then(res => {
        //     if (res.data.code == 200) {
        //         Toast.info('验证码发送成功', 2, null, false)
        //     } else if (res.data.errno === 410) {
        //         Toast.info('该手机号已注册,请使用该手机号登录,发起砍价。', 3, null, false)
        //         this.setState({
        //             isBargain: false
        //         })
        //     } else {
        //         Toast.info(res.data.msg)
        //     }
        // })
zhanghaozhe committed
92 93
    }

FE committed
94 95 96 97
    // 绑定手机号
    handleClick = (isValid = 1) => {
        const { country, iWantBargain } = this.props;
        const { code, mobile } = this.state;
FE committed
98 99 100 101 102 103
        if (!mobile) {
            Toast.info('请填手机号码');
            return;
        }
        if (!code) {
            Toast.info('请填写验证码');
FE committed
104
            return;
zhanghaozhe committed
105 106
        }

FE committed
107 108 109 110
        // is_valid	是否验证 1:验证(默认),0不验证
        http.post(
            `${API['passport-api']}/m/personal/bindPhone`,
            {
FE committed
111
              area_code: `00${country}`,
FE committed
112 113 114 115
              phone_num: mobile,
              code: code,
              type: 1,
              is_valid: isValid
zhanghaozhe committed
116
            }
FE committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        ).then(res => {
            const { errno, data, msg } = res.data;
            if(errno === 200) {
                if(isValid) {
                    if(data.tip_info) {
                      this.setState({
                        isTip: true,
                        bindInfo: data.tip_info
                      })
                    }else {
                      iWantBargain();
                    }
                }else {
                    iWantBargain();
                }
            }else {
                Toast.info(msg);
            }
        });


        // http.post(`${API.home}/m/user/bindMobile`, {
        //     ...this.state
        // }).then(res => {
        //     if (res.data.code == 200) {
        //         Toast.info('绑定手机号成功', 2, null, false)
        //         this.props.iWantBargain()
        //     } else {
        //         Toast.info(res.data.msg)
        //     }
        // })
zhanghaozhe committed
148 149 150 151 152

    }


    render() {
FE committed
153
        const { country, toClose } = this.props;
FE committed
154
        const { mobile, code, isBargain, isFocus, bindInfo, isTip, isTimer, seconds } = this.state;
FE committed
155
        const bool = /^\d+$/.test(mobile);
zhanghaozhe committed
156
        return (
FE committed
157 158
            <>
                {/* 该手机号已绑定其他帐号 */}
xuzhenghua committed
159
                {
FE committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
                    isTip &&
                    <div className="popup-bind popup-bind--bargain">
                        <div className="popup-bind__content">
                        <h4 className="popup-bind__title">绑定确认</h4>
                        <p className="popup-bind__desc">该手机号已绑定到以下账号,继续绑定将解除以下绑定状态</p>
                        <ul className="popup-bind__list">
                            {
                            bindInfo['email'] &&
                            <li className="popup-bind__account">

                                {/* 邮箱 */}
                                <i className="iconfont iconduanxin"></i>
                                <p className="popup-bind__account--name">{bindInfo['email']}</p>
                            </li>
                            }
                            {
                            bindInfo['wechat_nickname'] &&
                            <li className="popup-bind__account">

                                {/* wechat */}
                                <i className="icon-wachat"></i>
                                <p className="popup-bind__account--name">{bindInfo['wechat_nickname']}</p>
                            </li>
                            }
                            {
                            bindInfo['qq_nickname'] &&
                            <li className="popup-bind__account">

                            {/* qq */}
                            <i className="icon-qq"></i>
                            <p className="popup-bind__account--name">{bindInfo['qq_nickname']}</p>
                            </li>
                            }
                            {
                            bindInfo['sina_nickname'] &&
                            <li className="popup-bind__account">

                                {/* 微博 */}
                                <i className="icon-sina"></i>
                                <p className="popup-bind__account--name">{bindInfo['sina_nickname']}</p>
                            </li>
                            }
                        </ul>
                        <div className="popup-bind__button">
                            <button
                            className="popup-bind__button--cancle"
                            onClick={toClose}>取消</button>
                            <button
                            className="popup-bind__button--confirm"
                            onClick={() => this.handleClick(0)}>继续绑定</button>
                        </div>
                        </div>
                    </div>
xuzhenghua committed
213 214
                }
                {
FE committed
215 216 217 218 219 220 221 222 223 224 225
                    !isTip &&
                    <div className="bargain-phone-popup">
                        <h2 className="bargain-phone-popup__title">绑定手机,先砍一刀</h2>
                        <div 
                            className={classnames(
                                "bargain-phone-popup__item",
                                {
                                    'active': isFocus
                                }
                            )}
                        >
FE committed
226
                            <Link
FE committed
227
                                className="bargain-phone-popup__button--num"
FE committed
228
                                to={`/country?id=${getParam('id')}&from=bargain`}
FE committed
229 230 231
                                >
                                +{country}
                                <i className="iconfont iconiconfront-69"></i>
FE committed
232
                            </Link>
FE committed
233 234 235 236 237 238 239 240 241 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 269
                            <input 
                                className="bargain-phone-popup__ipt"
                                type="tel" 
                                onChange={this.handleChange}
                                onFocus={() => {
                                    this.setState({
                                        isFocus: true
                                    });
                                }} 
                                onBlur={() => {
                                    this.setState({
                                        isFocus: false
                                    });
                                }}
                                name='mobile' 
                                placeholder='手机号' 
                                maxLength={11}
                            />
                        </div>
                        <div className="bargain-phone-popup__item">
                            <input 
                                type="tel" 
                                id='code' 
                                onChange={this.handleChange} 
                                name='code' 
                                placeholder='验证码'
                                maxLength={6}
                            />
                            <button 
                                type="button"
                                className={classnames(
                                    'bargain-phone-popup__button--send',
                                    {
                                        'active': bool
                                    }
                                )}
                                onClick={this.sendCode}
FE committed
270 271 272
                            >
                                {isTimer? `重新发送${seconds}s` : '发送验证码'}
                            </button>
FE committed
273 274 275 276 277 278
                        </div>
                        {
                            isBargain
                            ? (
                                <button 
                                    type="button"
FE committed
279
                                    onClick={() => this.handleClick()}
FE committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
                                    className={classnames(
                                        'bargain-phone-popup__button--bargain', 
                                        {
                                            'active': bool && code
                                        }
                                    )}
                                >先砍一刀</button>
                            )
                            : (
                                <Link 
                                    className='bargain-phone-popup__button--bargain active'
                                    to={`/passport/login`}
                                >去登录</Link>
                            )
                        }
                    </div>
xuzhenghua committed
296
                }
FE committed
297
            </>
zhanghaozhe committed
298 299 300
        );
    }
}
zhanghaozhe committed
301

FE committed
302
export default BargainInfo;