selfDefinedReportCtrl.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. 'use strict';
  2. app.controller('selfDefinedReportCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_configure_data", '$parse', "$injector", "$aside", 'toaster', "api_configure_form", "api_cmdb", 'api_bpm', 'api_report_data', function ($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_configure_data, $parse, $injector, $aside, toaster, api_configure_form, api_cmdb, api_bpm, api_report_data) {
  3. console.log(echarts);
  4. var loginUser = $rootScope.user;
  5. $scope.pageData = {};
  6. $scope.haveSave = false;
  7. // $scope.pageData.chartType = {
  8. // status: 0,
  9. // value: "饼状图"
  10. // }
  11. $scope.my_tree_handler = function (branch) {
  12. if (!branch.children.length) {
  13. api_report_data.fetchDataList('reportCustom', { idx: 0, sum: 1000, reportCustom: { reportType: { id: branch.id } } }).then(function (data) {
  14. if (data.list.length) {
  15. $scope.pageData.sqlContent = data.list[0].fetchSql;
  16. console.log(data.list[0].fetchSql)
  17. if (data.list[0].status == 0) {
  18. $scope.pageData.chartType = {
  19. status: 0,
  20. value: "饼状图"
  21. }
  22. } else if (data.list[0].status == 1) {
  23. $scope.pageData.chartType = {
  24. status: 1,
  25. value: "柱状图"
  26. }
  27. }
  28. }else {
  29. $scope.pageData.sqlContent = '';
  30. }
  31. })
  32. } else {
  33. $scope.pageData.sqlContent = '';
  34. }
  35. $scope.changecate = true;
  36. $scope.addcate = false;
  37. filterData.treeIds = branch.id;
  38. $scope.selectedTreeNode = branch;
  39. $scope.output = branch;
  40. convertchildToTree(branch);
  41. // console.log($scope.subdata)
  42. // var eqflag = false;
  43. // angular.forEach($scope.outdata, function (item) {
  44. // if (item.id == $scope.output.id) eqflag = true;
  45. // });
  46. // if (eqflag) {
  47. // } else {
  48. // $scope.outdata.push({
  49. // 'name': $scope.output.label,
  50. // 'id': $scope.output.id
  51. // });
  52. // var postData = {
  53. // typeList: []
  54. // };
  55. // if ($scope.outdata.length > 0) {
  56. // angular.forEach($scope.outdata, function (data) {
  57. // postData.typeList.push({ id: data.id });
  58. // })
  59. // }
  60. // // api_solution.findSolutionTypesUser(postData).then(function(response){
  61. // // //Restangular.
  62. // // $scope.userdata = response.data;
  63. // // });
  64. // }
  65. };
  66. function convertchildToTree(datum) {
  67. $scope.subdata = {};
  68. // console.log($scope.parentdata)
  69. if (datum.parent) {
  70. // angular.forEach($scope.parentdata, function(item, index) {
  71. // if (datum.id == item.id) return $scope.subdata = item;
  72. // });
  73. $scope.subdata = { 'id': datum.id, 'name': datum.label, 'parent': datum.parent, 'hasArea': datum.hasArea, 'hasSimple': datum.hasSimple, 'group': datum.group }
  74. } else {
  75. $scope.subdata = { 'id': datum.id, 'name': datum.label, 'group': datum.group, 'hasSimple': datum.hasSimple, 'hasArea': datum.hasArea }
  76. }
  77. // if(datum.children.length==0){
  78. // angular.forEach($scope.parentdata,function(item, index){
  79. // if(datum.id==item.id) return $scope.subdata=item;
  80. // });
  81. // }else{$scope.subdata={id:datum.id,category:datum.label}}
  82. }
  83. function convertListToTree(data, treeMap) {
  84. // console.log(data);
  85. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  86. var root = null; //Initially set our loop to null
  87. var parentNode = null;
  88. //loop over data
  89. for (var i = 0; i < data.length; i++) {
  90. var datum = data[i];
  91. //each node will have children, so let's give it a "children" poperty
  92. datum.children = [];
  93. //add an entry for this node to the map so that any future children can
  94. //lookup the parent
  95. idToNodeMap[datum.id] = datum;
  96. //Does this node have a parent?
  97. // console.log("datum="+JSON.stringify(datum))
  98. if (typeof datum.parent === "undefined") {
  99. //Doesn't look like it, so this node is the root of the tree
  100. root = datum;
  101. treeMap[datum.id] = root;
  102. } else {
  103. //This node has a parent, so let's look it up using the id
  104. parentNode = idToNodeMap[datum.parent.id];
  105. //We don't need this property, so let's delete it.
  106. // delete datum.parent;
  107. //Let's add the current node as a child of the parent node.
  108. parentNode.children.push(datum);
  109. }
  110. }
  111. return root;
  112. }
  113. function convertParentToChildList(data) {
  114. var treeMap = {};
  115. var list = [];
  116. convertListToTree(data, treeMap);
  117. angular.forEach(treeMap, function (item) {
  118. list.push(item);
  119. });
  120. // console.log(list)
  121. return list;
  122. }
  123. // $scope.onFilterCallback = function(item){
  124. // $scope.addcategory.parent=item.label;
  125. // }
  126. $scope.parentdata = {};
  127. // ddd定制数据结构
  128. $scope.try_async_load = function () {
  129. $scope.my_data = [];
  130. $scope.doing_async = true;
  131. var data = { "idx": 0, "sum": 1000 };
  132. api_report_data.fetchDataList('reportType', data).then(function (response) {
  133. console.log(response.list)
  134. var data = response.list;
  135. // data.unshift({ id: 0, name: "all" })
  136. // console.log(data);
  137. var objects = [];
  138. $scope.parentdata = data;
  139. for (var i = 0; i < data.length; i++) {
  140. var object = {};
  141. object.id = data[i].id;
  142. // if (angular.isDefined(data[i].parent) && data[i].id != 0) {
  143. // object.parent = data[i].parent;
  144. // } else if (data[i].id != 0) {
  145. // object.parent = data[i].parent = { id: 0, name: "all" }
  146. // }
  147. if (angular.isDefined(data[i].parent)) {
  148. object.parent = data[i].parent;
  149. }
  150. if (angular.isDefined(data[i].hasArea)) {
  151. object.hasArea = data[i].hasArea;
  152. }
  153. if (angular.isDefined(data[i].hasSimple)) {
  154. object.hasSimple = data[i].hasSimple;
  155. }
  156. if (angular.isDefined(data[i].group)) {
  157. object.group = data[i].group;
  158. }
  159. object.label = data[i].name;
  160. // object.actions = data[i][3]; //权限部分
  161. // object.group = "1";
  162. // object.user = "2";
  163. object.state = {
  164. "opened": true
  165. };
  166. object.typeName = "type";
  167. // if()
  168. // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
  169. $scope.showAddSolutionType = true;
  170. // }
  171. // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
  172. $scope.showReviewKnowledgeType = true;
  173. // }
  174. objects.push(object);
  175. }
  176. console.log(objects)
  177. $scope.my_data = convertParentToChildList(objects);
  178. // console.log($scope.my_data);
  179. $scope.tree_data = angular.copy($scope.my_data);
  180. if ($scope.my_data.length > 0) {
  181. $scope.doing_async = false;
  182. }
  183. });
  184. };
  185. $scope.try_async_load();
  186. // $scope.ldloading={};
  187. var filterData = {
  188. key: 'null',
  189. status: 0,
  190. pageIndex: 0,
  191. pageSum: 10,
  192. //treeIds:'[]',
  193. userId: loginUser.id
  194. }
  195. // 增删改弹窗
  196. console.log($scope.inpContent)
  197. $scope.redact = function (type, model) {
  198. console.log(model)
  199. var modalInstance = $modal.open({
  200. templateUrl: 'assets/views/system/selfDefinedReport/tpl/dialog.tpl.html',
  201. controller: function ($scope, $modalInstance, api_bpm, modelData, currentUserId, Alert, api_report_data, selectedTreeNode, scope) {
  202. console.log(selectedTreeNode);
  203. $scope.inp = {};
  204. // console.log($scope.inpContent.a)
  205. if (type == 0) {
  206. $scope.title = '新增报表类型';
  207. $scope.placeholder = '请输入报表名称';
  208. $scope.inp.content = '';
  209. } else if (type == 1) {
  210. $scope.title = '修改报表类型';
  211. $scope.placeholder = '知识增加数量';
  212. $scope.delContent = $scope.inp.content = selectedTreeNode.label;
  213. } else if (type == 2) {
  214. $scope.title = '删除报表类型';
  215. $scope.type = 2;
  216. $scope.delContent = $scope.inp.content = selectedTreeNode.label;
  217. }
  218. $scope.ok = function () {
  219. console.log($scope.inp.content)
  220. if ($scope.inp.content == '') { return }
  221. var parentId = selectedTreeNode.parent ? selectedTreeNode.parent.id : 1;
  222. if (type == 0) {
  223. var iid = parentId == 1 ? selectedTreeNode.id : parentId;
  224. // var postData={reportType: { name: $scope.inp.content, id: parentId }};
  225. api_report_data.addModel('reportType', { reportType: { name: $scope.inp.content, parent: { id: iid } } }).then(function (data) {
  226. console.log(data);
  227. if (data && data.status == 200) {
  228. SweetAlert.swal("添加成功!", "添加成功", "success")
  229. $modalInstance.dismiss('cancel');
  230. scope.try_async_load()
  231. } else {
  232. SweetAlert.swal("添加失败!", "请稍候重试", "error");
  233. }
  234. })
  235. } else if (type == 1) {
  236. api_report_data.updateModel('reportType', { reportType: { name: $scope.inp.content, parent: { id: parentId }, id: selectedTreeNode.id } }).then(function (data) {
  237. console.log(data);
  238. if (data && data.status == 200) {
  239. SweetAlert.swal("修改成功!", "修改成功", "success")
  240. $modalInstance.dismiss('cancel');
  241. scope.try_async_load()
  242. } else {
  243. SweetAlert.swal("修改失败!", "请稍候重试", "error");
  244. }
  245. })
  246. } else if (type == 2) {
  247. if (selectedTreeNode.children.length) {
  248. alert('存在子集,无法删除!');
  249. } else {
  250. api_report_data.rmModels('reportType', selectedTreeNode.id).then(function (data) {
  251. console.log(data);
  252. if (data && data.status == 200) {
  253. SweetAlert.swal("删除成功!", "删除成功", "success")
  254. $modalInstance.dismiss('cancel');
  255. scope.try_async_load();
  256. } else {
  257. SweetAlert.swal("删除失败!", "请稍候重试", "error");
  258. }
  259. })
  260. }
  261. }
  262. }
  263. $scope.cancel = function () {
  264. $modalInstance.dismiss('cancel');
  265. }
  266. },
  267. size: 'sm',
  268. resolve: {
  269. api_bpm: function () {
  270. return api_bpm;
  271. },
  272. modelData: function () {
  273. return model;
  274. },
  275. currentUserId: function () {
  276. return loginUser.id;
  277. },
  278. Alert: function () {
  279. return SweetAlert;
  280. },
  281. api_report_data: function () {
  282. return api_report_data;
  283. },
  284. selectedTreeNode: function () {
  285. return $scope.selectedTreeNode;
  286. },
  287. scope: function () {
  288. return $scope;
  289. }
  290. }
  291. });
  292. modalInstance.result.then(function (selectedItem) {
  293. if (selectedItem == 'success') {
  294. $scope.refreshData('expand-right', defaultFilterData);
  295. }
  296. });
  297. }
  298. // 预览图形
  299. $scope.designType = [
  300. { value: '饼状图', status: 0 },
  301. { value: '柱状图', status: 1 },
  302. ]
  303. $scope.onChange = function (item) {
  304. console.log(item);
  305. console.log($scope.pageData.sqlContent)
  306. // $scope.pageData.chartType = item.status;
  307. }
  308. $scope.langs = i18nService.getAllLangs();
  309. $scope.lang = 'zh-cn';
  310. i18nService.setCurrentLang($scope.lang);
  311. $scope.gridOptions = {};
  312. $scope.gridOptions.data = 'myData';
  313. $scope.gridOptions.enableColumnResizing = true;
  314. $scope.gridOptions.enableFiltering = false;
  315. $scope.gridOptions.enableGridMenu = false;
  316. $scope.gridOptions.showGridFooter = false;
  317. $scope.gridOptions.showColumnFooter = false;
  318. $scope.gridOptions.fastWatch = true;
  319. $scope.gridOptions.useExternalFiltering = false;
  320. $scope.gridOptions.useExternalPagination = false;
  321. $scope.gridOptions.paginationPageSizes = [100];
  322. $scope.gridOptions.paginationPageSize = 100;
  323. $scope.gridOptions.multiSelect = false;
  324. $scope.gridOptions.rowIdentity = function (row) {
  325. return row.id;
  326. };
  327. $scope.gridOptions.getRowIdentity = function (row) {
  328. return row.id;
  329. };
  330. $scope.gridOptions.columnDefs = [
  331. { name: 'category', displayName: '事件类型', width: '33.4%', enableFiltering: false },
  332. { name: 'COUNT', displayName: '事件数量', width: '33.3%', enableFiltering: false },
  333. { name: 'percent', displayName: '事件占比', width: '33.3%', enableFiltering: false },
  334. ];
  335. // 展示表格
  336. $scope.showTable = function (data) {
  337. var myData = Restangular.stripRestangular(data);
  338. $scope.gridOptions.totalItems = myData.length;
  339. myData.data.forEach(function (v, i) {
  340. v.percent = v.percent + '%';
  341. v.id = i;
  342. })
  343. $scope.myData = myData.data;
  344. }
  345. // 展示echarts
  346. $scope.initEchart = function (data) {
  347. // console.log(data);
  348. if ($scope.pageData.chartType.status == 0) {
  349. initChartsConfig(data);
  350. } else if ($scope.pageData.chartType.status == 1) {
  351. initConfigChart(data)
  352. } else {
  353. initChartsConfig(data);
  354. }
  355. }
  356. //饼图
  357. function initChartsConfig(data) {
  358. var nameArr = [], dataArr = [];
  359. data.forEach(function (v, i) {
  360. nameArr.push(v.category);
  361. dataArr.push({ value: v.COUNT, name: v.category })
  362. })
  363. // nameArr=nameArr.slice(0,10)
  364. console.log(nameArr);
  365. var parkaccountChart = echarts.init(document.getElementById('main'));//p 标签id
  366. var option = {
  367. tooltip: {
  368. trigger: 'item',
  369. formatter: "{a} <br/>{b}: {c} ({d}%)"
  370. },
  371. legend: {
  372. orient: 'vertical',
  373. x: 'left',
  374. data: nameArr
  375. },
  376. series: [
  377. {
  378. name: '',
  379. type: 'pie',
  380. radius: ['50%', '70%'],
  381. avoidLabelOverlap: false,
  382. label: {
  383. normal: {
  384. show: false,
  385. position: 'center'
  386. },
  387. emphasis: {
  388. show: true,
  389. textStyle: {
  390. fontSize: '30',
  391. fontWeight: 'bold'
  392. }
  393. }
  394. },
  395. labelLine: {
  396. normal: {
  397. show: false
  398. }
  399. },
  400. data: dataArr
  401. }
  402. ]
  403. };
  404. parkaccountChart.setOption(option, true);
  405. }
  406. //柱状图数据
  407. function initConfigChart(data) {
  408. console.log(data);
  409. var nameArr = [], countArr = [];
  410. data.forEach(function (v, i) {
  411. nameArr.push(v.category);
  412. countArr.push(v.COUNT);
  413. })
  414. console.log(nameArr, countArr);
  415. var parkaccountChart = echarts.init(document.getElementById('main'));//p 标签id
  416. var option = {
  417. color: ['#3398DB'],
  418. tooltip: {
  419. trigger: 'axis',
  420. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  421. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  422. }
  423. },
  424. grid: {
  425. left: '3%',
  426. right: '4%',
  427. bottom: '3%',
  428. containLabel: true
  429. },
  430. xAxis: [
  431. {
  432. type: 'category',
  433. data: nameArr,
  434. axisTick: {
  435. alignWithLabel: true
  436. }
  437. }
  438. ],
  439. yAxis: [
  440. {
  441. type: 'value'
  442. }
  443. ],
  444. series: [
  445. {
  446. name: '直接访问',
  447. type: 'bar',
  448. barWidth: '60%',
  449. data: countArr
  450. }
  451. ]
  452. };
  453. parkaccountChart.setOption(option, true);
  454. }
  455. // }
  456. // 保存
  457. $scope.save = function () {
  458. // console.log($scope.pageData);
  459. // console.log($scope.selectedTreeNode);
  460. $scope.haveSave = true;
  461. var postData = {
  462. reportCustom: {
  463. reportType: {
  464. id: $scope.selectedTreeNode.id,
  465. name: $scope.selectedTreeNode.label
  466. },
  467. fetchSql: $scope.pageData.sqlContent,
  468. status: $scope.pageData.chartType.status
  469. }
  470. }
  471. console.log(postData)
  472. // console.log($scope.selectedTreeNode.id, $scope.selectedTreeNode.label)
  473. api_report_data.addModel('reportCustom', postData).then(function (data) {
  474. // console.log(data);
  475. if (data && data.status == 200) {
  476. SweetAlert.swal("保存成功!", "保存成功", "success")
  477. $scope.haveSave = true;
  478. api_report_data.report('executeSQL', { sql: $scope.pageData.sqlContent }).then(function (data) {
  479. // api_report_data.report('executeSQL', { sql: 'SELECT iic.category,COUNT(*) AS COUNT FROM itsm_incident ii INNER JOIN itsm_incident_category iic ON ii.categoryid = iic.id GROUP BY iic.category' }).then(function (data) {
  480. // console.log(data.data);
  481. $scope.showTable(data);
  482. $scope.echartsLength=data.data.length;
  483. // if (data.data.length <= 15) {
  484. // $scope.initEchart(data.data);
  485. // }
  486. if (data.data.length <= 15) {
  487. $scope.initEchart(data.data);
  488. $scope.myStyle={
  489. 'height':'1000px'
  490. }
  491. }else{
  492. $scope.myStyle={
  493. 'height':'620px'
  494. }
  495. }
  496. })
  497. } else {
  498. SweetAlert.swal("保存失败!", "请稍候重试", "error");
  499. }
  500. })
  501. }
  502. $scope.preview = function (data) {
  503. var modalInstance = $modal.open({
  504. templateUrl: 'assets/views/system/selfDefinedReport/tpl/preview.tpl.html',
  505. controller: function ($scope, $modalInstance, i18nService, $timeout, api_bpm_domain, api_user_data, pageData, scope) {
  506. $scope.langs = i18nService.getAllLangs();
  507. $scope.lang = 'zh-cn';
  508. i18nService.setCurrentLang($scope.lang);
  509. $scope.gridOptions = {};
  510. $scope.gridOptions.data = 'myData';
  511. $scope.gridOptions.enableColumnResizing = true;
  512. $scope.gridOptions.enableFiltering = false;
  513. $scope.gridOptions.enableGridMenu = false;
  514. $scope.gridOptions.showGridFooter = false;
  515. $scope.gridOptions.showColumnFooter = false;
  516. $scope.gridOptions.fastWatch = true;
  517. $scope.gridOptions.useExternalFiltering = false;
  518. $scope.gridOptions.useExternalPagination = false;
  519. $scope.gridOptions.paginationPageSizes = [1000];
  520. $scope.gridOptions.paginationPageSize = 1000;
  521. $scope.gridOptions.multiSelect = false;
  522. $scope.gridOptions.rowIdentity = function (row) {
  523. return row.id;
  524. };
  525. $scope.gridOptions.getRowIdentity = function (row) {
  526. return row.id;
  527. };
  528. $scope.gridOptions.columnDefs = [
  529. { name: 'category', displayName: '事件类型', width: '33.4%', enableFiltering: false },
  530. { name: 'COUNT', displayName: '事件数量', width: '33.3%', enableFiltering: false },
  531. { name: 'percent', displayName: '事件占比', width: '33.3%', enableFiltering: false },
  532. ];
  533. $scope.showTable = function (data) {
  534. var myData = Restangular.stripRestangular(data);
  535. $scope.gridOptions.totalItems = myData.length;
  536. myData.data.forEach(function (v, i) {
  537. v.percent = v.percent + '%';
  538. v.id = i;
  539. })
  540. $scope.myData = myData.data;
  541. }
  542. //饼图
  543. function initChartsConfig(data) {
  544. var nameArr = [], dataArr = [];
  545. data.forEach(function (v, i) {
  546. nameArr.push(v.category);
  547. dataArr.push({ value: v.COUNT, name: v.category })
  548. })
  549. // nameArr=nameArr.slice(0,10)
  550. console.log(nameArr);
  551. var parkaccountChart = echarts.init(document.getElementById('previewmain'));//p 标签id
  552. var option = {
  553. tooltip: {
  554. trigger: 'item',
  555. formatter: "{a} <br/>{b}: {c} ({d}%)"
  556. },
  557. legend: {
  558. orient: 'vertical',
  559. x: 'left',
  560. data: nameArr
  561. },
  562. series: [
  563. {
  564. name: '',
  565. type: 'pie',
  566. radius: ['50%', '70%'],
  567. avoidLabelOverlap: false,
  568. label: {
  569. normal: {
  570. show: false,
  571. position: 'center'
  572. },
  573. emphasis: {
  574. show: true,
  575. textStyle: {
  576. fontSize: '30',
  577. fontWeight: 'bold'
  578. }
  579. }
  580. },
  581. labelLine: {
  582. normal: {
  583. show: false
  584. }
  585. },
  586. data: dataArr
  587. }
  588. ]
  589. };
  590. parkaccountChart.setOption(option, true);
  591. }
  592. //柱状图数据
  593. function initConfigChart(data) {
  594. console.log(data);
  595. var nameArr = [], countArr = [];
  596. data.forEach(function (v, i) {
  597. nameArr.push(v.category);
  598. countArr.push(v.COUNT);
  599. })
  600. console.log(nameArr, countArr);
  601. var parkaccountChart = echarts.init(document.getElementById('previewmain'));//p 标签id
  602. var option = {
  603. color: ['#3398DB'],
  604. tooltip: {
  605. trigger: 'axis',
  606. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  607. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  608. }
  609. },
  610. grid: {
  611. left: '3%',
  612. right: '4%',
  613. bottom: '3%',
  614. containLabel: true
  615. },
  616. xAxis: [
  617. {
  618. type: 'category',
  619. data: nameArr,
  620. axisTick: {
  621. alignWithLabel: true
  622. }
  623. }
  624. ],
  625. yAxis: [
  626. {
  627. type: 'value'
  628. }
  629. ],
  630. series: [
  631. {
  632. name: '直接访问',
  633. type: 'bar',
  634. barWidth: '60%',
  635. data: countArr
  636. }
  637. ]
  638. };
  639. parkaccountChart.setOption(option, true);
  640. }
  641. $scope.initEchart = function (data) {
  642. if (pageData.chartType.status == 0) {
  643. initChartsConfig(data);
  644. } else if (pageData.chartType.status == 1) {
  645. initConfigChart(data)
  646. } else {
  647. initChartsConfig(data);
  648. }
  649. }
  650. api_report_data.report('executeSQL', { sql: pageData.sqlContent }).then(function (data) {
  651. // api_report_data.report('executeSQL', { sql: 'SELECT iic.category,COUNT(*) AS COUNT FROM itsm_incident ii INNER JOIN itsm_incident_category iic ON ii.categoryid = iic.id GROUP BY iic.category' }).then(function (data) {
  652. $scope.showTable(data);
  653. // console.log(data.data.length);
  654. $scope.echartsLength=data.data.length;
  655. if (data.data.length <= 15) {
  656. $scope.initEchart(data.data);
  657. $scope.myStyle={
  658. 'height':'1000px'
  659. }
  660. }else{
  661. $scope.myStyle={
  662. 'height':'620px'
  663. }
  664. }
  665. })
  666. $scope.ok = function () {
  667. $modalInstance.close($scope.selected.items);
  668. };
  669. $scope.cancel = function () {
  670. $modalInstance.dismiss('cancel');
  671. };
  672. },
  673. size: 'lg',
  674. resolve: {
  675. pageData: function () {
  676. return $scope.pageData
  677. },
  678. scope: function () {
  679. return $scope
  680. }
  681. }
  682. });
  683. modalInstance.result.then(function (selectedItem) {
  684. // if (selectedItem) {
  685. // var filterData = {
  686. // "assginee": selectedItem[0].id
  687. // }
  688. // api_bpm_domain.delegateTask(data.taskId, filterData).then(function (data) {
  689. // if (data && data.status == 200) {
  690. // SweetAlert.swal("添加成功!", "添加协同人成功", "success")
  691. // $scope.refreshData('expand-right', $scope.memoryfilterData);
  692. // } else {
  693. // SweetAlert.swal("添加失败!", "请稍候重试", "error");
  694. // }
  695. // // var myData = Restangular.stripRestangular(data);
  696. // // $scope.gridOptions.totalItems = myData.totalNum;
  697. // // $scope.myData = myData.list;
  698. // });
  699. // }
  700. });
  701. }
  702. // 日期组件
  703. $scope.open = function ($event) {
  704. $event.preventDefault();
  705. $event.stopPropagation();
  706. $scope.opened = !$scope.opened;
  707. };
  708. $scope.endOpen = function ($event) {
  709. console.log($scope.startOpened)
  710. $event.preventDefault();
  711. $event.stopPropagation();
  712. $scope.startOpened = false;
  713. $scope.endOpened = !$scope.endOpened;
  714. // console.log(document.getElementById('input1').nextSibling.setAttribute('height', '100px'))
  715. // document.getElementById('input2').nextSibling.setAttribute('style', 'displsy: block !important')
  716. // document.getElementById('input1').nextSibling.setAttribute('style', 'displsy: block !important')
  717. // console.log(document.getElementById('input1').nextSibling)
  718. // console.log(document.getElementById('input2').nextSibling)
  719. };
  720. $scope.startOpen = function ($event) {
  721. console.log($scope.startOpened)
  722. $event.preventDefault();
  723. $event.stopPropagation();
  724. $scope.endOpened = false;
  725. // document.getElementById('input1').nextSibling.setAttribute('style', 'displsy: block !important')
  726. // document.getElementById('input2').nextSibling.setAttribute('style', 'displsy: block !important')
  727. // console.log(document.getElementById('input1').nextSibling)
  728. // console.log(document.getElementById('input2').nextSibling)
  729. $scope.startOpened = !$scope.startOpened;
  730. };
  731. // 搜索
  732. $scope.chiceIncident = function (item) {
  733. console.log(item);
  734. // var fildata = {};
  735. // // $scope.memoryfilterData = fildata;
  736. // if (!fildata.incident) {
  737. // fildata['incident'] = {};
  738. // }
  739. // // $scope.gridOptions.paginationCurrentPage = 1;
  740. // if (item.acceptDateFrom) {
  741. // item.acceptDateFrom = moment(item.acceptDateFrom).format('YYYY-MM-DD HH:mm:ss');
  742. // }
  743. // if (item.acceptDateEnd) {
  744. // // item.acceptDateEnd = moment(item.acceptDateEnd).format('YYYY-MM-DD HH:mm:ss');
  745. // item.acceptDateEnd = moment(new Date(item.acceptDateEnd).getTime() + 86399999).format('YYYY-MM-DD HH:mm:ss');
  746. // }
  747. // var transitiondata = angular.copy(item);
  748. // angular.extend(fildata.incident, transitiondata)
  749. // $scope.memoryfilterData = fildata;
  750. // $scope.refreshData('expand-right', fildata);
  751. }
  752. //导出
  753. $scope.export = function () {
  754. var filadata = angular.copy($scope.memoryfilterData);
  755. filadata.sum = 10000;
  756. $http({
  757. url: api_bpm_data.downDataModel("incident", 3).getRequestedUrl(),
  758. method: 'POST',
  759. data: JSON.stringify(filadata),
  760. headers: {
  761. // 'Content-type': 'application/xls',
  762. 'Accept': '*/*'
  763. },
  764. responseType: 'arraybuffer'
  765. }).success(function (data, status, headers, config) {
  766. // $scope.ldloading.zoom_in = false;
  767. var file = new Blob([data], {
  768. type: 'application/vnd.ms-excel'
  769. });
  770. //trick to download store a file having its URL
  771. var fileURL = URL.createObjectURL(file);
  772. var a = document.createElement('a');
  773. a.href = fileURL;
  774. a.target = '_blank';
  775. a.download = '工单列表.xls';
  776. document.body.appendChild(a);
  777. a.click();
  778. }).error(function (data, status, headers, config) {
  779. // $scope.ldloading.zoom_in = false;
  780. console.log(data);
  781. });
  782. }
  783. }]);