/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/02/17 by CL $
*/
var _qq_cd_timer = 60; //倒计时
$(function(){
    
    function OESendQQ() {
        this.sendurl = _ROOT_PATH+'index.php?m=wap';
        
        this.input = 'qq'; //输入框名称
        this.qq = ''; //邮箱
        this.send_type = 'reg'; //发送类型
        
        this.but_send = 'but_send_qq_code'; //发送按钮 f
        this.but_obj_id = 'but_send_qq_code'; //返送按钮 id 
        
        
        this.wakeSend();
    }
    OESendQQ.prototype = {
        
        wakeSend:function() {
            var _this = this;
            
            //点击发送按钮
            $(document).on("click", "[f='"+_this.but_send+"']", function(){
                var $input = $(this).attr("data-input");
                if (typeof($input) == "undefined") {
                    
                }
                else {
                    _this.input = $input;
                }
                var $val = $("#"+_this.input).val();
                if (typeof($val) == "undefined") {
                    $val = "";
                }
                if ($val == "") {
                    OEUI.toast({
                        type: 'bottom',
                        text: '请填写邮箱地址'
                    });
                    return;
                }
                var $type = $(this).attr("data-type"); //类型
                if (typeof($type) == "undefined") {
                    $type = "reg";
                }
                _this.send_type = $type;
                _this.but_obj_id = $(this).attr("id"); //保存obj_id
                _this.qq = $val;
                _this.sendQQ();
                
            });
            
        },
        
        //发送邮箱验证码
        sendQQ:function() {
            var _this = this;
            
            if (!$("#"+_this.but_obj_id).hasClass("forbid_send")) { 
            
                $("#"+_this.but_obj_id).addClass("forbid_send");
                $.ajax({
                    type: "POST",
                    url: _this.sendurl,
                    cache: false,
                    data: {
                        c:'picker', a:'sendqq', type:_this.send_type, 
                        qq:_this.qq
                    },
                    dataType: "json",
                    success: function($data) {
                        var $json = eval($data);
                        var $response = $json.response;
                        var $result = $json.result;
                        $("#"+_this.but_obj_id).removeClass("forbid_send");
                        
                        if ($response == "1") {
                            OEUI.toast({
                                type: 'bottom',
                                text: '发送成功，请查收QQ邮件！'
                            });
                            _this.pickerCountDown(); //倒计时
                        }
                        else {
                            if ($result.length == 0 || $result == '') {
                                $result = '发送失败，请检查QQ邮箱是否可用！';
                            }
                            OEUI.toast({
                                type: 'bottom',
                                text: $result
                            });
                            
                            $("#"+_this.but_obj_id).html('获取验证码');
                        }
                    },
                    error: function() {
                        $("#"+_this.but_obj_id).removeClass("forbid_send");
                        $("#"+_this.but_obj_id).html('获取验证码');
                    }
                }); 
            }
        },
        
        //倒计时
        pickerCountDown:function() {
            var _this = this;
            var $obj = $("#"+_this.but_obj_id);
            if (_qq_cd_timer == 0) {
                $obj.html("获取验证码");
                $obj.removeClass("color_m");
                $obj.addClass("color_main");
                $obj.attr('f', _this.but_send);
                _qq_cd_timer = 60; 
            }
            else {
                $obj.removeClass("color_main");
                $obj.addClass("color_m"); 
                $obj.html(_qq_cd_timer+"秒重新发送");
                $obj.attr('f', '');
                _qq_cd_timer--; 
                setTimeout(function() { 
                    _this.pickerCountDown();
                },	1000);
            }
        }
    }
    
    new OESendQQ();
    
});

