meansCtrl.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. // "$aside", "toaster", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form",
  6. app.controller('meansCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$injector", '$parse', "$interval", "$modal", "$stateParams", "$aside", "SweetAlert", "toaster", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form", function($rootScope, $scope, $http, $state, $timeout, $parse, $injector, $interval, $modal, $stateParams, $aside, SweetAlert, toaster, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_configure_data, api_cmdb, api_configure_form) {
  7. $scope.langs = i18nService.getAllLangs();
  8. $scope.lang = 'zh-cn';
  9. i18nService.setCurrentLang($scope.lang);
  10. var loginUser = $rootScope.user;
  11. $scope.showdown = false;
  12. $scope.clickshow = function() {
  13. $scope.showdown = !$scope.showdown;
  14. }
  15. $scope.gridOptions = {};
  16. $scope.gridOptions.data = 'myData';
  17. $scope.gridOptions.enableColumnResizing = true;
  18. $scope.gridOptions.enableFiltering = true;
  19. $scope.gridOptions.enableGridMenu = true;
  20. $scope.gridOptions.enableRowSelection = true;
  21. $scope.gridOptions.enableSelectAll = true;
  22. $scope.gridOptions.showGridFooter = true;
  23. $scope.gridOptions.showColumnFooter = true;
  24. $scope.gridOptions.fastWatch = true;
  25. $scope.gridOptions.useExternalFiltering = true;
  26. $scope.gridOptions.useExternalPagination = true;
  27. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  28. $scope.gridOptions.paginationPageSize = 10;
  29. $scope.gridOptions.multiSelect = true;
  30. // $scope.gridOptions.enableRowHeaderSelection = true;
  31. // $scope.gridOptions.enableRowSelection = true;
  32. // $scope.gridOptions.enableFullRowSelection = true;
  33. // $scope.gridOptions.enableSelectionBatchEvent = true;
  34. var mun = $scope.gridOptions.paginationPageSize;
  35. $scope.gridOptions.rowIdentity = function(row) {
  36. return row.id;
  37. };
  38. $scope.gridOptions.getRowIdentity = function(row) {
  39. return row.id;
  40. };
  41. $scope.gridOptions.columnDefs = [{
  42. name: '操作',
  43. width: 50,
  44. enableFiltering: false,
  45. cellTemplate: '<div class="links cl-effect-1">' +
  46. '<a ng-click="grid.appScope.onClick(row.entity)" tooltip="编辑" tooltip-placement="right"><i class="fa fa-pencil-square-o"></i></a>' +
  47. '</div>'
  48. },
  49. { name: 'uuid', enableSorting: false, displayName: '内部编码', width: 130, enableFiltering: false },
  50. { name: 'name', enableSorting: false, displayName: '资产名称', width: 100, enableFiltering: false },
  51. { name: 'title', enableSorting: false, displayName: '资产类型', width: 100, enableFiltering: false },
  52. { name: 'status', enableSorting: false, displayName: '资产状态', width: 100, enableFiltering: false },
  53. { name: 'placeBasehw', enableSorting: false, displayName: '资产地点', width: 80, enableFiltering: false },
  54. { name: 'createtime', enableSorting: false, displayName: '创建时间', width: 80, enableFiltering: false },
  55. { name: 'plantime', enableSorting: false, displayName: '预计报废时间', width: 80, enableFiltering: false },
  56. { name: 'props.meansmanager', enableSorting: false, displayName: '管理员', width: 80, enableFiltering: false },
  57. { name: 'lastupdatetime', enableSorting: false, displayName: '最后更新时间', width: 100, enableFiltering: false },
  58. { name: 'props.meansliable', enableSorting: false, displayName: '责任人', width: 80, enableFiltering: false }
  59. ];
  60. $scope.gridOptions.rowTemplate = "<div ng-click=\"onview(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  61. //修改
  62. $scope.onClick = function(row) {
  63. // $scope.classify="basehwntwsv";
  64. var data = { "model": row };
  65. $state.go('app.means.bill', { formKey: 'means_edit', service: 'api_cmdb', 'model': JSON.stringify(data) })
  66. };
  67. //查看
  68. $scope.onview = function(row) {
  69. var data = { "model": row };
  70. $state.go('app.means.view', { formKey: 'means_edit', service: 'api_cmdb', 'model': JSON.stringify(data) })
  71. };
  72. $scope.gridOptions.onRegisterApi = function(gridApi) {
  73. $scope.gridApi = gridApi;
  74. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  75. var filtersData = $scope.memoryfilterData;
  76. filtersData.idx = newPage - 1;
  77. filtersData.sum = pageSize;
  78. // $scope.refreshData('expand-right', filtersData);
  79. $scope.gridApi.grid.selection.selectAll = false;
  80. $scope.myData = [];
  81. api_cmdb.query(filtersData).then(function(data) {
  82. var myData = Restangular.stripRestangular(data);
  83. $scope.gridOptions['totalItems'] = data.total;
  84. for (var i = 0; i < myData.data.node.length; i++) {
  85. myData.data.node[i].createtime = moment(myData.data.node[i].createtime).format('YYYY-MM-DD');
  86. }
  87. $scope.myData = myData.data.node;
  88. if ($scope.myData.length > 0) {
  89. var index = 0;
  90. for (var i = 0; i < $scope.myData.length; i++) {
  91. for (var j = 0; j < $scope.selected.items.length; j++) {
  92. if ($scope.myData[i].id == $scope.selected.items[j].id) {
  93. index++;
  94. }
  95. }
  96. }
  97. if (index == 10) {
  98. $scope.gridApi.grid.selection.selectAll = true;
  99. }
  100. }
  101. }, function() {});
  102. // console.log($scope.gridApi)
  103. // $scope.refreshData('expand-right', {"assignee":$rootScope.user.id, "candidateGroups":$rootScope.user.group[0].id, "idx":newPage-1,"sum":pageSize});
  104. });
  105. // $scope.sels=[];
  106. gridApi.selection.on.rowSelectionChanged($scope, function(scope, ect) {
  107. if (scope.isSelected) {
  108. scope.grid.appScope.selected.items.push(scope.entity)
  109. } else {
  110. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  111. if (scope.grid.appScope.selected.items[i].id == scope.entity.id) {
  112. scope.grid.appScope.selected.items.splice(i, 1);
  113. break;
  114. }
  115. }
  116. }
  117. // var j = 0;
  118. // for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  119. // if (scope.grid.appScope.selected.items[i] == scope.entity) {
  120. // j++;
  121. // break;
  122. // }
  123. // }
  124. // if (j == 1) {
  125. // scope.grid.appScope.selected.items.splice(i, 1);
  126. // } else {
  127. // scope.grid.appScope.selected.items.push(scope.entity);
  128. // }
  129. $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  130. });
  131. gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows) {
  132. // if ($scope.gridApi.grid.api && $scope.gridApi.grid.api.grid.selection.selectAll == true) {
  133. // for (var j = 0; j < rows.length; j++) {
  134. // rows[j].isSelected = false;
  135. // }
  136. // }
  137. var selectitem = [];
  138. selectitem = angular.copy($scope.selected.items);
  139. for (var j = 0; j < rows.length; j++) {
  140. if (rows[j].isSelected == true) {
  141. selectitem.push(rows[j].entity);
  142. } else {
  143. delete selectitem[j];
  144. // rows.splice(j, 1);
  145. }
  146. }
  147. $scope.selected.items = [];
  148. for (var i = 0; i < selectitem.length; i++) {
  149. if (selectitem[i]) {
  150. $scope.selected.items.push(selectitem[i]);
  151. }
  152. }
  153. // $scope.selected.items = $scope.gridApi.selection.getSelectedRows();
  154. // rows.forEach($scope.selected.items);
  155. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  156. // if ($scope.selected.items.length == 0) {
  157. // $scope.selected.items = $scope.mySelectedRows;
  158. // console.log($scope.selected.items);
  159. // } else {
  160. // if ($scope.mySelectedRows.length == 0) {
  161. // for (var i = 0; i < $scope.selected.items.length; i++) {
  162. // for (var j = 0; j < rows.length; j++) {
  163. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  164. // $scope.selected.items.splice(i, 1);
  165. // }
  166. // }
  167. // }
  168. // } else {
  169. // angular.forEach($scope.mySelectedRows, function(item) {
  170. // $scope.selected.items.push(item);
  171. // });
  172. // }
  173. // }
  174. });
  175. };
  176. $scope.searchSolution = function(type, key) {
  177. $scope.gridApi.grid.options.paginationCurrentPage = 1;
  178. var memoryfilterData = {
  179. "idx": 0,
  180. "sum": $scope.gridOptions.paginationPageSize
  181. };
  182. angular.extend($scope.memoryfilterData, memoryfilterData);
  183. $scope.memoryfilterData['searchCriteria'] = type;
  184. $scope.memoryfilterData['keys'] = key;
  185. // $scope.memoryfilterData=defaultFilterData;
  186. // api_cmdb.searchkey(defaultFilterData.type,defaultFilterData.key,defaultFilterData.idx,defaultFilterData.sum).then(function(data){
  187. // var myData = Restangular.stripRestangular(data);
  188. // if(myData.data&&myData.status==200){
  189. // $scope.gridOptions.totalItems = myData.total;
  190. // $scope.myData = myData.data;
  191. // }
  192. // });
  193. $scope.refreshData('expand-right', $scope.memoryfilterData);
  194. }
  195. $scope.onChangestatus = function(searchType) {
  196. // defaultFilterData['status'] = searchType;
  197. $scope.gridApi.grid.options.paginationCurrentPage = 1;
  198. var memoryfilterData = {
  199. "idx": 0,
  200. "sum": $scope.gridOptions.paginationPageSize
  201. };
  202. angular.extend($scope.memoryfilterData, memoryfilterData);
  203. $scope.memoryfilterData['status'] = searchType;
  204. $scope.refreshData('expand-right', $scope.memoryfilterData);
  205. }
  206. this.selectRowFunction = function(data) {
  207. $scope.ciId = data.id;
  208. console.log(data);
  209. };
  210. //树形图
  211. var apple_selected, tree, treedata_avm, treedata_geography;
  212. $scope.my_tree_handler = function(branch) {
  213. //var _ref;
  214. var classify = $scope.classify = branch.prefix.toLowerCase() + branch.sign;
  215. api_cmdb.query({ 'sign': classify }).then(function(data) {
  216. var myData = Restangular.stripRestangular(data);
  217. // console.log(myData.data.node);
  218. if (myData.data && myData.status == 200) {
  219. var ret = myData.data;
  220. redrawSvg(myData);
  221. }
  222. });
  223. };
  224. $scope.my_data = [];
  225. function convertListToTree(data, treeMap) {
  226. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  227. var root = null; //Initially set our loop to null
  228. var parentNode = null;
  229. //loop over data
  230. for (var i = 0; i < data.length; i++) {
  231. var datum = data[i];
  232. //each node will have children, so let's give it a "children" poperty
  233. datum.children = [];
  234. //add an entry for this node to the map so that any future children can
  235. //lookup the parent
  236. idToNodeMap[datum.id] = datum;
  237. //Does this node have a parent?
  238. if (typeof datum.parent === "undefined" || datum.parent == null) {
  239. //Doesn't look like it, so this node is the root of the tree
  240. root = datum;
  241. treeMap[datum.id] = root;
  242. } else {
  243. //This node has a parent, so let's look it up using the id
  244. parentNode = idToNodeMap[datum.parent.id];
  245. //We don't need this property, so let's delete it.
  246. delete datum.parent;
  247. //Let's add the current node as a child of the parent node.
  248. parentNode.children.push(datum);
  249. }
  250. }
  251. return root;
  252. }
  253. function convertParentToChildList(data) {
  254. var treeMap = {};
  255. var list = [];
  256. convertListToTree(data, treeMap);
  257. angular.forEach(treeMap, function(item) {
  258. list.push(item);
  259. });
  260. return list;
  261. }
  262. $scope.my_tree = tree = {};
  263. $scope.try_async_load = function() {
  264. $scope.my_data = [];
  265. $scope.select_treedata = [];
  266. $scope.doing_async = true;
  267. api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(result) {
  268. //console.log(result['list']);
  269. $scope.select_treedata = $scope.my_data = convertParentToChildList(result['list']);
  270. $scope.doing_async = false;
  271. // tree.expand_all();
  272. //console.log(treelist);
  273. });
  274. };
  275. $scope.select_treedata = [];
  276. $scope.propTypeOptions = [];
  277. $scope.try_async_load();
  278. $scope.onFilterremove = function(item) {
  279. console.log(item)
  280. }
  281. $scope.onFilterCallback = function(item) {
  282. //console.log(item);
  283. if (angular.isDefined(item.children) && item.children.length >= 1) {
  284. //not valid
  285. } else {
  286. var tempclassify = item.prefix.toLowerCase() + item.sign;
  287. $scope.gridApi.grid.options.paginationCurrentPage = 1;
  288. $scope.cifilter_classic = tempclassify;
  289. var memoryfilterData = {
  290. "sign": tempclassify,
  291. "idx": 0,
  292. "sum": $scope.gridOptions.paginationPageSize
  293. }
  294. angular.extend($scope.memoryfilterData, memoryfilterData)
  295. // $scope.memoryfilterData=memoryfilterData;
  296. $scope.refreshData('expand-right', $scope.memoryfilterData);
  297. // api_configure_form.renderTabForm(tempclassify).then(function(data){
  298. // var myData = Restangular.stripRestangular(data);
  299. // $scope.propTypeOptions = myData;
  300. // });
  301. }
  302. }
  303. //关系下载模版
  304. api_configure_data.fetchDataList('ciedgetype', { 'idx': 0, 'sum': 100 }).then(function(response) {
  305. if (response) {
  306. $scope.linktypeOptions = response.list;
  307. // angular.forEach($scope.linktypeOptions,function(item){
  308. // if(item.type==$scope.modelData.name){
  309. // $scope.modelData.linkName=item;
  310. // }
  311. // })
  312. }
  313. })
  314. $scope.rela = {};
  315. $scope.onChange = function(rela) {
  316. $scope.rela = rela;
  317. }
  318. //下载关系属性模版
  319. $scope.openmodel = function() {
  320. var modalInstance = $modal.open({
  321. templateUrl: 'assets/views/means/tpl/relationdown.html',
  322. controller: function($scope, scope, $modalInstance) {
  323. $scope.key = {};
  324. $scope.linktypeOptions = scope.linktypeOptions;
  325. $scope.ok = function(key) {
  326. $modalInstance.close(key);
  327. };
  328. $scope.cancel = function() {
  329. $modalInstance.dismiss('cancel');
  330. };
  331. },
  332. size: 'sm',
  333. resolve: {
  334. scope: function() {
  335. return $scope;
  336. }
  337. }
  338. });
  339. modalInstance.result.then(function(selectedItem) {
  340. if (selectedItem && angular.isDefined(selectedItem.type)) {
  341. // if (angular.isDefined(selectedItem.type)) {
  342. var type = 2;
  343. // api_configure_data.fetchDataList('ciedgetype',{'idx':0,'sum':100}).then(function(data){
  344. // if(data.status==200){
  345. // var myData = Restangular.stripRestangular(data).list;
  346. // for(var i=0;i<myData.length;i++){
  347. $http({
  348. url: api_configure_data.downModels(type, selectedItem.id, selectedItem.label).getRequestedUrl(),
  349. method: 'GET',
  350. headers: {
  351. // 'Content-type' : 'application/xls',
  352. 'Accept': '*/*'
  353. },
  354. responseType: 'arraybuffer'
  355. }).success(function(data, status, headers, config) {
  356. var file = new Blob([data], {
  357. type: 'application/octet-stream'
  358. // type : 'application/vnd.ms-excel'
  359. });
  360. //trick to download store a file having its URL
  361. var fileURL = URL.createObjectURL(file);
  362. var a = document.createElement('a');
  363. a.href = fileURL;
  364. a.target = '_blank';
  365. a.download = "关系属性.xlsx";
  366. document.body.appendChild(a);
  367. a.click();
  368. }).error(function(data, status, headers, config) {
  369. console.log(data);
  370. });
  371. } else {
  372. SweetAlert.swal({
  373. title: "未选择资产关系!",
  374. text: "请选择资产关系",
  375. type: "error"
  376. })
  377. }
  378. });
  379. }
  380. // $scope.getdown = function() {
  381. // if (angular.isDefined($scope.rela) && angular.isDefined($scope.rela.type)) {
  382. // var type = 2;
  383. // // api_configure_data.fetchDataList('ciedgetype',{'idx':0,'sum':100}).then(function(data){
  384. // // if(data.status==200){
  385. // // var myData = Restangular.stripRestangular(data).list;
  386. // // for(var i=0;i<myData.length;i++){
  387. // $http({
  388. // url: api_configure_data.downModels(type, $scope.rela.id, $scope.rela.label).getRequestedUrl(),
  389. // method: 'GET',
  390. // headers: {
  391. // // 'Content-type' : 'application/xls',
  392. // 'Accept': '*/*'
  393. // },
  394. // responseType: 'arraybuffer'
  395. // }).success(function(data, status, headers, config) {
  396. // var file = new Blob([data], {
  397. // type: 'application/octet-stream'
  398. // // type : 'application/vnd.ms-excel'
  399. // });
  400. // //trick to download store a file having its URL
  401. // var fileURL = URL.createObjectURL(file);
  402. // var a = document.createElement('a');
  403. // a.href = fileURL;
  404. // a.target = '_blank';
  405. // a.download = "关系属性.xlsx";
  406. // document.body.appendChild(a);
  407. // a.click();
  408. // }).error(function(data, status, headers, config) {
  409. // console.log(data);
  410. // });
  411. // // break;
  412. // // }
  413. // // }
  414. // // })
  415. // } else {
  416. // SweetAlert.swal({
  417. // title: "未选择资产关系!",
  418. // text: "请选择资产关系",
  419. // type: "error"
  420. // })
  421. // }
  422. // }
  423. $scope.importopen = function() { //导入触发事件
  424. var modalInstance = $modal.open({
  425. templateUrl: 'assets/views/import.html',
  426. controller: function($scope, $modalInstance, FileUploader) {
  427. var importUploader = $scope.importUploader = new FileUploader({
  428. url: api_cmdb.importData().getRequestedUrl(),
  429. alias: "file",
  430. removeAfterUpload: true
  431. });
  432. importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
  433. console.info('onWhenAddingFileFailed', item, filter, options);
  434. };
  435. importUploader.onAfterAddingFile = function(fileItem) {
  436. console.info('onAfterAddingFile', fileItem);
  437. if ($scope.importUploader.queue.length > 1) {
  438. $scope.importUploader.queue.splice(0, 1);
  439. }
  440. };
  441. importUploader.onAfterAddingAll = function(addedFileItems) {
  442. console.info('onAfterAddingAll', addedFileItems);
  443. };
  444. importUploader.onProgressItem = function(fileItem, progress) {
  445. console.info('onProgressItem', fileItem, progress);
  446. };
  447. importUploader.onProgressAll = function(progress) {
  448. console.info('onProgressAll', progress);
  449. };
  450. importUploader.onSuccessItem = function(fileItem, response, status, headers) {
  451. if (response.status == 200) {
  452. SweetAlert.swal({
  453. title: "导入成功!",
  454. confirmButtonColor: "#007AFF",
  455. type: "success"
  456. }, function() {
  457. $rootScope.isMask = false;
  458. // $scope.ldloading.expand_right = false;
  459. });
  460. console.info('onSuccessItem', fileItem, response, status, headers);
  461. } else {
  462. SweetAlert.swal({
  463. title: "导入失败!",
  464. text: response.error,
  465. type: "error"
  466. }, function() {
  467. $rootScope.isMask = false;
  468. // $scope.ldloading.expand_right = false;
  469. });
  470. }
  471. };
  472. importUploader.onErrorItem = function(fileItem, response, status, headers) {
  473. console.info('onErrorItem', fileItem, response, status, headers);
  474. SweetAlert.swal({
  475. title: "系统错误!",
  476. text: "系统错误,请稍候重试!",
  477. type: "error"
  478. }, function() {
  479. // $scope.ldloading.expand_right = false;
  480. $rootScope.isMask = false;
  481. });
  482. };
  483. importUploader.onCancelItem = function(fileItem, response, status, headers) {
  484. console.info('onCancelItem', fileItem, response, status, headers);
  485. };
  486. importUploader.onCompleteItem = function(fileItem, response, status, headers) {
  487. console.info('onCompleteItem', fileItem, response, status, headers);
  488. };
  489. importUploader.onCompleteAll = function() {
  490. console.info('onCompleteAll');
  491. };
  492. $scope.import = function(style) {
  493. // $scope.ldloading[style.replace('-', '_')] = true;
  494. $rootScope.isMask = true;
  495. importUploader.onBeforeUploadItem = function(item) {
  496. angular.extend(item.headers, $rootScope.getSession());
  497. item.formData.push({ 'filename': item.file.name });
  498. console.info('onBeforeUploadItem', item);
  499. };
  500. importUploader.uploadAll();
  501. }
  502. $scope.cancel = function() {
  503. $modalInstance.dismiss('cancel');
  504. };
  505. },
  506. size: 'sm',
  507. resolve: {
  508. importUploader: function() {
  509. return $scope.importUploader;
  510. }
  511. }
  512. });
  513. modalInstance.result.then(function(selectedItem) {
  514. if (selectedItem) {}
  515. })
  516. }
  517. //添加
  518. $scope.addData = function(size) {
  519. $state.go('app.means.editor', { formKey: 'means_editor', service: 'api_bpm_data' });
  520. }
  521. //下载资产模版
  522. $scope.openmeans = function() {
  523. var modalInstance = $modal.open({
  524. templateUrl: 'assets/views/means/tpl/meansdown.html',
  525. controller: function($scope, scope, $modalInstance) {
  526. $scope.item = {};
  527. $scope.headname = "资产模版下载";
  528. $scope.select_treedata = scope.select_treedata;
  529. $scope.ok = function(item) {
  530. $modalInstance.close(item);
  531. };
  532. $scope.cancel = function() {
  533. $modalInstance.dismiss('cancel');
  534. };
  535. },
  536. size: 'sm',
  537. resolve: {
  538. scope: function() {
  539. return $scope;
  540. }
  541. }
  542. });
  543. modalInstance.result.then(function(selectedItem) {
  544. $rootScope.isMask = true;
  545. if (selectedItem) {
  546. // if (angular.isDefined(classfy)) {
  547. var type = 1;
  548. // api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
  549. // if (data.status == 200) {
  550. // var myData = Restangular.stripRestangular(data).list;
  551. // for (var i = 0; i < $scope.select_treedata.length; i++) {
  552. // if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
  553. $http({
  554. url: api_configure_data.downModels(type, selectedItem.id, selectedItem.label).getRequestedUrl(),
  555. method: 'GET',
  556. headers: {
  557. // 'Content-type' : 'application/xls',
  558. 'Accept': '*/*'
  559. },
  560. responseType: 'arraybuffer'
  561. }).success(function(data, status, headers, config) {
  562. $rootScope.isMask = false;
  563. var file = new Blob([data], {
  564. type: 'application/octet-stream'
  565. // type : 'application/vnd.ms-excel'
  566. });
  567. //trick to download store a file having its URL
  568. var fileURL = URL.createObjectURL(file);
  569. var a = document.createElement('a');
  570. a.href = fileURL;
  571. a.target = '_blank';
  572. a.download = "资产属性.xlsx";
  573. document.body.appendChild(a);
  574. a.click();
  575. }).error(function(data, status, headers, config) {
  576. console.log(data);
  577. $rootScope.isMask = false;
  578. });
  579. // break;
  580. // }
  581. // }
  582. // }
  583. // })
  584. } else {
  585. SweetAlert.swal({
  586. title: "未选择资产分类!",
  587. text: "请选择资产分类",
  588. type: "error"
  589. }, function() {
  590. $rootScope.isMask = false;
  591. });
  592. }
  593. // }
  594. });
  595. }
  596. // //导出模版
  597. // $scope.download = function(classfy) {
  598. // if (angular.isDefined(classfy)) {
  599. // var type = 1;
  600. // api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
  601. // if (data.status == 200) {
  602. // var myData = Restangular.stripRestangular(data).list;
  603. // for (var i = 0; i < myData.length; i++) {
  604. // if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
  605. // $http({
  606. // url: api_configure_data.downModels(type, myData[i].id, myData[i].label).getRequestedUrl(),
  607. // method: 'GET',
  608. // headers: {
  609. // // 'Content-type' : 'application/xls',
  610. // 'Accept': '*/*'
  611. // },
  612. // responseType: 'arraybuffer'
  613. // }).success(function(data, status, headers, config) {
  614. // var file = new Blob([data], {
  615. // type: 'application/octet-stream'
  616. // // type : 'application/vnd.ms-excel'
  617. // });
  618. // //trick to download store a file having its URL
  619. // var fileURL = URL.createObjectURL(file);
  620. // var a = document.createElement('a');
  621. // a.href = fileURL;
  622. // a.target = '_blank';
  623. // a.download = "资产属性.xlsx";
  624. // document.body.appendChild(a);
  625. // a.click();
  626. // }).error(function(data, status, headers, config) {
  627. // console.log(data);
  628. // });
  629. // break;
  630. // }
  631. // }
  632. // }
  633. // })
  634. // } else {
  635. // SweetAlert.swal({
  636. // title: "未选择资产分类!",
  637. // text: "请选择资产分类",
  638. // type: "error"
  639. // })
  640. // }
  641. // }
  642. //导出
  643. $scope.exportopen = function() {
  644. var modalInstance = $modal.open({
  645. templateUrl: 'assets/views/means/tpl/meansdown.html',
  646. controller: function($scope, scope, $modalInstance) {
  647. $scope.item = {};
  648. $scope.headname = "资产导出";
  649. $scope.select_treedata = scope.select_treedata;
  650. $scope.ok = function(item) {
  651. $modalInstance.close(item);
  652. };
  653. $scope.cancel = function() {
  654. $modalInstance.dismiss('cancel');
  655. };
  656. },
  657. size: 'sm',
  658. resolve: {
  659. scope: function() {
  660. return $scope;
  661. }
  662. }
  663. });
  664. modalInstance.result.then(function(selectedItem) {
  665. $rootScope.isMask = true;
  666. if (selectedItem) {
  667. // if (angular.isDefined(classfy)) {
  668. var type = 1;
  669. // api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
  670. // if (data.status == 200) {
  671. // var myData = Restangular.stripRestangular(data).list;
  672. // for (var i = 0; i < $scope.select_treedata.length; i++) {
  673. // if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
  674. $http({
  675. url: api_cmdb.exportData(selectedItem.label, selectedItem.id).getRequestedUrl(),
  676. method: 'GET',
  677. headers: {
  678. // 'Content-type' : 'application/xls',
  679. 'Accept': '*/*'
  680. },
  681. responseType: 'arraybuffer'
  682. }).success(function(data, status, headers, config) {
  683. $rootScope.isMask = false;
  684. var file = new Blob([data], {
  685. type: 'application/octet-stream'
  686. // type : 'application/vnd.ms-excel'
  687. });
  688. //trick to download store a file having its URL
  689. var fileURL = URL.createObjectURL(file);
  690. var a = document.createElement('a');
  691. a.href = fileURL;
  692. a.target = '_blank';
  693. a.download = selectedItem.label + '.xlsx';
  694. document.body.appendChild(a);
  695. a.click();
  696. }).error(function(data, status, headers, config) {
  697. $rootScope.isMask = false;
  698. console.log(data);
  699. });
  700. // break;
  701. // }
  702. // }
  703. // }
  704. // })
  705. } else {
  706. SweetAlert.swal({
  707. title: "未选择资产分类!",
  708. text: "请选择资产分类",
  709. type: "error"
  710. }, function() {
  711. $rootScope.isMask = false;
  712. });
  713. }
  714. // }
  715. });
  716. }
  717. // $scope.export = function(classfy, style) {
  718. // if (angular.isDefined(classfy)) {
  719. // $scope.ldloading[style.replace('-', '_')] = true;
  720. // api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
  721. // if (data.status == 200) {
  722. // var myData = Restangular.stripRestangular(data).list;
  723. // for (var i = 0; i < myData.length; i++) {
  724. // if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
  725. // $http({
  726. // url: api_cmdb.exportData(myData[i].label, myData[i].id).getRequestedUrl(),
  727. // method: 'GET',
  728. // headers: {
  729. // // 'Content-type' : 'application/xls',
  730. // 'Accept': '*/*'
  731. // },
  732. // responseType: 'arraybuffer'
  733. // }).success(function(data, status, headers, config) {
  734. // $scope.ldloading.zoom_in = false;
  735. // var file = new Blob([data], {
  736. // type: 'application/octet-stream'
  737. // // type : 'application/vnd.ms-excel'
  738. // });
  739. // //trick to download store a file having its URL
  740. // var fileURL = URL.createObjectURL(file);
  741. // var a = document.createElement('a');
  742. // a.href = fileURL;
  743. // a.target = '_blank';
  744. // a.download = myData[i].label + '.xlsx';
  745. // document.body.appendChild(a);
  746. // a.click();
  747. // }).error(function(data, status, headers, config) {
  748. // $scope.ldloading.zoom_in = false;
  749. // console.log(data);
  750. // });
  751. // break;
  752. // }
  753. // }
  754. // }
  755. // })
  756. // } else {
  757. // SweetAlert.swal({
  758. // title: "未选择资产分类!",
  759. // text: "请选择资产分类",
  760. // type: "error"
  761. // })
  762. // }
  763. // }
  764. // }
  765. //导入
  766. var importUploader = $scope.importUploader = new FileUploader({
  767. url: api_cmdb.importData().getRequestedUrl()
  768. });
  769. importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
  770. console.info('onWhenAddingFileFailed', item, filter, options);
  771. };
  772. importUploader.onAfterAddingFile = function(fileItem) {
  773. console.info('onAfterAddingFile', fileItem);
  774. };
  775. importUploader.onAfterAddingAll = function(addedFileItems) {
  776. console.info('onAfterAddingAll', addedFileItems);
  777. };
  778. importUploader.onProgressItem = function(fileItem, progress) {
  779. console.info('onProgressItem', fileItem, progress);
  780. };
  781. importUploader.onProgressAll = function(progress) {
  782. console.info('onProgressAll', progress);
  783. };
  784. importUploader.onSuccessItem = function(fileItem, response, status, headers) {
  785. if (response.status == 200) {
  786. SweetAlert.swal({
  787. title: "导入成功!",
  788. confirmButtonColor: "#007AFF",
  789. type: "success"
  790. }, function() {
  791. $rootScope.isMask = false;
  792. });
  793. console.info('onSuccessItem', fileItem, response, status, headers);
  794. } else {
  795. SweetAlert.swal({
  796. title: "导入失败!",
  797. text: response.error,
  798. type: "error"
  799. }, function() {
  800. $rootScope.isMask = false;
  801. });
  802. }
  803. };
  804. importUploader.onErrorItem = function(fileItem, response, status, headers) {
  805. console.info('onErrorItem', fileItem, response, status, headers);
  806. SweetAlert.swal({
  807. title: "系统错误!",
  808. text: "系统错误,请稍候重试!",
  809. type: "error"
  810. }, function() {
  811. $rootScope.isMask = false;
  812. });
  813. };
  814. importUploader.onCancelItem = function(fileItem, response, status, headers) {
  815. console.info('onCancelItem', fileItem, response, status, headers);
  816. };
  817. importUploader.onCompleteItem = function(fileItem, response, status, headers) {
  818. console.info('onCompleteItem', fileItem, response, status, headers);
  819. };
  820. importUploader.onCompleteAll = function() {
  821. console.info('onCompleteAll');
  822. };
  823. $scope.import = function(style) {
  824. $rootScope.isMask = true;
  825. importUploader.onBeforeUploadItem = function(item) {
  826. angular.extend(item.headers, $rootScope.getSession());
  827. item.formData.push({ 'filename': item.file.name });
  828. console.info('onBeforeUploadItem', item);
  829. };
  830. importUploader.uploadAll();
  831. }
  832. $scope.removeData = function() {
  833. var rmvList = $scope.selected.items.id;
  834. // angular.forEach($scope.selected.items,function(item){
  835. // rmvList.push(item.id);
  836. // });
  837. // if(rmvList.length>0){
  838. api_cmdb.put($scope.selected.items, rmvList).then(function(response) {
  839. if (response.status == 200) {
  840. SweetAlert.swal({
  841. title: "删除成功!",
  842. type: "success",
  843. confirmButtonColor: "#007AFF"
  844. }, function() {
  845. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  846. $scope.selected = {
  847. items: []
  848. };
  849. });
  850. } else {
  851. SweetAlert.swal({
  852. title: "操作异常!",
  853. text: "系统异常,请稍后重试,或者联系管理员!",
  854. type: "error"
  855. });
  856. }
  857. })
  858. // }
  859. }
  860. $scope.selected = {
  861. items: []
  862. }
  863. $scope.editted = {
  864. items: []
  865. }
  866. var defaultFilterData = {
  867. // "assignee":2,
  868. // "sign":"basehwitndl",
  869. "idx": 0,
  870. "sum": $scope.gridOptions.paginationPageSize
  871. };
  872. $scope.memoryfilterData = {
  873. // "assignee":2,
  874. // "sign":"basehwitndl",
  875. "idx": 0,
  876. "sum": $scope.gridOptions.paginationPageSize
  877. }
  878. $scope.ldloading = {};
  879. var pdKey = $state.current.pdKey;
  880. $scope.refreshData = function(style, filterData) {
  881. if (angular.isUndefined(filterData)) {
  882. filterData = defaultFilterData;
  883. }
  884. $scope.myData = [];
  885. // $scope.gridOptions['sum']=filterData.sum;
  886. api_cmdb.jry_query(filterData).then(function(data) {
  887. // $scope.callsPending--;
  888. var myData = Restangular.stripRestangular(data);
  889. $scope.gridOptions['totalItems'] = data.total;
  890. // angular.forEach(myData.data.node,function(item){
  891. // moment(item.createtime).format('YYYY-MM-DD');
  892. // })
  893. for (var i = 0; i < myData.data.node.length; i++) {
  894. myData.data.node[i].createtime = moment(myData.data.node[i].createtime).format('YYYY-MM-DD');
  895. }
  896. $scope.myData = myData.data.node;
  897. }, function() {});
  898. };
  899. $scope.refreshData('expand-right', defaultFilterData);
  900. }]);
  901. app.controller('MeansOperCtrl', ['$rootScope', '$http', '$scope', function($rootScope, $http, $scope) {
  902. // console.log('$rootScope.user3='+JSON.stringify($scope.item));
  903. // if( $scope.item.handlerUser!=null){
  904. // if ($rootScope.user.id==$scope.item.handlerUser.id) {
  905. // $scope.item.chaozuoPower=true;
  906. // }
  907. // }
  908. $scope.look = function() {
  909. $scope.colobject.grid.appScope.lookFunction($scope.item);
  910. // console.log('$scope.item='+JSON.stringify($scope.item));
  911. }
  912. $scope.edit = function() {
  913. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  914. console.log('$scope.item=' + JSON.stringify($scope.item));
  915. // $scope.doEdit($scope.item.id);
  916. }
  917. }]);
  918. app.directive('meansoperator', function() {
  919. return {
  920. restrict: 'E',
  921. scope: {
  922. item: '=',
  923. colobject: '='
  924. },
  925. controller: 'MeansOperCtrl',
  926. template: '<div class="links cl-effect-1">' +
  927. '<a ng-click="look()" tooltip="查看" tooltip-placement="left"><i class="ti-eye"></i></a>' +
  928. '<a ng-click="edit()" tooltip="修改" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>' +
  929. '</div>'
  930. };
  931. });