index.js 2.92 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'
zhanghaozhe committed
6
import { http } from "@/utils";
xuzhenghua committed
7
import {Link} from "react-router-dom";
zhanghaozhe committed
8 9


zhanghaozhe committed
10 11 12 13
class BargainInfo extends Component {

    state = {
        mobile: '',
xuzhenghua committed
14 15
        code: '',
        isBargain: true
zhanghaozhe committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    }

    handleChange = e => {

        let {name, value} = e.target

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

    sendCode = () => {

        console.log(validateTel(this.state.mobile));

        if (!validateTel(this.state.mobile)) {
            Toast.info('请输入正确的手机号')
            return
        }


zhanghaozhe committed
37
        http.post(`${API['base-api']}/sys/bind_send_sms`, {
zhanghaozhe committed
38 39 40 41
            phone_num: this.state.mobile
        }).then(res => {
            if (res.data.code == 200) {
                Toast.info('验证码发送成功', 2, null, false)
xuzhenghua committed
42 43 44 45 46
            } else if (res.data.errno === 410) {
                Toast.info('该手机号已注册,请使用该手机号登录,发起砍价。', 3, null, false)
                this.setState({
                    isBargain: false
                })
zhanghaozhe committed
47 48 49 50 51 52 53 54 55 56 57 58
            } else {
                Toast.info(res.data.msg)
            }
        })
    }

    handleClick = () => {
        if (!this.state.code) {
            Toast.info('请填写验证码')
            return
        }

zhanghaozhe committed
59
        http.post(`${API.home}/m/user/bindMobile`, {
zhanghaozhe committed
60 61 62 63
            ...this.state
        }).then(res => {
            if (res.data.code == 200) {
                Toast.info('绑定手机号成功', 2, null, false)
xuzhenghua committed
64
                this.props.iWantBargain()
zhanghaozhe committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
            } else {
                Toast.info(res.data.msg)
            }
        })

    }


    render() {
        let {mobile, code} = this.state
        return (
            <div className={'bargain-bind-phone'}>
                <div className="title">绑定手机,先砍一刀</div>
                <List className={'list'}>
                    <input type="tel" onChange={this.handleChange} name='mobile' placeholder='手机号' maxLength={11}/>
                    <label htmlFor="code">
xuzhenghua committed
81 82
                        <input type="tel" id='code' onChange={this.handleChange} name='code' placeholder='验证码'
                               maxLength={6}/>
zhanghaozhe committed
83 84 85
                        <div className={'send-code'} onClick={this.sendCode}>发送验证码</div>
                    </label>
                </List>
xuzhenghua committed
86 87 88 89 90 91 92 93 94
                {
                    this.state.isBargain &&
                    <button onClick={this.handleClick}
                            className={validateTel(mobile) && code ? 'active' : ''}>先砍一刀</button>
                }
                {
                    !this.state.isBargain &&
                    <Link className='button active' to={`/passport/login`}>去登录</Link>
                }
zhanghaozhe committed
95 96 97 98
            </div>
        );
    }
}
zhanghaozhe committed
99

xuzhenghua committed
100
export default BargainInfo