index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // 默认显示宠物和医院
  2. $(function(){
  3. setTime();
  4. // 初始化数据
  5. initData();
  6. // 初始化大屏样式
  7. initScreen();
  8. var isFirstLoadding = localStorage.getItem('isFirstLoadding');
  9. // 第一次加载
  10. if (isFirstLoadding === null) {
  11. $('#pets_distribute').attr('checked','checked');
  12. localStorage.setItem('isShowPets',true);
  13. $('#pets_hospital').attr('checked','checked');
  14. localStorage.setItem('isShowHospital',true);
  15. localStorage.setItem('isFirstLoadding',false);
  16. } else {
  17. localStorage.getItem('isShowPets') && $('#pets_distribute').attr('checked','checked');
  18. localStorage.getItem('isShowHospital') && $('#pets_hospital').attr('checked','checked');
  19. }
  20. // 初始化地图
  21. initBdMap();
  22. });
  23. //时间
  24. var timer = null;
  25. function setTime(){
  26. if(timer !== null){
  27. clearTimeout(timer);
  28. }
  29. setTimeout(function () {
  30. $("#date").text(getTime()[0]);
  31. $("#time").text(getTime()[1] +" "+ getTime()[2]);
  32. setTime();
  33. },1000);
  34. }
  35. // 初始化数据
  36. function initData() {
  37. getHospitalData();
  38. getPetData();
  39. getSearchPetsData();
  40. getRecordPetsPieData();
  41. getRecordRankingData();
  42. }
  43. // 初始化大屏
  44. function initScreen() {
  45. $('#position_left').text() && $('#position_left').html('');
  46. $('#position_top').text() && $('#position_top').html('');
  47. $('#position_right').text() && $('#position_right').html('');
  48. // 头部导航
  49. initTopNav();
  50. // 上牌排名
  51. initRecordRank();
  52. // 数据统计
  53. initStatistics();
  54. // 备案宠物品种统计
  55. initRecordPetsPie();
  56. // 寻宠轮播
  57. initSearchPets();
  58. // 初始化tips
  59. initStyle();
  60. }
  61. // 窗口尺寸改变
  62. $(window).resize(function(e){
  63. initStyle();
  64. });
  65. // 设置悬浮图标Css
  66. function initStyle() {
  67. var window_w = $(window).width();
  68. var position_left_w = $('#position_left').width();
  69. var position_right_w = $('#position_right').width();
  70. if ( window_w < 1200 + 40 ) {
  71. $('#position_top').css({left:"10px",width:"99%"});
  72. $('#position_left').css({top:"150px"});
  73. $('#position_right').css({top:"150px"});
  74. } else {
  75. $('#position_top').css({left: (position_left_w + 20) +"px",width: (window_w - position_left_w - position_right_w - 40) +"px"});
  76. $('#position_left').css({top:"90px"});
  77. $('#position_right').css({top:"90px"});
  78. }
  79. $('#cityOpt').css({left:(position_left_w + 20) +"px"});
  80. }
  81. // 显示/隐藏城市
  82. function showCityOpt() {
  83. $('#cityOpt').show();
  84. }
  85. function hideCityOpt() {
  86. $('#cityOpt').hide();
  87. }
  88. // 寻宠轮播
  89. setInterval(function(){
  90. var times = searchPetsData.length;
  91. if (times <= 1) {
  92. return;
  93. }
  94. $('#pets-carousel-item'+searchPetsIndex).hide();
  95. searchPetsIndex++;
  96. if (searchPetsIndex == times) {
  97. searchPetsIndex = 0;
  98. }
  99. $('#pets-carousel-item'+searchPetsIndex).show();
  100. },searchPetsInterval * 1000);
  101. // 全屏模式
  102. function fullScreen() {
  103. var e = document.documentElement
  104. , a = e.requestFullScreen || e.webkitRequestFullScreen || e.mozRequestFullScreen || e.msRequestFullscreen;
  105. "undefined" != typeof a && a && a.call(e)
  106. }
  107. function exitScreen() {
  108. document.documentElement;
  109. document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitCancelFullScreen ? document.webkitCancelFullScreen() : document.msExitFullscreen && document.msExitFullscreen()
  110. }
  111. $('.nav-full-screen').on('click',function(e){
  112. var a = "nav-icon-screen-full"
  113. , t = "nav-icon-screen-restore";
  114. $(this).hasClass(a) ? (fullScreen(),$(this).addClass(t).removeClass(a).attr('src',compbase + '/icon/min-screen.png')) : (exitScreen(),$(this).addClass(a).removeClass(t).attr('src',compbase + '/icon/full-screen.png'));
  115. });
  116. // 显示/隐藏宠物覆盖物
  117. $(document).on('click','#pets_distribute',function(){
  118. var isChecked = $(this).attr('checked');
  119. if (isChecked) {
  120. $(this).removeAttr('checked');
  121. localStorage.removeItem('isShowPets');
  122. } else {
  123. $(this).attr('checked','checked');
  124. localStorage.setItem('isShowPets',true);
  125. }
  126. initBdMap();
  127. });
  128. // 显示/隐藏宠物医院覆盖物
  129. $(document).on('click','#pets_hospital',function(){
  130. var isChecked = $(this).attr('checked');
  131. if (isChecked) {
  132. $(this).removeAttr('checked');
  133. localStorage.removeItem('isShowHospital');
  134. } else {
  135. $(this).attr('checked','checked');
  136. localStorage.setItem('isShowHospital',true);
  137. }
  138. initBdMap();
  139. });
  140. // 切换城市
  141. $(document).on('click','.city-choose',function(e){
  142. var cityid = $(this).data('cityid');
  143. cityData.some(function(item1){
  144. if (item1.id == cityid) {
  145. curCityInfo = item1;
  146. return true;
  147. }
  148. item1.sub && item1.sub.some(function(item2){
  149. if (item2.id == cityid) {
  150. curCityInfo = item2;
  151. return true;
  152. }
  153. })
  154. });
  155. localStorage.setItem('curCityInfo',JSON.stringify(curCityInfo));
  156. // 重新加载数据
  157. getHospitalData();
  158. getPetData();
  159. getSearchPetsData();
  160. getRecordPetsPieData();
  161. getRecordRankingData();
  162. initScreen();
  163. initBdMap();
  164. });