Blame view

static/js/passport/back/mobile.js 1.4 KB
xuqi authored
1 2 3 4 5
/**
 * 找回密码-手机
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/8
 */
xuqi authored
6
var $ = require('jquery');
xuqi authored
7 8

var $phoneNum = $('#phone-num'),
xuqi authored
9
    $countrySelect = $('#country-select'),
xuqi authored
10
    $areaCode = $('#area-code'),
xuqi authored
11 12 13
    $btnNext = $('#btn-next');

var api = require('../api');
xuqi authored
14
var tip = require('../../plugin/tip');
xuqi authored
15 16

var trim = $.trim;
xuqi authored
17
var showErrTip = tip.show;
xuqi authored
18
xuqi authored
19 20
api.selectCssHack($('#country-select'));
xuqi authored
21 22 23 24 25 26 27 28 29 30
api.bindClearEvt();

$phoneNum.bind('input', function() {
    if (trim($phoneNum.val()) === '') {
        $btnNext.addClass('disable');
    } else {
        $btnNext.removeClass('disable');
    }
});
xuqi authored
31
$countrySelect.change(function() {
xuqi authored
32
    $areaCode.text($countrySelect.val());
xuqi authored
33 34
});
xuqi authored
35
$btnNext.on('touchstart', function() {
xuqi authored
36
    var pn = trim($phoneNum.val()),
xuqi authored
37
        area = $countrySelect.val();
xuqi authored
38 39 40 41 42

    if ($btnNext.hasClass('disable')) {
        return;
    }
xuqi authored
43
    if (api.phoneRegx[area].test(pn)) {
xuqi authored
44 45 46 47
        $.ajax({
            url: '/passport/back/sendcode',
            type: 'POST',
            data: {
xuqi authored
48
                areaCode: area.replace('+', ''),
xuqi authored
49
                phoneNum: pn
xuqi authored
50 51 52
            },
            success: function(data) {
                if (data.code === 200) {
53
                    location.href = data.data;
xuqi authored
54 55 56
                } else {
                    showErrTip(data.message);
                }
xuqi authored
57 58 59 60 61 62
            }
        });
    } else {
        showErrTip('手机号格式不正确,请重新输入');
    }
});