meansCtrl.js 35 KB

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