Blame view

public/js/passport/sms-password.page.js 2.62 KB
1
'use strict';
陈轩 authored
2
lijing authored
3 4
let tip, checkPoint, validatePWD;
let $eyeBtn,
陈轩 authored
5
    $pwd,
6 7 8
    $nextBtn,
    $pwdLint,
    $pwdLintTxt;
陈轩 authored
9
lijing authored
10
let page;
11
12
13
require('common');
14
tip = require('plugin/tip');
zzzzzzz authored
15
checkPoint = require('./smslogin/check-point');
16
validatePWD = require('./password-check');
17
陈轩 authored
18 19 20
setTimeout(function() {
    checkPoint('YB_SET_PASSWORD_L');
}, 3000);
21 22

page = {
23
    registerCode: window.queryString.registerCode,
陈轩 authored
24 25 26 27 28 29 30 31
    init: function() {
        this.domInit();
        this.bindEvent();
    },
    domInit: function() {
        $eyeBtn = $('#eye');
        $pwd = $('#pwd');
        $nextBtn = $('#btn-next');
32 33
        $pwdLint = $('.js-password').find('.pwd-lint');
        $pwdLintTxt = $pwdLint.find('.pwd-lint-txt');
陈轩 authored
34
    },
陈轩 authored
35
    bindEvent: function() {
lijing authored
36
        let self = this;
陈轩 authored
37 38 39 40 41 42

        $eyeBtn.on('click', function() {
            self.togglePassword();
        });

        $nextBtn.on('click', function() {
43
            if (!self.registerCode) {
陈轩 authored
44 45
                return tip.show('非法请求');
            }
陈轩 authored
46
            self.setPasswordAndLogin();
陈轩 authored
47 48 49
        });

        $pwd.on('input', function() {
lijing authored
50 51
            let val = $.trim(this.value);
            let bool = validatePWD(val, function(res) {
52
                $pwdLint.css({visibility: res.valid ? 'hidden' : 'visible'});
53 54 55 56 57

                if (!res.valid) {
                    $pwdLintTxt.text(res.msg);
                }
            });
陈轩 authored
58 59 60

            $nextBtn
                .toggleClass('disable', !bool)
陈轩 authored
61
                .prop('disabled', !bool);
陈轩 authored
62 63 64 65
        });
    },

    togglePassword: function() {
lijing authored
66
        let bool = $eyeBtn.hasClass('close');
陈轩 authored
67 68 69 70 71 72 73 74

        $eyeBtn.toggleClass(function() {
            $pwd.attr('type', !bool ? 'password' : 'text');
            return 'close';
        }, !bool);
    },

    setPasswordAndLogin: function() {
lijing authored
75 76
        let password = $.trim($pwd.val());
        let self = this;
陈轩 authored
77
陈轩 authored
78 79 80 81 82
        if ($nextBtn.prop('disabled')) {
            return;
        }

        $nextBtn.prop('disabled', true);
陈轩 authored
83
        $.post('/passport/sms_login/password.json', {
陈轩 authored
84
            password: password,
85
            registerCode: self.registerCode
陈轩 authored
86 87 88
        })
            .done(function(res) {
                if (res.code === 200) {
89
                    checkPoint('YB_SET_PASSWORD_ENSURE_C'); // 埋点
陈峰 authored
90
                    // $nextBtn.off();
陈轩 authored
91 92 93 94 95 96 97 98
                    location.href = res.redirect;
                    return;
                }

                tip.show(res.message);
            })
            .fail(function() {
                tip.show('出错了, 请重试');
陈轩 authored
99 100
            })
            .always(function() {
陈轩 authored
101
                $nextBtn.prop('disabled', false);
陈轩 authored
102 103
            });
    }
陈轩 authored
104 105 106
};
$(function() {
    page.init();
陈轩 authored
107
});