record_v3.0.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. window.staticImg = "http://static.lolbox.duowan.com/images";
  2. $(function() {
  3. var recordDetailTpl = __inline("../tpl/recordDetail.tmpl");
  4. var recordDataLayerTpl = __inline("../tpl/recordDataLayer.tmpl");
  5. var boxContentTpl = __inline("../tpl/boxContent.tmpl");
  6. var Record = function() {
  7. this.baseUrl = "http://api.lolbox.duowan.com/api/v3/player/";
  8. this.boxServerName = encodeURIComponent($.cookie("boxServerName"));
  9. this.boxPlayerName = encodeURIComponent($.cookie("boxPlayerName"));
  10. this.serverName = encodeURIComponent(getURLParam("serverName"));
  11. this.playerName = encodeURIComponent(getURLParam("playerName"));
  12. this.historyId = getURLParam("historyId");
  13. this.gameZone = getURLParam("gameZone");
  14. this.userId = getURLParam("userId");
  15. this.boxUserId = $.cookie("boxUserId");
  16. this.championId = getURLParam("championId");
  17. this.hero = getURLParam("hero");
  18. this.favorate = 0;
  19. this.suffix = "&serverName=" + this.serverName + "&playerName=" + this.playerName;
  20. if(this.hero) this.suffix += "&hero=" + this.hero;
  21. this.p = 1;//页码
  22. this.listData = null;//缓存list列表数据到本地
  23. this.$loading = $("#loading");
  24. this.$boxContent = $(".recent-record__list");
  25. this.$recordDetail = $("#recordDetail");
  26. this.$recordDataLayer = $("#recordDataLayer");
  27. this.$collect = $("#collect");
  28. this.$recordTarget = $("#recordTarget");
  29. this.$body = $("body");
  30. this.$wanScriptName = $("#wanScriptName");
  31. this.navStatus = 1; // 默认个人成就
  32. //饼图默认设置
  33. this.highchartsOpts = {
  34. chart: {
  35. type: 'pie'
  36. },
  37. plotOptions: {
  38. series: {
  39. dataLabels: {
  40. enabled: false
  41. }
  42. }
  43. },
  44. tooltip: {
  45. enabled:false
  46. },
  47. drilldown: {
  48. series: null
  49. }
  50. };
  51. this.init();
  52. };
  53. Record.prototype = {
  54. constructor: Record,
  55. init: function() {
  56. var self = this;
  57. self.bindEvents();
  58. self._getListData();
  59. $('#modeTabs>li').each(function(item) {
  60. var pageName = $(this).data('name');
  61. $(this).find('a').attr('href', pageName + '.html?serverName=' + self.serverName + '&playerName=' + self.playerName + '&userId=' + self.userId + '&gameZone=' + self.gameZone);
  62. });
  63. // 非本人才显示返回按钮
  64. if ( this.boxUserId != this.userId ) {
  65. $('.common-page__goBack').css('visibility', 'visible');
  66. }
  67. },
  68. // 事件绑定
  69. bindEvents: function() {
  70. var self = this;
  71. //我的收藏/TA的收藏r
  72. this.$collect.on('click', function(e) {
  73. e.preventDefault();
  74. var filterData = [];
  75. for(var i=0,len=self.listData.length;i<len;i++) {
  76. var item = self.listData[i];
  77. if(item.collect) {
  78. filterData.push(item);
  79. }
  80. }
  81. self.listData = filterData;
  82. var renderArr = filterData.slice(0, 8);
  83. self.$recordDetail.html('');
  84. self._renderList(renderArr);
  85. });
  86. //分页上一页、下一页点击
  87. this.$body.delegate(".zj-page .zj-s", "click", function(e) {
  88. e.preventDefault();
  89. var page = $(this).attr("data-page");
  90. if(page == 0 || page == (self.totalPage + 1)) return;
  91. self.p = page;
  92. self._renderList(self.listData.slice((page - 1) * 7, page * 7));
  93. });
  94. //分页点击去到哪一页
  95. this.$body.delegate(".zj-page .go-page", "click", function(e) {
  96. e.preventDefault();
  97. var page = $(".zj-cur").val();
  98. if(page <= 0 || page >= (self.totalPage + 1)) return;
  99. self.p = page;
  100. self._renderList(self.listData.slice((page - 1) * 7, page * 7));
  101. });
  102. //enter
  103. this.$body.delegate(".zj-page .zj-cur", "keyup", function(e) {
  104. if(event.keyCode==13) {
  105. var page = $(this).val();
  106. if(page <= 0 || page >= (self.totalPage + 1)) return;
  107. self.p = page;
  108. self._renderList(self.listData.slice((page - 1) * 8, page * 8));
  109. }
  110. });
  111. //点击左边栏li item时拿到其matchId并获取其对应detail数据
  112. this.$body.delegate(".l-box .recent-list li", "click", function(e) {
  113. e.preventDefault();
  114. var id = $(this).attr("data-id"),
  115. name = $(this).attr("data-name"),
  116. enname = $(this).attr("data-enname");
  117. $(this).addClass("hover").siblings().removeClass("hover");
  118. self.matchId = id;
  119. self._getDetailDataDone(id, name, enname);
  120. });
  121. //收藏/取消收藏
  122. this.$body.delegate(".fav-btn", "click", function(e) {
  123. e.preventDefault();
  124. e.stopPropagation();
  125. var _this = this;
  126. var isAdd = $(this).hasClass("add-fav");
  127. var action = isAdd ? 'collect' : 'delete';
  128. var id = $(this).attr("data-id");
  129. var url = "http://api.lolbox.duowan.com/api/v2/player/" + self.gameZone + "/" + self.userId + "/game/" + action + "/?game_id=" + id;
  130. $.ajax({
  131. url: url,
  132. type: 'get',
  133. dataType: 'jsonp',
  134. success: function(result) {
  135. if ( result ) {
  136. if( isAdd ) {
  137. $( _this ).removeClass("add-fav").addClass("fav").attr("title", "点击删除此收藏");
  138. } else {
  139. if( confirm('确认删除此收藏吗?') ) {
  140. $( _this ).removeClass("fav").addClass("add-fav").attr("title", "点击收藏比赛");
  141. }
  142. }
  143. }
  144. }
  145. });
  146. });
  147. this.$body.delegate(".zj-table tr a", "click", function(e) {
  148. var userid = $(this).attr("user-id");
  149. var sn = $(this).attr("game-zone");
  150. var pn = $(this).attr("data-playerName");
  151. if(!userid || userid == 0) {
  152. location.href = 'http://lolbox.duowan.com/staticPub/v3.1/playerList.html?sn=' + sn + '&pn=' + encodeURIComponent(pn);
  153. return false;
  154. }
  155. })
  156. // 详细战绩&个人成就导航
  157. this.$body.delegate(".record-nav li", "click", function(e) {
  158. e.preventDefault();
  159. e.stopPropagation();
  160. self.navStatus = $(this).index(); // 记录导航状态
  161. var tab = $(this).data('tab');
  162. $(this).addClass('active').siblings().removeClass('active');
  163. $('.tab-content').hide();
  164. $('#' + tab).show();
  165. // 导航点击统计
  166. var curIndex = $(this).index();
  167. var StatId = [
  168. {'id': 'click/grzj', 'desc': '点击/个人战绩'},
  169. {'id': 'click/xxzj', 'desc': '点击/详细战绩'}
  170. ];
  171. try{
  172. window.external.data_report( StatId[curIndex].id, StatId[curIndex].desc );
  173. }catch(e){}
  174. });
  175. // 返回上一页
  176. $('.common-page__goBack').on('click', function() {
  177. window.history.back();
  178. return false;
  179. });
  180. // 刷新按钮
  181. $('.common-page__reflash').on('click', function() {
  182. location.reload();
  183. });
  184. /*鼠标悬浮在用户头像的弹窗*/
  185. $(document).on('mouseenter', '.history-recordTab__userIcon', function() {
  186. self.userRecordDetail();
  187. }).on('mouseleave', '.history-recordTab__userIcon', function() {
  188. setTimeout(function() {
  189. var isHover = $('.userRecordDetail').hasClass('hover');
  190. if ( !isHover ) {
  191. $('.userRecordDetail').hide();
  192. }
  193. }, 0.5*1000)
  194. });
  195. $(document).on('mouseenter', '.userRecordDetail', function() {
  196. $(this).addClass('hover');
  197. }).on('mouseleave', '.userRecordDetail', function() {
  198. $(this).removeClass('hover').hide();
  199. });
  200. // 近期战绩下拉筛选列表 - 导航
  201. $(document).on('click', '.recent-nav__input', function() {
  202. $(this).toggleClass('on');
  203. $('.recent-nav__list').toggle();
  204. })
  205. // 近期战绩下拉筛选列表 - 选项
  206. $(document).on('click', '.recent-nav__list li', function(e) {
  207. e.preventDefault();
  208. var key = $(this).find('a').html();
  209. $('.recent-nav__input')
  210. .removeClass('on')
  211. .find('.key').html(key);
  212. $('.recent-nav__list').hide();
  213. self._getListData(key);
  214. })
  215. },
  216. // 获取左侧比赛列表
  217. _getListData: function(type) {
  218. var self = this;
  219. var game_type = {'匹配赛': 3, '排位赛': 4, '大乱斗': 6};
  220. var url = this.baseUrl + this.gameZone + '/'+this.userId+'/game_recent/';
  221. var args = {};
  222. self.championId && ( args.champion_id = self.championId );
  223. game_type[type] && ( args.game_type = game_type[type] );
  224. $.ajax({
  225. url: url,
  226. data: args,
  227. type: 'GET',
  228. dataType: 'jsonp',
  229. success: function(data, status, xhr) {
  230. if (xhr && xhr.status && xhr.status == 200) {
  231. var list = data.game_list;
  232. var renderArr = list.slice(0, 7);
  233. self.isSelf = data.is_myself;
  234. self.listData = list;
  235. self.totalPage = Math.ceil(list.length / 7);
  236. self._renderList(renderArr);
  237. //从数组第一个元素中获取到serverName的中文名
  238. var sn_cn = list[0] ? list[0].game_zone.alias : null;
  239. var crumbs = sn_cn ? decodeURIComponent(self.playerName) + "(" + sn_cn + ")" : decodeURIComponent(self.playerName);
  240. self.$recordTarget.attr("href", "playerDetail.html?serverName=" + self.serverName + "&playerName=" + self.playerName + "&userId=" + self.userId + "&gameZone=" + self.gameZone)
  241. .html(crumbs);
  242. }
  243. }
  244. });
  245. },
  246. // 获取玩家比赛详情
  247. _getDetailData: function(id) {
  248. var url = this.baseUrl + this.gameZone + "/"+this.userId+"/game/"+ id + '/';
  249. return $.ajax({
  250. url: url,
  251. type: 'GET',
  252. dataType: 'jsonp'
  253. });
  254. },
  255. _getDetailDataDone: function(id, name, enname) {
  256. var self = this;
  257. this.$loading.show();
  258. self.$recordDetail.hide();
  259. this._getDetailData(id).done(function(data) {
  260. self._renderDetail(data, name, enname);
  261. self.$loading.hide();
  262. self.$recordDetail.show();
  263. }).fail(function() {
  264. self.$loading.hide();
  265. self.$recordDetail.show();
  266. });
  267. },
  268. /*渲染左侧的战绩列表*/
  269. _renderList: function(data) {
  270. var self = this;
  271. // 左侧列表渲染
  272. data.totalPage = self.totalPage;
  273. data.p = self.p;
  274. data.isSelf = self.isSelf;
  275. self.$boxContent.html(boxContentTpl({data: data}));
  276. // 历史战绩对应详情初始化
  277. if(data && data.length > 0) {
  278. if ( self.historyId ) {
  279. getHistoryData(self.historyId);
  280. }else{
  281. getHistoryData(0);
  282. }
  283. }
  284. // 获取左侧第N个li历史战绩数据
  285. function getHistoryData(index) {
  286. var champion = data[index].champion,
  287. enname = champion.name,
  288. name = champion.display_name.concat(champion.title);
  289. self.matchId = data[index].game_id;
  290. self._getDetailDataDone(self.matchId, name, enname);
  291. $('.recent-list li').eq(index).addClass('hover');
  292. }
  293. },
  294. /*渲染历史战绩 - 个人成就*/
  295. _renderDetail: function(data, name, enname) {
  296. var template, self = this;
  297. if(data.player_game_list) {
  298. // 模板渲染
  299. this.$recordDetail.html(recordDetailTpl({data: data}));
  300. this.$recordDataLayer.html(recordDataLayerTpl({data: data}));
  301. // 显示显示默认或记录的导航位置
  302. $('.record-nav li').eq(self.navStatus).click();
  303. // 获取推荐视频
  304. self.positionRender(data.player_game_list[0]);
  305. // 显示广告
  306. $(".ad-wrap").show();
  307. } else {
  308. template = "<div class='tip-no-data'><img src='img/clothes-commit-fail.png'><p>由于未知原因,此场比赛消失在遥远的二次元空间中。</p></div>";
  309. this.$recordDetail.html(template);
  310. }
  311. },
  312. // 位置数据渲染
  313. positionRender: function(data) {
  314. // 位置计算
  315. var position_map = {'is_support': '辅助', 'is_adc': '输出', 'is_jungler': '打野'};
  316. var loseData = data.team_lose.player_champions;
  317. var allData = data.team_win.player_champions.concat(loseData); //输的和赢的数据合并
  318. var userId = encodeURIComponent(getURLParam("userId"));
  319. var key = getPositionKey(allData);
  320. $('.historyRecord-userInfo__position').html(position_map[key]);
  321. // 遍历战绩
  322. function getPositionKey(o) {
  323. for (var i = 0; i < o.length; i++) {
  324. var itemUserId = o[i].player.user_id;
  325. if ( userId == itemUserId ) {
  326. if ( o[i].is_jungler ) {
  327. return 'is_jungler';
  328. break;
  329. }
  330. if ( o[i].is_support ) {
  331. return 'is_support';
  332. break;
  333. }
  334. if ( o[i].is_adc ) {
  335. return 'is_adc';
  336. break;
  337. }
  338. }
  339. }
  340. }
  341. return position_map[key];
  342. },
  343. /*
  344. * @ 历史战绩-个人战绩TAB详细战绩弹窗
  345. * @ 注意!!!这里有坑,数据是来自详细战绩弹窗
  346. */
  347. userRecordDetail: function() {
  348. var self = this;
  349. var userName = decodeURIComponent(self.playerName).replace(/(^\s+)|(\s+$)/g,"");
  350. var recordList = $('.data-layer .layer');
  351. /*从历史战绩-个人战绩TAB #data-layer列表中拿到弹窗数据*/
  352. for (var i = 0; i < recordList.length; i++) {
  353. var listName = $(recordList[i]).find('.tip-user-name').text().replace(/(^\s+)|(\s+$)/g,"");
  354. if ( userName == listName.replace(/^\s+/,"") ) {
  355. var dom = $(recordList[i]).html();
  356. $('.userRecordDetail-con').html(dom);
  357. getUserLevel();
  358. break;
  359. }
  360. }
  361. /*获取用户段位*/
  362. function getUserLevel() {
  363. $.ajax({
  364. url: 'http://api.lolbox.duowan.com/api/v2/player/'+ self.gameZone+'/'+ self.userId+'/',
  365. dataType: 'jsonp',
  366. success: function(o) {
  367. var data = o && o.player_list && o.player_list[0];
  368. var tierRank = data.tier_rank, tierName;
  369. if (tierRank && tierRank['tier'] && tierRank['tier']['const'] > 0) {
  370. tierName = tierRank['tier']['name_cn'] + ' ' + tierRank['rank']['name'];
  371. } else {
  372. tierName = '-';
  373. }
  374. var dom = '<div class="tip-level"></div><div class="tip-topright"><p><em class="zj-zdl zj-s"></em>' + data.box_score + '</p><p class="zj-blue">' + tierName + '</p></div>';
  375. $('.userRecordDetail .tip-topright-wrap').html(dom);
  376. $('.userRecordDetail').show();
  377. }
  378. });
  379. }
  380. }
  381. };
  382. // URL解析
  383. function getURLParam(name) {
  384. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  385. return value ? decodeURIComponent(value[1]) : value;
  386. }
  387. // 删除字符串空格
  388. function Trim(str,is_global){
  389. var result;
  390. result = str.replace(/(^\s+)|(\s+$)/g,"");
  391. if(is_global.toLowerCase()=="g")
  392. result = result.replace(/\s/g,"");
  393. return result;
  394. }
  395. new Record();
  396. });