nxreportCtrl.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. 'use strict';
  2. app.controller('nxreportCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "moment", "SweetAlert", "Restangular", "api_report_nx", "api_statistic", function($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, moment, SweetAlert, Restangular, api_report_nx, api_statistic) {
  3. $scope.parameters = {};
  4. $scope.hearderlist = [];
  5. $scope.pielenddata = [];
  6. $scope.piebodydata = [];
  7. $scope.barlenddata = [];
  8. $scope.barbodydata = [];
  9. $scope.categryid = 2;
  10. $scope.sum = 0;
  11. $scope.startlist = { id: 2, label: "事件总数&分类统计报告", title: "事件总数", key: "incidentClassify", selected: true };
  12. $scope.nowdata = moment(new Date()).format('YYYY/MM/DD HH:ss:mm');
  13. //时间搜索
  14. // $scope.starttimes = moment(new Date().getTime() - 86400000 * 7).format('YYYY-MM-DD'); //开始时间
  15. // $scope.endtimes = moment(new Date().getTime() - 86400000).format('YYYY-MM-DD'); //结束时间
  16. var weeks = new Date().getDay();
  17. $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYY-MM-DD');
  18. $scope.endtimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYY-MM-DD');
  19. $scope.changeForm = function(paramDateFrom) {
  20. $scope.starttimes = moment(paramDateFrom).format('YYYY-MM-DD');
  21. }
  22. $scope.changeTo = function(paramDateTo) {
  23. $scope.endtimes = moment(paramDateTo).format('YYYY-MM-DD');
  24. }
  25. $scope.parameters.paramDateFrom = $scope.starttimes;
  26. $scope.parameters.paramDateTo = $scope.endtimes;
  27. //高度
  28. setInterval(function() {
  29. if (document.getElementById("DIV3")) {
  30. $scope.listheight = { "min-height": document.getElementById("DIV3").scrollHeight - 20 + "px" };
  31. }
  32. }, 1000)
  33. var downPdf = document.getElementById("exportToPdf");
  34. downPdf.onclick = function() {
  35. html2canvas(
  36. document.getElementById("export_content"), {
  37. dpi: 172, //导出pdf清晰度
  38. onrendered: function(canvas) {
  39. var contentWidth = canvas.width;
  40. var contentHeight = canvas.height;
  41. //一页pdf显示html页面生成的canvas高度;
  42. var pageHeight = contentWidth / 592.28 * 841.89;
  43. //未生成pdf的html页面高度
  44. var leftHeight = contentHeight;
  45. //pdf页面偏移
  46. var position = 0;
  47. //html页面生成的canvas在pdf中图片的宽高(a4纸的尺寸[595.28,841.89])
  48. var imgWidth = 595.28;
  49. var imgHeight = 592.28 / contentWidth * contentHeight;
  50. var pageData = canvas.toDataURL('image/jpeg', 1.0);
  51. var pdf = new jsPDF('', 'pt', 'a4');
  52. //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
  53. //当内容未超过pdf一页显示的范围,无需分页
  54. if (leftHeight < pageHeight) {
  55. pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
  56. } else {
  57. while (leftHeight > 0) {
  58. pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
  59. leftHeight -= pageHeight;
  60. position -= 841.89;
  61. //避免添加空白页
  62. if (leftHeight > 0) {
  63. pdf.addPage();
  64. }
  65. }
  66. }
  67. pdf.save('content.pdf');
  68. },
  69. //背景设为白色(默认为黑色)
  70. background: "#fff"
  71. })
  72. }
  73. //上周
  74. $scope.week = function() {
  75. $scope.searchstate = "week";
  76. var weeks = new Date().getDay();
  77. $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYY-MM-DD');
  78. $scope.endtimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYY-MM-DD');
  79. $scope.parameters.paramDateFrom = $scope.starttimes;
  80. $scope.parameters.paramDateTo = $scope.endtimes;
  81. // $scope.parameters = parseDateParameter($scope.parameters);
  82. $scope.mdxquery();
  83. }
  84. //上月
  85. $scope.month = function() {
  86. $scope.searchstate = "month";
  87. $scope.starttimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth() - 1)).format('YYYY-MM-DD');
  88. $scope.endtimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth()) - 86400000).format('YYYY-MM-DD');
  89. $scope.parameters.paramDateFrom = $scope.starttimes;
  90. $scope.parameters.paramDateTo = $scope.endtimes;
  91. // $scope.parameters = parseDateParameter($scope.parameters);
  92. $scope.mdxquery();
  93. }
  94. //上年
  95. $scope.year = function() {
  96. $scope.searchstate = "year";
  97. $scope.starttimes = moment().startOf('year').format('YYYY-MM-DD');
  98. $scope.endtimes = moment().format('YYYY-MM-DD');
  99. $scope.parameters.paramDateFrom = $scope.starttimes;
  100. $scope.parameters.paramDateTo = $scope.endtimes;
  101. // $scope.parameters = parseDateParameter($scope.parameters);
  102. $scope.mdxquery();
  103. }
  104. /**
  105. *日历
  106. */
  107. $scope.open = function($event) {
  108. $event.preventDefault();
  109. $event.stopPropagation();
  110. $scope.opened = !$scope.opened;
  111. };
  112. $scope.endOpen = function($event) {
  113. $event.preventDefault();
  114. $event.stopPropagation();
  115. $scope.startOpened = false;
  116. $scope.endOpened = !$scope.endOpened;
  117. };
  118. $scope.startOpen = function($event) {
  119. $event.preventDefault();
  120. $event.stopPropagation();
  121. $scope.endOpened = false;
  122. $scope.startOpened = !$scope.startOpened;
  123. };
  124. /***
  125. * 导出
  126. */
  127. $scope.exportData = function() {
  128. // var modelData = $scope.startlist;
  129. // $state.go('childpape', { starttime: $scope.parameters.paramDateFrom, endtime: $scope.parameters.paramDateTo, model: JSON.stringify(modelData) });
  130. // api_report_nx.getPdf({ url: "http://localhost/#/childpape/2018-11-12/2018-11-18/%7B%22id%22:24,%22label%22:%22%E8%B5%84%E4%BA%A7%E5%9C%A8%E5%BA%93%E7%8A%B6%E6%80%81%E7%BB%9F%E8%AE%A1%E6%8A%A5%E5%91%8A%22,%22key%22:%22assetStatus%22,%22level%22:2,%22expanded%22:false,%22uid%22:%220.2409134734491598%22,%22parent_uid%22:%220.23149440146902256%22,%22children%22:%5B%5D,%22classes%22:%5B%22leaf%22%5D,%22selected%22:true%7D" }).then(function(response) {
  131. // var downUrl = api_report_nx.getPdf({ url: "http://localhost/#/childpape/2018-11-12/2018-11-18/%7B%22id%22:24,%22label%22:%22%E8%B5%84%E4%BA%A7%E5%9C%A8%E5%BA%93%E7%8A%B6%E6%80%81%E7%BB%9F%E8%AE%A1%E6%8A%A5%E5%91%8A%22,%22key%22:%22assetStatus%22,%22level%22:2,%22expanded%22:false,%22uid%22:%220.2409134734491598%22,%22parent_uid%22:%220.23149440146902256%22,%22children%22:%5B%5D,%22classes%22:%5B%22leaf%22%5D,%22selected%22:true%7D" }).getRequestedUrl();
  132. // var a = document.createElement('a');
  133. // a.href = downUrl;
  134. // a.target = '_blank';
  135. // // a.download = filename;
  136. // document.body.appendChild(a);
  137. // a.click();
  138. // });
  139. $http({
  140. url: api_report_nx.getPdf().getRequestedUrl(),
  141. method: 'post',
  142. data: { url: "http://localhost/#/childpape/2018-11-12/2018-11-18/%7B%22id%22:24,%22label%22:%22%E8%B5%84%E4%BA%A7%E5%9C%A8%E5%BA%93%E7%8A%B6%E6%80%81%E7%BB%9F%E8%AE%A1%E6%8A%A5%E5%91%8A%22,%22key%22:%22assetStatus%22,%22level%22:2,%22expanded%22:false,%22uid%22:%220.2409134734491598%22,%22parent_uid%22:%220.23149440146902256%22,%22children%22:%5B%5D,%22classes%22:%5B%22leaf%22%5D,%22selected%22:true%7D" },
  143. headers: {
  144. //'Content-type' : 'application/xls',
  145. 'Accept': '*/*'
  146. },
  147. responseType: 'arraybuffer'
  148. }).success(function(data, status, headers, config) {
  149. var file = new Blob([data], {
  150. type: 'application/octet-stream'
  151. });
  152. //trick to download store a file having its URL
  153. var fileURL = URL.createObjectURL(file);
  154. var a = document.createElement('a');
  155. a.href = fileURL;
  156. // window.open(a.href);
  157. a.target = '_blank';
  158. // a.download = filename;
  159. document.body.appendChild(a);
  160. a.click();
  161. }).error(function(data, status, headers, config) {
  162. // console.log(data);
  163. });
  164. }
  165. /**
  166. * 时间搜索
  167. */
  168. $scope.mdxquery = function() {
  169. $scope.parameters.paramDateFrom = moment($scope.parameters.paramDateFrom).format('YYYY-MM-DD');
  170. $scope.parameters.paramDateTo = moment($scope.parameters.paramDateTo).format('YYYY-MM-DD');
  171. if ($scope.startlist.id == 2) {
  172. incidentClassify()
  173. } else if ($scope.startlist.id == 3) {
  174. incidentHandler()
  175. } else if ($scope.startlist.id == 6) {
  176. problemClassify()
  177. } else if ($scope.startlist.id == 7) {
  178. problemHandler()
  179. } else if ($scope.startlist.id == 12) {
  180. changeClassify()
  181. } else if ($scope.startlist.id == 13) {
  182. changeHandler()
  183. } else if ($scope.startlist.id == 16) {
  184. releaseClassify()
  185. } else if ($scope.startlist.id == 17) {
  186. releaseHandler()
  187. } else if ($scope.startlist.id == 22) {
  188. assetClassify()
  189. } else if ($scope.startlist.id == 24) {
  190. assetStatus()
  191. }
  192. }
  193. /**
  194. * 树形列表
  195. */
  196. $scope.my_tree = {};
  197. $scope.my_data = [];
  198. $scope.try_async_load = function() {
  199. $scope.my_data = [
  200. { id: 1, label: "事件报表", children: [{ id: 2, label: "事件总数&分类统计报告", title: "事件总数", key: "incidentClassify", selected: true, }, { id: 3, label: "处理完事件占比", tip1: "完成事件数量", tip2: "事件占比", key: "incidentHandler" }] },
  201. {
  202. id: 5,
  203. label: "问题报表",
  204. children: [{ id: 6, label: "问题总数&分类统计报告", title: "问题总数", key: "problemClassify" }, { id: 7, label: "处理人完成问题占比", tip1: "完成问题数量", tip2: "问题占比", key: "problemHandler" }]
  205. }, {
  206. id: 11,
  207. label: "变更报表",
  208. children: [{ id: 12, label: "变更总数&分类统计报告", title: "变更总数", key: "changeClassify" }, { id: 13, label: "处理人完成变更占比", tip1: "完成变更数量", tip2: "变更占比", key: "changeHandler" }]
  209. }, {
  210. id: 15,
  211. label: "发布报表",
  212. children: [{ id: 16, label: "发布总数&分类统计报告", title: "发布总数", key: "releaseClassify" }, { id: 17, label: "处理人完成发布占比", tip1: "完成发布数量", tip2: "发布占比", key: "releaseHandler" }]
  213. },
  214. { id: 21, label: "资产报表", children: [{ id: 22, label: "资产总金额&分类统计报告", title: "资产总金额", key: "assetClassify" }, { id: 24, label: "资产总量统计报告", title: "资产总量", key: "assetStatus" }] }
  215. ];
  216. $scope.my_tree = angular.copy($scope.my_data);
  217. };
  218. function convertListToTree(data, treeMap) {
  219. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  220. var root = null; //Initially set our loop to null
  221. var parentNode = null;
  222. //loop over data
  223. for (var i = 0; i < data.length; i++) {
  224. var datum = data[i];
  225. //each node will have children, so let's give it a "children" poperty
  226. datum.children = [];
  227. //add an entry for this node to the map so that any future children can
  228. //lookup the parent
  229. idToNodeMap[datum.id] = datum;
  230. //Does this node have a parent?
  231. if (typeof datum.parent === "undefined" || datum.parent == null) {
  232. //Doesn't look like it, so this node is the root of the tree
  233. root = datum;
  234. treeMap[datum.id] = root;
  235. } else {
  236. //This node has a parent, so let's look it up using the id
  237. parentNode = idToNodeMap[datum.parent.id];
  238. //We don't need this property, so let's delete it.
  239. delete datum.parent;
  240. //Let's add the current node as a child of the parent node.
  241. parentNode.children.push(datum);
  242. }
  243. }
  244. return root;
  245. console.log(root)
  246. }
  247. function convertParentToChildList(data) {
  248. var treeMap = {};
  249. var list = [];
  250. convertListToTree(data, treeMap);
  251. angular.forEach(treeMap, function(item) {
  252. list.push(item);
  253. });
  254. return list;
  255. }
  256. $scope.try_async_load();
  257. $scope.my_tree_handler = function(branch) {
  258. $scope.startlist = branch;
  259. if (branch.id == 2) {
  260. incidentClassify()
  261. } else if (branch.id == 3) {
  262. incidentHandler();
  263. $scope.my_data[0].children[0].selected = false;
  264. } else if (branch.id == 6) {
  265. problemClassify()
  266. $scope.my_data[0].children[0].selected = false;
  267. } else if (branch.id == 7) {
  268. problemHandler()
  269. $scope.my_data[0].children[0].selected = false;
  270. } else if (branch.id == 12) {
  271. changeClassify()
  272. $scope.my_data[0].children[0].selected = false;
  273. } else if (branch.id == 13) {
  274. changeHandler()
  275. $scope.my_data[0].children[0].selected = false;
  276. } else if (branch.id == 16) {
  277. releaseClassify()
  278. $scope.my_data[0].children[0].selected = false;
  279. } else if (branch.id == 17) {
  280. releaseHandler()
  281. $scope.my_data[0].children[0].selected = false;
  282. } else if (branch.id == 22) {
  283. assetClassify()
  284. $scope.my_data[0].children[0].selected = false;
  285. } else if (branch.id == 24) {
  286. assetStatus()
  287. $scope.my_data[0].children[0].selected = false;
  288. }
  289. }
  290. /***
  291. * 事件分类总数
  292. */
  293. // setTimeout(function() {
  294. function incidentClassify() {
  295. $scope.pielenddata = [];
  296. $scope.piebodydata = [];
  297. $scope.hearderlist = [{ name: "事件类别(三级)", value: "type3" }, { name: "事件数量", value: "num" }, { name: "所属类型(二级)", value: "type2" }, { name: "所属类型(一级)", value: "type1" }, { name: "占比", value: "proportion" }];
  298. api_report_nx.fetchDataList("incidentClassify", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  299. if (response.code == 200) {
  300. $scope.sum = response.sum;
  301. $scope.rRows = response.incidentClassifyList;
  302. angular.forEach(response.incidentClassify, function(item) {
  303. $scope.pielenddata.push(item.type);
  304. $scope.piebodydata.push({ "value": item.num, "name": item.type, "proportion": item.proportion });
  305. })
  306. pieechart()
  307. } else {
  308. }
  309. });
  310. }
  311. // setTimeout(function() {
  312. incidentClassify()
  313. // }, 500);
  314. /**
  315. * 处理事件占比
  316. */
  317. function incidentHandler() {
  318. $scope.barlenddata = [];
  319. $scope.barbodydata = [];
  320. $scope.hearderlist = [{ name: "处理人", value: "name" }, { name: "完成事件数", value: "num" }, { name: "占比", value: "proportion" }];
  321. api_report_nx.fetchDataList("incidentHandler", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  322. if (response.code == 200) {
  323. $scope.sum = response.sum;
  324. $scope.rRows = response.incidentHandler;
  325. angular.forEach(response.incidentHandler, function(item) {
  326. $scope.barlenddata.push(item.name);
  327. $scope.barbodydata.push({ "value": item.num, "name": item.name, "proportion": item.proportion });
  328. })
  329. barechart()
  330. } else {
  331. }
  332. });
  333. }
  334. // incidentHandler()
  335. /**
  336. * 问题总数
  337. */
  338. function problemClassify() {
  339. $scope.pielenddata = [];
  340. $scope.piebodydata = [];
  341. $scope.hearderlist = [{ name: "问题类别(三级)", value: "type3" }, { name: "问题数量", value: "num" }, { name: "所属类型(二级)", value: "type2" }, { name: "所属类型(一级)", value: "type1" }, { name: "占比", value: "proportion" }];
  342. api_report_nx.fetchDataList("problemClassify", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  343. if (response.code == 200) {
  344. $scope.sum = response.sum;
  345. $scope.rRows = response.problemClassifyList;
  346. angular.forEach(response.problemClassify, function(item) {
  347. $scope.pielenddata.push(item.type);
  348. $scope.piebodydata.push({ "value": item.num, "name": item.type, "proportion": item.proportion });
  349. })
  350. pieechart()
  351. } else {
  352. }
  353. });
  354. }
  355. /**
  356. * 处理问题占比
  357. */
  358. function problemHandler() {
  359. $scope.barlenddata = [];
  360. $scope.barbodydata = [];
  361. $scope.hearderlist = [{ name: "主责人", value: "name" }, { name: "完成问题数", value: "num" }, { name: "占比", value: "proportion" }];
  362. api_report_nx.fetchDataList("problemHandler", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  363. if (response.code == 200) {
  364. $scope.sum = response.sum;
  365. $scope.rRows = response.problemHandler;
  366. angular.forEach(response.problemHandler, function(item) {
  367. $scope.barlenddata.push(item.name);
  368. $scope.barbodydata.push({ "value": item.num, "name": item.name, "proportion": item.proportion });
  369. })
  370. barechart()
  371. } else {
  372. }
  373. });
  374. }
  375. /**
  376. * 变更总数
  377. */
  378. function changeClassify() {
  379. $scope.pielenddata = [];
  380. $scope.piebodydata = [];
  381. $scope.hearderlist = [{ name: "变更类别(三级)", value: "type3" }, { name: "变更数量", value: "num" }, { name: "所属类型(二级)", value: "type2" }, { name: "所属类型(一级)", value: "type1" }, { name: "占比", value: "proportion" }];
  382. api_report_nx.fetchDataList("changeClassify", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  383. if (response.code == 200) {
  384. $scope.sum = response.sum;
  385. $scope.rRows = response.changeClassifyList;
  386. angular.forEach(response.changeClassify, function(item) {
  387. $scope.pielenddata.push(item.type);
  388. $scope.piebodydata.push({ "value": item.num, "name": item.type, "proportion": item.proportion });
  389. })
  390. pieechart()
  391. } else {
  392. }
  393. });
  394. }
  395. /**
  396. * 完成变更占比
  397. */
  398. function changeHandler() {
  399. $scope.barlenddata = [];
  400. $scope.barbodydata = [];
  401. $scope.hearderlist = [{ name: "主责人", value: "name" }, { name: "完成变更数", value: "num" }, { name: "占比", value: "proportion" }];
  402. api_report_nx.fetchDataList("changeHandler", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  403. if (response.code == 200) {
  404. $scope.sum = response.sum;
  405. $scope.rRows = response.changeHandler;
  406. angular.forEach(response.changeHandler, function(item) {
  407. $scope.barlenddata.push(item.name);
  408. $scope.barbodydata.push({ "value": item.num, "name": item.name, "proportion": item.proportion });
  409. })
  410. barechart()
  411. } else {
  412. }
  413. });
  414. }
  415. /**
  416. * 发布总数
  417. */
  418. function releaseClassify() {
  419. $scope.pielenddata = [];
  420. $scope.piebodydata = [];
  421. api_report_nx.fetchDataList("releaseClassify", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  422. if (response.code == 200) {
  423. $scope.sum = response.sum;
  424. $scope.rRows = response.releaseClassifyList;
  425. angular.forEach(response.releaseClassify, function(item) {
  426. $scope.pielenddata.push(item.name);
  427. $scope.piebodydata.push({ "value": item.num, "name": item.name, "proportion": item.proportion });
  428. })
  429. pieechart()
  430. } else {
  431. }
  432. });
  433. }
  434. /**
  435. * 完成发布占比
  436. */
  437. function releaseHandler() {
  438. $scope.barlenddata = [];
  439. $scope.barbodydata = [];
  440. api_report_nx.fetchDataList("releaseHandler", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  441. if (response.code == 200) {
  442. $scope.sum = response.sum;
  443. $scope.rRows = response.releaseHandler;
  444. angular.forEach(response.releaseHandler, function(item) {
  445. $scope.barlenddata.push(item.name);
  446. $scope.barbodydata.push({ "value": item.num, "name": item.name, "proportion": item.proportion });
  447. })
  448. barechart()
  449. } else {
  450. }
  451. });
  452. }
  453. /**
  454. * 资产总额
  455. */
  456. function assetClassify() {
  457. $scope.pielenddata = [];
  458. $scope.piebodydata = [];
  459. $scope.hearderlist = [{ name: "资产类别(三级)", value: "label3" }, { name: "资产金额", value: "money" }, { name: "资产类别(二级)", value: "label2" }, { name: "资产类别(一级)", value: "label1" }];
  460. api_report_nx.fetchDataList("assetClassify", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  461. if (response.code == 200) {
  462. $scope.sum = response.sumMoney;
  463. $scope.summap = response.sum;
  464. $scope.rRows = response.assetClassifyList;
  465. angular.forEach(response.assetClassify, function(item) {
  466. $scope.pielenddata.push(item.label);
  467. $scope.piebodydata.push({ "value": item.money, "name": item.label, "proportion": item.proportion });
  468. })
  469. pieechart()
  470. } else {
  471. }
  472. });
  473. }
  474. /**
  475. *资产在库
  476. */
  477. $scope.summap = 0;
  478. function assetStatus() {
  479. $scope.pielenddata = [];
  480. $scope.piebodydata = [];
  481. $scope.hearderlist = [{ name: "资产类别(三级)", value: "label3" }, { name: "数量", value: "sum" }, { name: "资产类别(二级)", value: "label2" }, { name: "资产类别(一级)", value: "label1" }];
  482. api_report_nx.fetchDataList("assetStatus", { "startTime": $scope.parameters.paramDateFrom, "endTime": $scope.parameters.paramDateTo }).then(function(response) {
  483. // if (response.code == 200) {
  484. $scope.sum = response.sum;
  485. // $scope.summap = response.sum;
  486. $scope.rRows = response.assetStatusList;
  487. angular.forEach(response.assetStatus, function(item) {
  488. $scope.pielenddata.push(item.state);
  489. $scope.piebodydata.push({ "value": item.sum, "name": item.state, "proportion": item.proportion });
  490. })
  491. pieechart()
  492. // } else {
  493. // }
  494. });
  495. }
  496. /**
  497. * 环形图
  498. */
  499. function pieechart() {
  500. var dom = document.getElementById("report");
  501. var myChart = echarts.init(dom);
  502. var app = {};
  503. var option = null;
  504. myChart.showLoading({  
  505. text: '数据加载中...',
  506. color: '#c23531',
  507. textColor: '#fff',
  508. maskColor: 'rgba(255,255,255,0)',
  509. zlevel: 0
  510. });
  511. myChart.hideLoading();
  512. option = {
  513. // title: [{
  514. // text: [$scope.sum],
  515. // x: '15%',
  516. // y: '50%',
  517. // textStyle: {
  518. // fontSize: 42,
  519. // fontWeight: 'normal',
  520. // fontStyle: 'normal',
  521. // color: '#005395',
  522. // align: 'center',
  523. // }
  524. // },
  525. // {
  526. // text: $scope.startlist.title,
  527. // x: '15%',
  528. // y: '40%',
  529. // textStyle: {
  530. // fontSize: 16,
  531. // fontWeight: 'normal',
  532. // fontStyle: 'normal',
  533. // align: "center",
  534. // color: '#333'
  535. // }
  536. // }
  537. // ],
  538. title: {
  539. subtext: [$scope.sum],
  540. text: $scope.startlist.title,
  541. itemGap: 3,
  542. "x": '20%',
  543. "y": '40%',
  544. textAlign: "center",
  545. "textStyle": {
  546. "fontWeight": 'normal',
  547. "fontSize": 18,
  548. "color": '#333',
  549. },
  550. "subtextStyle": {
  551. "fontWeight": 'normal',
  552. "fontSize": 42,
  553. "color": '#005395',
  554. "lineHeight": 14
  555. },
  556. },
  557. tooltip: {
  558. "backgroundColor": "rgba(0,0,0,9)",
  559. "textStyle": {
  560. "fontSize": 12,
  561. "color": '#f9f9f9',
  562. },
  563. trigger: 'item',
  564. formatter: "{a} <br/>{b}: {c} ({d}%)"
  565. },
  566. legend: {
  567. orient: 'vertical',
  568. x: '40%',
  569. y: 'center',
  570. itemGap: 20,
  571. data: $scope.pielenddata,
  572. formatter: function(param) {
  573. for (var i = 0; i < $scope.pielenddata.length; i++) {
  574. if ($scope.piebodydata[i].name == param) {
  575. return ' ' + $scope.piebodydata[i].name + ' ' + $scope.piebodydata[i].value + ' ' + $scope.piebodydata[i].proportion;
  576. }
  577. }
  578. }
  579. },
  580. series: [{
  581. name: $scope.startlist.title,
  582. type: 'pie',
  583. radius: ['70%', '85%'],
  584. center: ['20%', '50%'],
  585. color: ['#315b7e', '#3370a1', '#1a3a53', '#61829d', '#8496A5', '#e6eef4', '#15598F', '#61829d', '#5F9FD1', '#7EAFD6'],
  586. hoverAnimation: true,
  587. label: {
  588. normal: {
  589. show: false,
  590. position: 'center'
  591. },
  592. formatter: [
  593. '{a|这段文本采用样式a}',
  594. '{b|这段文本采用样式b}这段用默认样式{x|这段用样式x}'
  595. ].join('\n'),
  596. rich: {
  597. a: {
  598. color: 'red',
  599. lineHeight: 10
  600. },
  601. b: {
  602. backgroundColor: {
  603. image: 'xxx/xxx.jpg'
  604. },
  605. height: 40
  606. },
  607. x: {
  608. fontSize: 18,
  609. fontFamily: 'Microsoft YaHei',
  610. borderColor: '#449933',
  611. borderRadius: 4
  612. },
  613. }
  614. },
  615. labelLine: {
  616. normal: {
  617. show: false
  618. }
  619. },
  620. data: $scope.piebodydata
  621. }]
  622. };
  623. if (option && typeof option === "object") {
  624. myChart.setOption(option);
  625. myChart.hideLoading();
  626. }
  627. // ///
  628. // var dom = document.getElementById("reportnext");
  629. // var myChartn = echarts.init(dom);
  630. // var app = {};
  631. // var optionn = null;
  632. // myChartn.showLoading({  
  633. // text: '数据加载中...',
  634. // color: '#c23531',
  635. // textColor: '#fff',
  636. // maskColor: 'rgba(255,255,255,0)',
  637. // zlevel: 0
  638. // });
  639. // myChartn.hideLoading();
  640. // optionn = {
  641. // title: [{
  642. // text: [$scope.sum],
  643. // x: 'center',
  644. // y: '50%',
  645. // textStyle: {
  646. // fontSize: 42,
  647. // fontWeight: 'normal',
  648. // fontStyle: 'normal',
  649. // color: '#005395',
  650. // align: 'center',
  651. // }
  652. // },
  653. // {
  654. // text: $scope.startlist.title,
  655. // x: 'center',
  656. // y: '40%',
  657. // textStyle: {
  658. // fontSize: 16,
  659. // fontWeight: 'normal',
  660. // fontStyle: 'normal',
  661. // align: "center",
  662. // color: '#333'
  663. // }
  664. // }
  665. // ],
  666. // tooltip: {
  667. // "backgroundColor": "rgba(0,0,0,9)",
  668. // "textStyle": {
  669. // "fontSize": 12,
  670. // "color": '#f9f9f9',
  671. // },
  672. // trigger: 'item',
  673. // formatter: "{a} <br/>{b}: {c} ({d}%)"
  674. // },
  675. // legend: {
  676. // orient: 'vertical',
  677. // x: '90%',
  678. // y: 'center',
  679. // itemGap: 40,
  680. // data: $scope.pielenddata,
  681. // formatter: function(param) {
  682. // for (var i = 0; i < $scope.pielenddata.length; i++) {
  683. // if ($scope.piebodydata[i].name == param) {
  684. // return ' ' + $scope.piebodydata[i].name + ' ' + $scope.piebodydata[i].value + ' ' + $scope.piebodydata[i].proportion;
  685. // }
  686. // }
  687. // }
  688. // },
  689. // series: [{
  690. // show: false,
  691. // name: $scope.startlist.title,
  692. // type: 'pie',
  693. // radius: ['70%', '85%'],
  694. // center: ['50%', '50%'],
  695. // color: ['#315b7e', '#3370a1', '#1a3a53', '#61829d', '#8496A5', '#e6eef4', '#15598F', '#61829d', '#5F9FD1', '#7EAFD6'],
  696. // hoverAnimation: true,
  697. // label: {
  698. // normal: {
  699. // show: false,
  700. // position: 'center'
  701. // },
  702. // formatter: [
  703. // '{a|这段文本采用样式a}',
  704. // '{b|这段文本采用样式b}这段用默认样式{x|这段用样式x}'
  705. // ].join('\n'),
  706. // rich: {
  707. // a: {
  708. // color: 'red',
  709. // lineHeight: 10
  710. // },
  711. // b: {
  712. // backgroundColor: {
  713. // image: 'xxx/xxx.jpg'
  714. // },
  715. // height: 40
  716. // },
  717. // x: {
  718. // fontSize: 18,
  719. // fontFamily: 'Microsoft YaHei',
  720. // borderColor: '#449933',
  721. // borderRadius: 4
  722. // },
  723. // }
  724. // },
  725. // labelLine: {
  726. // normal: {
  727. // show: false
  728. // }
  729. // },
  730. // data: $scope.piebodydata
  731. // }]
  732. // };
  733. // if (optionn && typeof optionn === "object") {
  734. // myChartn.setOption(optionn);
  735. // myChartn.hideLoading();
  736. // }
  737. }
  738. // }, 1000)
  739. /***
  740. * 柱状图
  741. */
  742. function hardDisks(data) {
  743. if ($scope.sum == 0) {
  744. return 0;
  745. } else {
  746. }
  747. return data / $scope.sum;
  748. }
  749. function barechart() {
  750. var dom = document.getElementById("barreport");
  751. var mybarChart = echarts.init(dom);
  752. var app = {};
  753. var optionbar = null;
  754. mybarChart.showLoading({  
  755. text: '数据加载中...',
  756. color: '#c23531',
  757. textColor: '#fff',
  758. maskColor: 'rgba(255,255,255,0)',
  759. zlevel: 0
  760. });
  761. mybarChart.hideLoading();
  762. optionbar = {
  763. title: {
  764. // text: '(件)故障数量',
  765. x: '10',
  766. y: '0',
  767. textStyle: {
  768. fontWeight: 'normal',
  769. fontSize: 12,
  770. color: "#56c9ff",
  771. }
  772. },
  773. xAxis: {
  774. axisTick: {
  775. alignWithLabel: true
  776. },
  777. splitLine: {
  778. show: false
  779. },
  780. splitArea: {
  781. show: false
  782. },
  783. // data: XData,
  784. data: $scope.barlenddata,
  785. axisLine: {
  786. lineStyle: {
  787. color: '#eaeaea'
  788. }
  789. },
  790. axisLabel: {
  791. interval: 0,
  792. formatter: function(value) {
  793. return value.split("").join("\n");
  794. },
  795. // rotate: 45,
  796. // margin: 2,
  797. textStyle: {
  798. color: '#999',
  799. fontSize: 14,
  800. }
  801. },
  802. },
  803. // grid: { // 控制图的大小,调整下面这些值就可以,
  804. // x: 40,
  805. // x2: 100,
  806. // y2: 150, // y2可以控制 X轴跟Zoom控件之间的间隔,避免以为倾斜后造成 label重叠到zoom上
  807. // },
  808. yAxis: {
  809. axisTick: {
  810. show: false
  811. },
  812. splitLine: {
  813. show: false
  814. },
  815. splitArea: {
  816. show: false
  817. },
  818. minInterval: 1,
  819. axisLabel: {
  820. show: true,
  821. textStyle: {
  822. color: '#999',
  823. fontSize: 14,
  824. }
  825. },
  826. axisLine: {
  827. show: false,
  828. lineStyle: {
  829. color: '#eaeaea'
  830. }
  831. },
  832. splitLine: {
  833. lineStyle: {
  834. color: "#eaeaea"
  835. }
  836. }
  837. },
  838. grid: {
  839. left: 10,
  840. top: 25,
  841. bottom: 20,
  842. right: 10,
  843. containLabel: true
  844. },
  845. "tooltip": {
  846. "trigger": "item",
  847. "backgroundColor": "rgba(0,0,0,9)",
  848. "textStyle": {
  849. "fontSize": 12,
  850. "color": '#f9f9f9',
  851. },
  852. formatter: function(data) {
  853. return $scope.startlist.tip1 + ':' + data.value + '<br />' + $scope.startlist.tip2 + ':' + data.data.proportion;
  854. },
  855. },
  856. series: {
  857. type: "bar",
  858. itemStyle: {
  859. normal: {
  860. color: function(params) {
  861. // type = 'linear';
  862. // var colorList = [
  863. // '#005395'
  864. // ];
  865. return '#005395'
  866. },
  867. }
  868. },
  869. label: {
  870. normal: {
  871. show: true,
  872. position: 'top',
  873. textStyle: {
  874. // color: '#56c9ff'
  875. }
  876. }
  877. },
  878. barWidth: 18,
  879. // barWidth: '30%',
  880. // data: yData
  881. data: $scope.barbodydata
  882. }
  883. };
  884. if (optionbar && typeof optionbar === "object") {
  885. mybarChart.setOption(optionbar);
  886. mybarChart.hideLoading();
  887. }
  888. }
  889. }])