adminrequesterCtrl.js 19 KB

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