var domain = 'https://mo.youzu.com'; var version = '001'; var homeUrl = 'https://home.youzu.com'; var account = ''; $('').appendTo("body"); $('').appendTo("body"); $('').appendTo("body"); $('').appendTo("body"); $('').appendTo("body"); var code_pop_win = { defaultSetting : {'app_id' : '', 'server_id' : 0}, api_host : domain, account : account, game_id : 0, op_id : 0, content : '', role : null, roleList : {}, server: null, serverList : {}, status : true, init: function(settings) { var tem = []; tem.push('
'); tem.push('
'); tem.push('
'); tem.push('礼包兑换'); tem.push(''); tem.push(''); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push(''); tem.push('请选择服务器'); tem.push('
'); tem.push('
'); tem.push(''); tem.push('请选择角色'); tem.push('
'); tem.push('
'); tem.push(''); tem.push('请输入礼包码'); tem.push('
'); tem.push('
'); tem.push(''); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
领取说明:
'); tem.push('
'); tem.push('

1. 只限于appstore官方渠道玩家使用;

'); tem.push('

2. 新建角色24小时后才可使用;

'); tem.push('

若有疑问请联系客服:400 668 9919

'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('
'); tem.push('

兑换成功!

'); tem.push('

请登录游戏查看奖励。友情提示:毎一个礼包码只能使用一次

'); tem.push('确定'); tem.push('
'); tem.push('
'); tem.push('

兑换失败!

'); tem.push('

该礼包码已经被使用过。

'); tem.push('确定'); tem.push('
'); tem.push('
'); tem.push('

友情提示

'); tem.push('

该礼包码已经被使用过。

'); tem.push('确定'); tem.push('
'); this.content = tem.join(""); $('body').append(this.content); this.role = $('#yzlrPop-role').select2(); this.server = $('#yzlrPop-server').select2(); $('#yzlrPop').addClass('yzlrShow') $.extend(this.defaultSetting, settings); if(!this.defaultSetting.app_id) { console.log('缺少app_id参数'); return; }else{ this.getAppInfo(this.defaultSetting.app_id); } }, getAppInfo: function(app_id){ var _this = this; $.ajax({ url : _this.api_host + '/youzu/code/getappinfo', type : 'get', data : {'appid':app_id}, dataType :'jsonp', async: false, success : function(data){ if(data.code != 0){ console.log(data.msg); _this.status = false; }else{ _this.game_id = data.data.game_id; _this.op_id = data.data.op_id; _this.bind(); _this.getServer(); } }, }); }, getServer: function(){ if(!this.checkStatus()){ return false; } console.log('开始获取区服数据'); //this.op_id=1;this.game_id=193;this.account='15037617820200003747'; var _this = this; getServerList(_this.op_id,_this.game_id,_this.account, function(data, code){ console.log(data); console.log('获取区服数据结束'); if(code == 1 || code == 401){ var serverList = []; for(i in data){ var name = data[i].server_name; var roleNames = []; for(k in data[i].roleInfo){ if(typeof(data[i].roleInfo[k].role_name) != 'undefined'){ roleNames.push(data[i].roleInfo[k].role_name); } } if(roleNames.length > 0){ name = name+'('+roleNames.join(',')+')'; } serverList.push({'id':data[i].server_id, 'text':name}); } _this.serverList = serverList; _this.server.select2({data:_this.serverList}); if(_this.defaultSetting.server_id) { _this.server.val(_this.defaultSetting.server_id).trigger("change"); } }else{ var errWin = $('#sysError'); errWin.children('.popCont').text('获取区服列表失败'); errWin.show(); _this.status = false; } }); }, checkStatus: function(){ return this.status; }, bind: function(){ var _this = this; var allowPost = true; $('#yzlrPop-close').on('click', function(){ $('#yzlrPop').removeClass('yzlrShow') }); //获取角色列表 this.server.on("change", function (e) { var id = $(this).val(); if(id < 1){ return; } console.log('获取服务器角色'); getServerRole(_this.op_id,_this.game_id,_this.account, id, function(data, code){ _this.role.val(0).trigger('change'); var tmp = _this.role.children('option:first'); _this.role.empty().append(tmp); if(code == 1){ $("#ori_role_account").val(_this.account); var roleList = []; for(i in data){ roleList.push({id:data[i].role_id, text:data[i].role_name}); } _this.role.select2({data:roleList}); if(data.length == 1){ _this.role.val(data[0].role_id).trigger("change"); } }else{ _this.status = false; var errWin = $('#sysError'); errWin.children('.popCont').text('未查询到角色信息'); errWin.show(); } }); }); //提交 $('#js-getCode').on('click', function(){ if(!allowPost){ return; } var server_id = _this.server.val(); var role_id = _this.role.val(); var ori_role_account = $("#ori_role_account").val(); var code = $('#yzlrPop-code').val();console.log(server_id + ' '+role_id+' '+code) console.log(server_id+' '+role_id+' '+code) if(server_id < 1){ $('#server-error').html('请选择服务器').addClass('yzlrIn'); return; }else{ $('#server-error').removeClass('yzlrIn'); } if(role_id < 1){ $('#role-error').html('请选择角色').addClass('yzlrIn'); return; }else{ $('#role-error').removeClass('yzlrIn'); } if(!code){ $('#code-error').html('请输入礼包码').addClass('yzlrIn'); return; }else{ $('#code-error').removeClass('yzlrIn'); } allowPost = false; $.ajax({ url : _this.api_host + '/youzu/Code/sendgift', type : 'get', dataType : 'jsonp', data : {server_id:server_id, role_id:role_id, code:code, game_id:_this.game_id, op_id:_this.op_id,ori_role_account:ori_role_account}, async: false, jsonp : "callback", //jsonpCallback :"success_jsonpCallback", success :function(data){ allowPost = true; if(data.code === 0){ $('#success').show(); $('#yzlrPop-code').val(''); }else{ $('#fail').children('.popCont').text(data.msg); $('#fail').show(); } } }); }); } }; function closeSelf(e){ e.parent().hide(); }