<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>修改密码</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">旧密码：</label>
                                            <div class="col-sm-4">
                                                <input type="password" class="form-control oldpwd" placeholder="旧密码" name="oldpwd">
                                            </div>
                                            <p class="col-sm-6 help-block"></p>
                                        </div>
                                        <hr/>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">新密码：</label>
                                            <div class="col-sm-4">
                                                <input type="password" class="form-control newpwd1" placeholder="新密码(大于等于6位,不能纯数字)" name="newpwd1">
                                            </div>
                                            <p class="col-sm-6 help-block"></p>
                                        </div>
                                        <hr/>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">确认密码：</label>
                                            <div class="col-sm-4">
                                                <input type="password" class="form-control newpwd2" placeholder="确认密码(大于等于6位,不能纯数字)" name="newpwd2">
                                            </div>
                                            <p class="col-sm-6 help-block"></p>
                                        </div>
                                        <hr/>
                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="changepwd btn btn-primary ">提交</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript">
    $('.changepwd').click(function(){
        var oldpwdVal = $('.oldpwd').val();
        var newpwd1 = $('.newpwd1').val();
        var newpwd2 = $('.newpwd2').val();
        if ( oldpwdVal.length == 0 || oldpwdVal == null) {
            alert('旧密码为空');
            $('.oldpwd').focus();
            return false;
        }
        if ( newpwd1.length == 0 || newpwd1 == null) {
            alert('新密码为空');
            $('.newpwd1').focus();
            return false;
        }
        if ( newpwd2.length == 0 || newpwd2 == null) {
            alert('确认密码为空');
            $('.newpwd2').focus();
            return false;
        }

        if (newpwd1 != newpwd2) {
            alert('新密码不一致');
            $('.newpwd2').focus();
            return false;
        }

        if (newpwd1.length < 6) {
            alert('新密码长度低于6位');
            $('.newpwd1').focus();
            return false;
        }

        if (!isNaN(newpwd1)) {
            alert('新密码不能全为数字');
            $('.newpwd1').focus();
            return false;
        }

        //提交
        $.ajax({
            type: 'POST',
            url: '<?php echo base_url('sys/actionchange');?>',
            dataType: 'json',
            data: {oldpwd:oldpwdVal, newpwd1:newpwd1, newpwd2:newpwd2},
            success:function(e){
                if (e.code == 1) {
                    alert('修改成功');
                    window.location = '<?php echo base_url('qazwsxcde');?>';
                }else if(e.code == -1){
                    alert('旧密码错误');
                }else{
                    alert('新密码不一致');
                }
            }
        });
    });
</script>
