adminrequesterCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('adminUserListCtrl_requ', ["$rootScope","$scope","$http", "$state","FileUploader", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function ($rootScope, $scope,$http, $state,FileUploader, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data) {
  6. $scope.langs=i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser=$rootScope.user;
  10. //$scope.allright=false;
  11. //$scope.allrightnot=true;
  12. $scope.gridOptions = {};
  13. $scope.gridOptions.data = 'myData';
  14. $scope.gridOptions.enableColumnResizing = true;
  15. $scope.gridOptions.enableFiltering = false;
  16. $scope.gridOptions.enableGridMenu = false;
  17. $scope.gridOptions.enableRowSelection = true;
  18. $scope.gridOptions.showGridFooter = true;
  19. $scope.gridOptions.showColumnFooter = false;
  20. $scope.gridOptions.fastWatch = true;
  21. $scope.gridOptions.useExternalPagination = true;
  22. $scope.gridOptions.paginationPageSizes = [10];
  23. $scope.gridOptions.paginationPageSize = 10;
  24. $scope.gridOptions.multiSelect = false;
  25. //$scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(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>";
  26. $scope.gridOptions.rowIdentity = function(row) {
  27. return row.id;
  28. };
  29. $scope.gridOptions.getRowIdentity = function(row) {
  30. return row.id;
  31. };
  32. $scope.transferRole = function(roles){
  33. var tempValue="";
  34. angular.forEach(roles,function(item){
  35. if(tempValue!=""){
  36. tempValue = tempValue + "/" ;
  37. }
  38. tempValue = tempValue + item.role;
  39. })
  40. return tempValue;
  41. }
  42. //remote data
  43. $scope.gridOptions.columnDefs = [
  44. { name:'name', displayName:'姓名', width:100},
  45. { name:'account', displayName:'工号', width:140},
  46. { name:'deptName', displayName:'部门', width:140,enableFiltering:false},
  47. { name:'mphone', displayName:'电话', width:120,enableFiltering:false},
  48. { name:'编辑', cellTemplate:'<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  49. '<i class="fa fa-pencil-square-o"/></a>' , width:100,enableFiltering:false}
  50. ];
  51. var importUploader = $scope.importUploader = new FileUploader({
  52. url:api_user_data.importData().getRequestedUrl(),
  53. });
  54. // importUploader.filters.push({
  55. // name: 'customFilter',
  56. // fn: function(item /*{File|FileLikeObject}*/ , options) {
  57. // var type = item.name.slice(item.name.lastIndexOf('.') + 1);
  58. // //var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
  59. // return (type == 'xlsx');
  60. // }
  61. // });
  62. importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
  63. console.info('onWhenAddingFileFailed', item, filter, options);
  64. };
  65. importUploader.onAfterAddingFile = function(fileItem) {
  66. console.info('onAfterAddingFile', fileItem);
  67. };
  68. importUploader.onAfterAddingAll = function(addedFileItems) {
  69. console.info('onAfterAddingAll', addedFileItems);
  70. };
  71. importUploader.onProgressItem = function(fileItem, progress) {
  72. console.info('onProgressItem', fileItem, progress);
  73. };
  74. importUploader.onProgressAll = function(progress) {
  75. console.info('onProgressAll', progress);
  76. };
  77. importUploader.onSuccessItem = function(fileItem, response, status, headers) {
  78. if(response.status==200){
  79. SweetAlert.swal({
  80. title: "导入成功!",
  81. confirmButtonColor: "#007AFF",
  82. type: "success"
  83. },function(){
  84. $scope.ldloading.expand_right= false;
  85. $scope.refreshData('expand-right', defaultFilterData);
  86. // $scope.scheduleClass = {};
  87. // $scope.calendarView = 'month';
  88. // $scope.calendarDate = moment().startOf('month').toDate();
  89. // $scope.calendarTitle;
  90. // $scope.externalEvents = [];
  91. // api_bpm_schedule.getScheduleClass().then(function(response){
  92. // if(response.status == 200){
  93. // var scheduleClassList = response.list;
  94. // angular.forEach(scheduleClassList,function(item){
  95. // item.startsAt=moment(item.startTime).format('HH:mm:ss');
  96. // item.endsAt=moment(item.endTime).format('HH:mm:ss');
  97. // $scope.scheduleClass[item['code']]=item;
  98. // var templateEvent = {
  99. // title:item['description'],
  100. // type:item['code'],
  101. // startTime:item.startsAt,
  102. // //starts_at:
  103. // endTime:item.endsAt,
  104. // //ends_at:
  105. // draggable: true
  106. // };
  107. // $scope.externalEvents.push(templateEvent);
  108. // })
  109. // }
  110. // })
  111. });
  112. }else{
  113. $scope.ldloading.expand_right= false;
  114. SweetAlert.swal({
  115. title: "导入失败!",
  116. text: response.error,
  117. type: "error"
  118. })
  119. }
  120. console.info('onSuccessItem', fileItem, response, status, headers);
  121. };
  122. importUploader.onErrorItem = function(fileItem, response, status, headers) {
  123. console.info('onErrorItem', fileItem, response, status, headers);
  124. SweetAlert.swal({
  125. title: "系统错误!",
  126. text: "系统错误,请稍候重试!",
  127. type: "error"
  128. });
  129. };
  130. importUploader.onCancelItem = function(fileItem, response, status, headers) {
  131. console.info('onCancelItem', fileItem, response, status, headers);
  132. };
  133. importUploader.onCompleteItem = function(fileItem, response, status, headers) {
  134. console.info('onCompleteItem', fileItem, response, status, headers);
  135. };
  136. importUploader.onCompleteAll = function() {
  137. console.info('onCompleteAll');
  138. };
  139. $scope.ldloading = {};
  140. $scope.import = function(){
  141. $scope.ldloading.expand_right = true;
  142. importUploader.onBeforeUploadItem = function(item) {
  143. angular.extend(item.headers,$rootScope.getSession());
  144. item.formData.push({'filename':item.file.name});
  145. item.formData.push({'type':"requester"});
  146. console.info('onBeforeUploadItem',item);
  147. };
  148. importUploader.uploadAll();
  149. }
  150. $scope.download=function(){
  151. var type="requester";
  152. var month=0;
  153. $http({
  154. url : api_user_data.downDataModel(type,month).getRequestedUrl(),
  155. method : 'GET',
  156. headers : {
  157. // 'Content-type' : 'application/xls',
  158. 'Accept': '*/*'
  159. },
  160. responseType : 'arraybuffer'
  161. }).success(function(data, status, headers, config) {
  162. var file = new Blob([ data ], {
  163. // type : 'application/octet-stream'
  164. type : 'application/vnd.ms-excel'
  165. });
  166. //trick to download store a file having its URL
  167. var fileURL = URL.createObjectURL(file);
  168. var a = document.createElement('a');
  169. a.href = fileURL;
  170. a.target = '_blank';
  171. a.download = "请求人";
  172. document.body.appendChild(a);
  173. a.click();
  174. }).error(function(data, status, headers, config) {
  175. console.log(data);
  176. });
  177. }
  178. $scope.downloadtwo=function(){
  179. var type="requester";
  180. var month=1;
  181. $http({
  182. url : api_user_data.downDataModel(type,month).getRequestedUrl(),
  183. method : 'GET',
  184. headers : {
  185. // 'Content-type' : 'application/xls',
  186. 'Accept': '*/*'
  187. },
  188. responseType : 'arraybuffer'
  189. }).success(function(data, status, headers, config) {
  190. var file = new Blob([ data ], {
  191. type : 'application/octet-stream'
  192. // type : 'application/vnd.ms-excel'
  193. });
  194. //trick to download store a file having its URL
  195. var fileURL = URL.createObjectURL(file);
  196. var a = document.createElement('a');
  197. a.href = fileURL;
  198. a.target = '_blank';
  199. a.download = "请求人.xlsx";
  200. document.body.appendChild(a);
  201. a.click();
  202. }).error(function(data, status, headers, config) {
  203. console.log(data);
  204. });
  205. }
  206. $scope.saveData = function(data){
  207. $scope.requesterdata={};
  208. var filterData = {"idx":0,"sum":100};
  209. var modalInstance = $modal.open({
  210. templateUrl: 'assets/views/system/tpl/systemuser.html',
  211. controller: function($scope, $modalInstance, api_user_data){
  212. $scope.requesterdata=data;
  213. // $scope.falemchoice=[{id:1,gender:'男'},{id:2,gender:'女'}];
  214. $scope.cancel = function() {
  215. $modalInstance.dismiss('cancel');
  216. };
  217. $scope.savercode = function(requesterdata){
  218. var fildata={"requester":{
  219. "id":requesterdata.id,
  220. "account":requesterdata.account,
  221. "name":requesterdata.name,
  222. "gender":requesterdata.gender,
  223. "email":requesterdata.email,
  224. "mphone":requesterdata.mphone,
  225. "telephone":requesterdata.telephone,
  226. "deptName":requesterdata.deptName
  227. }}
  228. api_user_data.updData('requester',fildata).then(function(response){
  229. if(response){
  230. if(response.status==200){
  231. SweetAlert.swal({
  232. title:"修改成功!",
  233. type:"success"
  234. },function(){
  235. console.log($scope.serverdata)
  236. })
  237. }else{
  238. SweetAlert.swal({
  239. title:"修改失败!",
  240. type:"error"
  241. })
  242. }
  243. $modalInstance.close();
  244. }
  245. })
  246. }
  247. }
  248. });
  249. // $state.go('app.system.form_requester',{formKey:'system_edit_requester', service:'api_user_data', model : JSON.stringify(modelData)}
  250. // );
  251. };
  252. $scope.addData = function(){
  253. var modalInstance = $modal.open({
  254. templateUrl: 'assets/views/system/tpl/systemuser.html',
  255. controller: function($scope, $modalInstance, api_bpm_data){
  256. $scope.cancel = function() {
  257. $modalInstance.dismiss('cancel');
  258. };
  259. $scope.savercode = function(requesterdata) {
  260. $modalInstance.close(requesterdata);
  261. };
  262. }
  263. });
  264. modalInstance.result.then(function(selectedItem) {
  265. if(selectedItem){
  266. var fildata={"requester":{
  267. "account":selectedItem.account,
  268. "name":selectedItem.name,
  269. "gender":selectedItem.gender,
  270. "email":selectedItem.email,
  271. "mphone":selectedItem.mphone,
  272. "telephone":selectedItem.telephone,
  273. "deptName":selectedItem.deptName}}
  274. api_user_data.addData('requester',fildata).then(function(response){
  275. if(response){
  276. if(response.status==200){
  277. SweetAlert.swal({
  278. title:"新增成功!",
  279. type:"success"
  280. },function(){
  281. $scope.refreshData('expand-right', defaultFilterData);
  282. })
  283. }else{
  284. SweetAlert.swal({
  285. title:"新增失败!",
  286. type:"error"
  287. })
  288. }
  289. }
  290. })
  291. }
  292. });
  293. }
  294. $scope.removeData = function(){
  295. // var rmvList = [$scope.selected.items.id]
  296. var rmvList = [];
  297. angular.forEach($scope.selected.items,function(item){
  298. rmvList.push(item.id);
  299. });
  300. if(rmvList.length>0){
  301. api_user_data.rmvData('requester',rmvList).then(function(response){
  302. if(response.data){
  303. SweetAlert.swal({
  304. title: "删除成功!",
  305. type: "success",
  306. confirmButtonColor: "#007AFF"
  307. },function(){
  308. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  309. $scope.selected = {
  310. items:[]
  311. };
  312. });
  313. }else{
  314. SweetAlert.swal({
  315. title: "操作异常!",
  316. text: "系统异常,请稍后重试,或者联系管理员!",
  317. type: "error"
  318. });
  319. }
  320. })
  321. }
  322. }
  323. $scope.selected = {
  324. items:[]
  325. }
  326. $scope.editted = {
  327. items:[]
  328. }
  329. $scope.gridOptions.onRegisterApi = function(gridApi){
  330. $scope.gridApi = gridApi;
  331. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  332. // console.log(rowEntity);
  333. // });
  334. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  335. var filtersData = $scope.memoryfilterData;
  336. filtersData.idx=newPage-1;
  337. filtersData.sum=pageSize;
  338. $scope.refreshData('expand-right',filtersData);
  339. });
  340. gridApi.selection.on.rowSelectionChanged($scope, function(data){
  341. data.grid.appScope.selected.items=data.entity
  342. console.log(data);
  343. });
  344. // gridApi.core.on.filterChanged( $scope, function() {
  345. // var grid = this.grid;
  346. // var filtersData = {
  347. // idx:0,
  348. // sum:10
  349. // };
  350. // angular.forEach(grid.columns,function(item){
  351. // if(item.enableFiltering){
  352. // if(angular.isDefined(item.filters[0].term)&&item.filters[0].term!=''){
  353. // if(angular.isUndefined(filtersData['requester'])){
  354. // filtersData['requester']={};
  355. // }
  356. // filtersData['requester'][item.field]=item.filters[0].term;
  357. // }
  358. // }
  359. // });
  360. // // $scope.memoryfilterData = filterData
  361. // $scope.refreshData('expand-right', filtersData);
  362. // });
  363. };
  364. var defaultFilterData = {
  365. "idx":0,
  366. "sum":10
  367. };
  368. $scope.memoryfilterData = {
  369. "idx":0,
  370. "sum":10
  371. }
  372. $scope.ldloading = {};
  373. $scope.refreshData = function(style,filterData){
  374. $scope.ldloading[style.replace('-', '_')] = true;
  375. if(angular.isUndefined(filterData)){
  376. filterData = defaultFilterData;
  377. }
  378. if(angular.isDefined($scope.searchTypes)){
  379. filterData['searchType'] = $scope.searchTypes;
  380. }
  381. $scope.myData = [];
  382. api_user_data.fetchDataList('requester',filterData).then(function(data){
  383. var myData = Restangular.stripRestangular(data);
  384. $scope.gridOptions.totalItems = myData.totalNum;
  385. $scope.myData = myData.list;
  386. $scope.ldloading[style.replace('-', '_')] = false;
  387. },function(){
  388. $scope.ldloading[style.replace('-', '_')] = false;
  389. });
  390. };
  391. $scope.refreshData('expand-right', defaultFilterData);
  392. }]);