jquery 转盘抽奖

/*
 *转盘 活动 Type
 *作者:ZC3  
 *时间:2014-5-06
 *版本:V1.0
 */
define(function(require, exports, module) {
    var givemefuc;
    var singlecost = 0;
    var lianchoucount = 0;
    var chongzhicost = 0;
    var goldballcount = 0;
    exports.init = function(givef) {
        givemefuc = givef;
        initHtml();
    };
    function initHtml() {
        var grhtml = "<div class='gift_zp_bg'>";
        grhtml += "<div class='gift_zp_time'>【活动时间】:</div>";
        grhtml += "<div class='gift_zp_start'></div> ";
        grhtml += "<div class='gift_zp_arrowc'><img src='" + GetImgPath() + "images/gift/zhuanpan/gift_zp_arrow.png' id='gift_zp_arrow'></div> ";
        grhtml += "<div class='gift_zp_des'><h4>活动规则:</h4>1、<span>" + singlecost + "</span>金/次<br/>2、若获得金球,可在兑换页面中用金球兑换不同的奖励<br/>3、活动每日24点重置</div>";
        grhtml += "<div class='gift_zp_ballcount'>金球数:<span></span></div>";
        grhtml += "<div class='gift_zp_duihuan btn_gs' >换大奖</div>";
        grhtml += "<div class='gift_zp_chongzhi btn_bs' >重置</div>";
        grhtml += "<div class='gift_zp_lianchou btn_gs' >抽10次</div>";
        grhtml += "</div>";
        $('.gift_huodong_right').html(grhtml);
        Loading('gift_huodong'); /*加载右边的加载条*/

        $.post("data/prochandler.ashx", {"type": "Act_TurnTable_GetInfo"}, function(data) {
            if (data[0].ret == "-1") {
                showinfo("系统错误");
            } else if (data[0].ret == "-2") {
                showinfo("活动未开启");
            } else {
                var hdtime = returntime($("#zhuanpan").attr("tid"), $("#zhuanpan").attr("nid"));
                var ghtml = "";
                $(".gift_zp_time").text("活动时间:" + hdtime);
                $(".gift_zp_ballcount span").text(data[0].a1);
                goldballcount = parseInt(data[0].a1);
                $(".gift_zp_des span").text(data[0].a2);
                singlecost = data[0].a2;
                lianchoucount = data[0].a6;
                chongzhicost = data[0].a3;
                var rewarditemarr = data[0].a4.split("|");
                for (var i = 0; i < 12; i++) {
                    var rewarditem = rewarditemarr[i].split(",");
                    ghtml += "<div class='gift_zp_rewardc gift_zp_rewardc" + i + " " + (parseInt(data[0].a5.substr(i, 1)) > 0 ? 'gift_zp_rewardf' : '') + "' tid='" + data[0].a5.substr(i, 1) + "'>";
                    ghtml += "<img  class='gift_zp_reward gift_zp_reward" + i + "' src='" + GetImgPath() + "images/item/s" + rewarditem[2] + ".png' tid='" + rewarditem[1] + "'>";
                    ghtml += "</div>";
                }
                $('.gift_zp_bg').append(ghtml);
                $(".gift_zp_start").on({//开始
                    click: function() {
                        zpstart(1);
                    }
                });
                $(".gift_zp_reward").on({
                    mouseover: function() {
                        if ($(this).attr("tid") != "") {
                            showtipbox($(this), $(this).attr("tid"));
                        }
                    }, /*会在鼠标移入对象时触发*/
                    mouseout: function() {
                        removetipbox();
                    }, /*在鼠标从元素上离开后会触发*/
                    click: function() {
                    }
                });
                $(".gift_zp_duihuan").on({//换大奖
                    click: function() {
                        lingqujiangli();
                    }
                });
                $(".gift_zp_chongzhi").on({//重置
                    click: function() {
                        var html = "<div class='ply_style'>是否花费" + chongzhicost + "金币重置?</div>";
                        showmsg('温馨提示', html, '重置', zpchongzhi, 'gift_huodong', null, null);

                    }
                });
                $(".gift_zp_lianchou").on({//抽10次
                    click: function() {
                        zpstart(lianchoucount);
                    }
                });
            }
            RemoveLoading(); /*消除加载条*/
        }, "json");
    }
    //开始
    function zpstart(type) {
        $.post("data/prochandler.ashx", {"type": "Act_TurnTable_Turn", "pickcount": type}, function(data) {
            if (data[0].ret == '-1') {
                showinfo("系统错误");
            } else if (data[0].ret == '-2') {
                showinfo("活动未开启");
                $("#gift_huodong").remove();
            } else if (data[0].ret == '-3') {
                showinfo("没有转盘奖励");
            } else if (data[0].ret == '-4') {
                var html = "<div class='ply_style'>金币不足,马上充值?</div>";
                showmsg('温馨提示', html, '充值', addgold, 'gift_huodong', null, null, 1);
            } else {
                var jb = $('.index_info_gold_2 .goldcolor').text();
                if (type == lianchoucount) {
                    $('.index_info_gold_2 .goldcolor').text(data[0].a3);
                    $(".gift_zp_ballcount span").text(data[0].a4);
                    zplianchou(data);
                    for (i = 0; i < 12; i++) {
                        if (data[0].a5.substr(i, 1) == "1") {
                            $(".gift_zp_rewardc" + i).addClass("gift_zp_rewardf");
                            $(".gift_zp_rewardc" + i).attr("tid", 1);
                        }
                    }
                } else {
                    $('.index_info_gold_2 .goldcolor').text(data[0].a3);
                    $(".gift_zp_ballcount span").text(data[0].a4);
                    var at = parseInt(data[0].a2);
                    var a = Math.floor(at * 360 / 12) - 15; //生成随机数
                    $(".gift_zp_start").bind().off();
                    $("#gift_zp_arrow").rotate({
                        duration: 3000, //转动时间间隔(转动速度)
                        angle: 0, //开始角度
                        animateTo: 1800 + a, //转动角度,5圈+
                        easing: $.easing.easeOutSine, //动画扩展
                        callback: function() { //回调函数
                            if (parseInt($(".gift_zp_rewardc" + (at - 1)).attr("tid")) == 0) {
                                giftdonghuaty("gift_zp_rewardc" + (at - 1));
                                $(".gift_zp_rewardc" + (at - 1)).addClass("gift_zp_rewardf");
                                $(".gift_zp_rewardc" + (at - 1)).attr("tid", 1);
                            } else {
                                showinfo("奖励已经被抽取");
                            }
                            $(".gift_zp_start").on({//开始
                                click: function() {
                                    zpstart(1);
                                }
                            });
                        }
                    });
                }
            }
        }, 'json');
    }
    /*获得领取奖励界面*/
    function lingqujiangli() {
        $(".gift_zp_bg").removeClass("gift_zp_bg").addClass("gift_zp_bg2");
        var grhtml = "<div class='gift_zp_rebtn btn_bs'>抽金球</div>";
        grhtml += "<div class='gift_zp_rewzone'>";
        grhtml += "<div class='gift_zp_sr6 gift_zp_sr_s6'>";
        grhtml += "</div>";
        grhtml += "<div class='gift_zp_src'><div class='gift_zp_center'>";
        grhtml += "</div><div class='scrollbar'><div class='handle'></div></div></div>";
        grhtml += "</div>";
        $(".gift_zp_bg2").html(grhtml);
        $.post("data/prochandler.ashx", {"type": "Act_TurnTable_GoldenAward"}, function(data) {

            var gmaxhtml = "";
            var rewardarr = data[6].a2.split("|");
            var namearr = rewardarr[0].split(",");
            var codearr = rewardarr[1].split(",");
            for (var k = 0; k < namearr.length; k++) {
                gmaxhtml += "<img  class=' gift_zp_sritemb gift_zp_sritemb" + k + "' src='" + GetImgPath() + "images/item/s" + codearr[k] + ".png' tid='" + namearr[k] + "'>";
            }
            var btnstyle = goldballcount > parseInt(data[6].a1) ? 'btn_gs' : 'btn_off_s';
            gmaxhtml += "<div class='gift_zp_rbtn6 gift_zp_rbtnb " + btnstyle + "' tid='" + data[6].a1 + "' nid='6'>25球领取</div>";
            $(".gift_zp_sr6").html(gmaxhtml);
            var gminhtml = "";
            for (var i = 1; i < data.length - 1; i++) {
                gminhtml += "<div class='gift_zp_sr gift_zp_sr_s" + i + "'>";
                gminhtml += "<div class='gift_zp_level'>" + data[i].a1 + "球奖</div>";
                var rewardarr2 = data[i].a2.split("|");
                var namearr2 = rewardarr2[0].split(",");
                var codearr2 = rewardarr2[1].split(",");
                for (var j = 0; j < namearr2.length; j++) {
                    gminhtml += "<img  class='gift_zp_sritem' src='" + GetImgPath() + "images/item/s" + codearr2[j] + ".png' tid='" + namearr2[j] + "'>";
                }
                var btnstyle = goldballcount >= parseInt(data[i].a1) ? 'btn_gs' : 'btn_off_s';
                gminhtml += "<div class='gift_zp_rbtn " + btnstyle + " gift_zp_rbtn" + i + "' tid='" + data[i].a1 + "' nid='" + i + "'>领取(<span class="lingqusp"" + i + ">" + Math.floor((goldballcount / parseInt(data[i].a1))) + "</span>)</div>";
                gminhtml += "</div>";
            }
            $(".gift_zp_center").html(gminhtml);
            var $scrollbar = $('.gift_zp_src').find('.scrollbar');
            $('.gift_zp_src').sly({itemNav: 'basic', scrollBy: 1, scrollBar: $scrollbar, dynamicHandle: 1});

            $(".gift_zp_sritemb,.gift_zp_sritem").on({
                mouseover: function() {
                    if ($(this).attr("tid") != "") {
                        showtipbox($(this), $(this).attr("tid"));
                    }
                }, /*会在鼠标移入对象时触发*/
                mouseout: function() {
                    removetipbox();
                }, /*在鼠标从元素上离开后会触发*/
                click: function() {
                }
            });
            /*领取奖励*/
            $('.gift_zp_rbtn,.gift_zp_rbtnb').on({
                click: function() {
                    lingqu($(this).attr("tid"), $(this).attr("nid"));
                }
            });
            /*返回*/
            $('.gift_zp_rebtn').on({
                click: function() {
                    initHtml();
                }
            });

        }, 'json');
    }
    /*领取具体奖励*/
    function lingqu(ballc, nid) {
        $.post("data/prochandler.ashx", {"type": "Act_TurnTable_UseGolden", "ball": ballc}, function(data) {
            if (data[0].ret == "-1") {
                showinfo("系统错误");
            } else if (data[0].ret == "-2") {
                showinfo("金球数量不足");
            } else if (data[0].ret == "-2") {
                showinfo("不存在该奖励");
            } else {
                for (var i = 1; i < 7; i++) {
                    if ($(".gift_zp_rbtn" + i)) {
                        if (parseInt(data[0].a1) - parseInt($(".gift_zp_rbtn" + i).attr("tid")) >= 0) {
                            $(".gift_zp_rbtn" + i).addClass("btn_gs").removeClass("btn_off_s");
                            var linqucount = Math.floor(parseInt(data[0].a1) / parseInt($(".gift_zp_rbtn" + i).attr("tid")));
                            $(".gift_zp_rbtn" + i).find("span").text(linqucount);
                        } else {
                            $(".gift_zp_rbtn" + i).off().addClass("btn_off_s").removeClass("btn_gs");
                            $(".gift_zp_rbtn" + i).find("span").text("0");
                        }
                    }
                }
                giftdonghuaty("gift_zp_sr_s" + nid);
            }
        }, 'json');
    }
    /*领取通用动画*/
    function giftdonghuaty(type) {
        var htmlxinshou = "";
        for (var i = 0; i < $("." + type + " img").length; i++) {
            htmlxinshou += "<img  src='" + $('.' + type).find('img').eq(i).attr('src') + "' id ='giveme" + i + "' class='giveme'/>";
        }
        $('#index_main').append(htmlxinshou);
        for (var i = 0; i < $("." + type + " img").length; i++) {
            var theTagLeft = parseInt($("." + type + " img").eq(i).offset().left);
            var theTagTop = parseInt($("." + type + " img").eq(i).offset().top);
            var jleft = parseInt($('.index_info_main').offset().left);
            var jtop = parseInt($('.index_info_main').offset().top);
            theTagLeft = theTagLeft - jleft;
            theTagTop = theTagTop - jtop;
            $("#giveme" + i).css({top: parseInt(theTagTop) + 'px', left: parseInt(theTagLeft) + 'px'});
            //            $("#count_giveme" + i).css({top: parseInt(theTagTop + 45) + 'px', left: parseInt(theTagLeft + 52) + 'px'});
        }
        setTimeout(givemefuc, 1000);
    }
    //十连抽
    function zplianchou(data) {
        if ($(".giftshuoming")[0]) {
            $(".giftshuoming").remove();
        }
        var html = "<div class='shuoming_title'>转盘奖励详情</div>";
        html += "<div class='shuoming_zconter'><div class='shuoming_zconter1'>";
        html += "<table class='gift_zp_jlxq'>";
        var rewardarr = data[0].a1.split("|");
        for (var i = 0; i < rewardarr.length; i++) {
            var rewarditem = rewardarr[i].split(",");
            html += "<tr><td>" + (i + 1) + "、</td><td>" + (rewardarr[i] == "" ? "没有抽到奖励" : rewarditem[1]) + "</td></tr>";
        }
        html += "</table>";
        html += "</div></div>";
        AddBox('huodongjieshao', "转盘奖励", html, null, "gift_huodong"); //语言包:活动说明:
    }
    //重置
    function  zpchongzhi() {
        $.post("data/prochandler.ashx", {"type": "Act_TurnTable_Refresh"}, function(data) {
            switch (data[0].ret + "") {
                case"-1":
                    showinfo("系统错误");
                    break;
                case"-2":
                    showinfo("活动未开启");
                    break;
                case"-3":
//                    var html = "<div class='ply_style'>金币不足,马上充值?</div>";
//                    showmsg('温馨提示', html, '充值', addgold, 'gift_huodong', null, null, 1);
                    jinbibuzu(); //金币不足;
                    break;
                default:
                    showinfo("重置成功", 1000, 0);
                    $('.index_info_gold_2 span').text(data[0].a3);
                    initHtml();
                    break;
            }
        }, "json");
    }
});

posted @ 2014-05-12 10:53  曹桦伟  阅读(343)  评论(0编辑  收藏  举报