tongji.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. (function () {
  2. var custmerform = {};
  3. var $scroll = '';
  4. var chartMap = {};
  5. // 图表数据
  6. function chart(data, $page) {
  7. if (data.length > 0) {
  8. chartMap = {};
  9. $.each(data, function (_index, _item) {
  10. var _html = '\
  11. <div class="lr-black-panel">\
  12. <div class="lr-title">'+ _item.F_Name + '</div>\
  13. <div class="lr-content lr-chart-content">\
  14. <div class="lr-chart-container" id="'+ _item.F_Id + '" data-desktop="' + _item.F_Type + '" ></div>\
  15. </div>\
  16. </div>';
  17. $page.find('#lr_desktop_msg_content').append(_html);
  18. chartMap[_item.F_Id] = echarts.init(document.getElementById(_item.F_Id));
  19. // 获取后台数据
  20. var data = '{"Id":"1064e045-f075-42a2-8431-ba717e1539b3","value":[{"name":"2017.07.13","value":9000.00},{"name":"2017.08.11","value":100900.00},{"name":"2017.09.25","value":0.00},{"name":"2018.04.03","value":100.00},{"name":"2018.05.21","value":2.00}]}';
  21. //learun.httpget("", { type: 'chart', id: _item.F_Id }, function(data) {
  22. data = JSON.parse(data);
  23. if (data) {
  24. var type = $('#' + data.Id).attr('data-desktop');
  25. var legendData = [];
  26. var valueData = [];
  27. $.each(data.value, function (_index, _item) {
  28. legendData.push(_item.name);
  29. valueData.push(_item.value);
  30. });
  31. var option = {};
  32. option.tooltip = {
  33. trigger: 'item',
  34. formatter: "{a} <br/>{b}: {c} ({d}%)"
  35. };
  36. console.log(option.tooltip);
  37. option.legend = {
  38. orient: 'vertical',
  39. left: 'left',
  40. data: legendData
  41. };
  42. console.log(option.legend);
  43. option.series = [{
  44. name: '占比',
  45. type: 'pie',
  46. radius: ['50%', '70%'],
  47. avoidLabelOverlap: false,
  48. label: {
  49. normal: {
  50. show: false,
  51. position: 'center'
  52. },
  53. emphasis: {
  54. show: true,
  55. textStyle: {
  56. fontSize: '30',
  57. fontWeight: 'bold'
  58. }
  59. }
  60. },
  61. labelLine: {
  62. normal: {
  63. show: false
  64. }
  65. },
  66. data: data.value
  67. }];
  68. console.log(option.series);
  69. option.color = ['#df4d4b', '#304552', '#52bbc8', 'rgb(224,134,105)', '#8dd5b4', '#5eb57d', '#d78d2f'];
  70. console.log(option);
  71. chartMap[data.Id].setOption(option);
  72. }
  73. //});
  74. });
  75. }
  76. }
  77. // 统计数据
  78. function target(data, $page) {
  79. if (data.length > 0) {
  80. var _html = '\
  81. <div class="lr-black-panel">\
  82. <div class="lr-title">统计数据</div>\
  83. <div class="lr-content lr-flex-content">\
  84. </div>\
  85. </div>';
  86. $page.find('#lr_desktop_msg_content').append(_html);
  87. //var $content = $desktop.find('.lr-flex-content');
  88. $.each(data, function (_index, _item) {
  89. var _itemHtml = '\
  90. <div class="targetItem">\
  91. <div class="name">'+ _item.F_Name + '</div>\
  92. <div class="number" data-number="'+ _item.F_Id + '" ></div>\
  93. </div>';
  94. $('#lr_desktop_msg_content').find('.lr-flex-content').append(_itemHtml);
  95. //$content.append(_itemHtml);
  96. // 获取后台数据
  97. learun.httpget(config.webapi + "learun/adms/desktop/data", { type: 'Target', id: _item.F_Id }, function(data){
  98. if (data) {
  99. $('[data-number="' + data.Id + '"]').text(data.value);
  100. }
  101. });
  102. });
  103. }
  104. }
  105. function refreshDeskTop($page) {
  106. learun.clientdata.get('desktop', {
  107. callback: function (data) {
  108. //var $desktop = $('#lr_desktop_msg_content');
  109. //$desktop.html('');
  110. chart(data.chart || [], $page);
  111. target(data.target || [], $page);
  112. /*if (self) {
  113. self.refresh(true);
  114. self.endPulldownToRefresh();
  115. }*/
  116. }
  117. });
  118. }
  119. var page = {
  120. init: function ($page) {
  121. // 基础数据初始化
  122. learun.clientdata.init();
  123. refreshDeskTop($page);
  124. $scroll = $page.find('#lr_desktop_msg').pullRefresh({
  125. down: {
  126. height: 30,
  127. contentinit: '下拉可以刷新',
  128. contentdown: '下拉可以刷新',
  129. contentover: '松开立即刷新',
  130. contentrefresh: '正在刷新...',
  131. callback: function () {
  132. refreshDeskTop($page);
  133. }
  134. }
  135. });
  136. // 加载功能列表
  137. learun.clientdata.get('module', {
  138. callback: function (data) {
  139. learun.myModule.get(data, function (myModules) {
  140. var mylen = parseInt((myModules.length + 1) / 4) + ((myModules.length + 1) % 4 > 0 ? 1 : 0);
  141. switch (mylen) {
  142. case 1:
  143. $page.find('.lr-workspace-page').css('padding-top', '210px');
  144. break;
  145. case 2:
  146. $page.find('.lr-workspace-page').css('padding-top', '290px');
  147. break;
  148. case 3:
  149. $page.find('.lr-workspace-page').css('padding-top', '370px');
  150. break;
  151. }
  152. var map = {};
  153. $.each(data, function (_index, _item) {
  154. map[_item.F_Id] = _item;
  155. });
  156. var $appbox = $page.find('.appbox');
  157. var $last = null;
  158. $.each(myModules, function (_index, _id) {
  159. var item = map[_id];
  160. if (item) {
  161. var _html = '\
  162. <div class="appitem appitem2" data-value="'+ item.F_Id + '">\
  163. <div><i class="'+ item.F_Icon + '"></i></div>\
  164. <span>'+ item.F_Name + '</span>\
  165. </div>';
  166. var _$html = $(_html);
  167. _$html[0].item = item;
  168. if ($last === null) {
  169. $appbox.prepend(_$html);
  170. }
  171. else {
  172. $last.after(_$html);
  173. }
  174. $last = _$html;
  175. }
  176. });
  177. $last = null;
  178. });
  179. }
  180. });
  181. },
  182. reload: function ($page, pageinfo) {
  183. if (learun.isOutLogin) {// 如果是重新登录的情况刷新下桌面数据
  184. learun.isOutLogin = false;
  185. refreshDeskTop($page);
  186. learun.clientdata.clear('module');
  187. learun.myModule.states = -1;
  188. }
  189. // 加载功能列表
  190. learun.clientdata.get('module', {
  191. callback: function (data) {
  192. learun.myModule.get(data, function (myModules) {
  193. var mylen = parseInt((myModules.length + 1) / 4) + ((myModules.length + 1) % 4 > 0 ? 1 : 0);
  194. switch (mylen) {
  195. case 1:
  196. $page.find('.lr-workspace-page').css('padding-top', '210px');
  197. break;
  198. case 2:
  199. $page.find('.lr-workspace-page').css('padding-top', '290px');
  200. break;
  201. case 3:
  202. $page.find('.lr-workspace-page').css('padding-top', '370px');
  203. break;
  204. }
  205. var map = {};
  206. $.each(data, function (_index, _item) {
  207. map[_item.F_Id] = _item;
  208. });
  209. var $appbox = $page.find('.appbox');
  210. var $last = null;
  211. $appbox.find(".appitem2").remove();
  212. $.each(myModules, function (_index, _id) {
  213. var item = map[_id];
  214. if (item) {
  215. var _html = '\
  216. <div class="appitem appitem2" data-value="'+ item.F_Id + '">\
  217. <div><i class="'+ item.F_Icon + '"></i></div>\
  218. <span>'+ item.F_Name + '</span>\
  219. </div>';
  220. var _$html = $(_html);
  221. _$html[0].item = item;
  222. if ($last === null) {
  223. $appbox.prepend(_$html);
  224. }
  225. else {
  226. $last.after(_$html);
  227. }
  228. $last = _$html;
  229. }
  230. });
  231. $last = null;
  232. });
  233. }
  234. });
  235. $.each(chartMap, function (id, obj) {
  236. obj.resize();
  237. });
  238. }
  239. };
  240. return page;
  241. })();