adminrequesterCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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%', enableFiltering: false },
  54. // { name: 'studentNo', displayName: '学号', width: 120 },
  55. { name: 'account', displayName: '学工号', width: '15%', enableFiltering: false },
  56. { name: 'dept.dept', displayName: '部门', width: '15%', enableFiltering: false },
  57. { name: 'mphone', displayName: '电话', width: '15%', enableFiltering: false },
  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.jry_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. if(data.place){
  236. var modelData = {
  237. model: {
  238. requester: {
  239. "id": data.id,
  240. "account": data.account,
  241. "name": data.name,
  242. "gender": data.gender,
  243. "email": data.email,
  244. "mphone": data.mphone,
  245. "deptName": data.deptName,
  246. "telephone": data.telephone,
  247. "dept": data.dept,
  248. "area": data.place.area,
  249. "place": data.place,
  250. "studentNo": data.studentNo,
  251. "houseNumber": data.houseNumber,
  252. "requesterTypeDTO": data.requesterTypeDTO
  253. }
  254. }
  255. };
  256. }else{
  257. var modelData = {
  258. model: {
  259. requester: {
  260. "id": data.id,
  261. "account": data.account,
  262. "name": data.name,
  263. "gender": data.gender,
  264. "email": data.email,
  265. "mphone": data.mphone,
  266. "deptName": data.deptName,
  267. "telephone": data.telephone,
  268. "dept": data.dept,
  269. // "area": data.place.area,
  270. "place": data.place,
  271. "studentNo": data.studentNo,
  272. "houseNumber": data.houseNumber,
  273. "requesterTypeDTO": data.requesterTypeDTO
  274. }
  275. }
  276. };
  277. }
  278. $state.go('app.system.user.requester', { formKey: 'system_edit_requester', service: 'api_user_data', model: JSON.stringify(modelData) });
  279. };
  280. //新增
  281. $scope.addData = function() {
  282. $state.go('app.system.user.requester', { formKey: 'system_edit_requester', service: 'api_user_data' })
  283. }
  284. $scope.removeData = function() {
  285. var modalInstance = $modal.open({
  286. templateUrl: 'assets/views/delete.html',
  287. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  288. var rmvList = [];
  289. $scope.title = '报修人删除';
  290. $scope.connect = '确定要删除此报修人?';
  291. rmvList.push(scope.selected.items[0].id);
  292. $scope.ok = function() {
  293. $modalInstance.close(rmvList);
  294. };
  295. $scope.cancel = function() {
  296. $modalInstance.dismiss('cancel');
  297. };
  298. },
  299. size: 'sm',
  300. resolve: {
  301. scope: function() {
  302. return $scope;
  303. }
  304. }
  305. });
  306. modalInstance.result.then(function(selectedItem) {
  307. if (selectedItem) {
  308. if (selectedItem.length > 0) {
  309. api_user_data.rmvData('requester', selectedItem).then(function(response) {
  310. if (response.data) {
  311. SweetAlert.swal({
  312. title: "删除成功!",
  313. type: "success",
  314. confirmButtonColor: "#007AFF"
  315. }, function() {
  316. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id) });
  317. $scope.selected = {
  318. items: []
  319. };
  320. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  321. $scope.gridApi.grid.selection.selectedCount = 0;
  322. });
  323. } else {
  324. SweetAlert.swal({
  325. title: "操作异常!",
  326. text: "系统异常,请稍后重试,或者联系管理员!",
  327. type: "error"
  328. });
  329. }
  330. })
  331. }
  332. }
  333. })
  334. }
  335. $scope.selected = {
  336. items: []
  337. }
  338. $scope.editted = {
  339. items: []
  340. }
  341. $scope.gridOptions.onRegisterApi = function(gridApi) {
  342. $scope.gridApi = gridApi;
  343. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  344. // console.log(rowEntity);
  345. // });
  346. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  347. var filtersData = $scope.memoryfilterData;
  348. filtersData.idx = newPage - 1;
  349. filtersData.sum = pageSize;
  350. defaultFilterData = filtersData;
  351. $scope.refreshData('expand-right', filtersData);
  352. });
  353. // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  354. // data.grid.appScope.selected.items = data.entity
  355. // });
  356. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  357. if (data.isSelected) {
  358. data.grid.appScope.selected.items[0] = data.entity;
  359. } else {
  360. if (data.grid.appScope.selected.items[0].id == data.entity.id) {
  361. data.grid.appScope.selected.items = [];
  362. }
  363. }
  364. });
  365. gridApi.core.on.filterChanged($scope, function() {
  366. var grid = this.grid;
  367. var filtersData = {
  368. idx: 0,
  369. sum: 10
  370. };
  371. angular.forEach(grid.columns, function(item) {
  372. if (item.enableFiltering) {
  373. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  374. if (angular.isUndefined(filtersData['requester'])) {
  375. filtersData['requester'] = {};
  376. }
  377. filtersData['requester'][item.field] = item.filters[0].term;
  378. }
  379. }
  380. });
  381. $scope.memoryfilterData = filtersData;
  382. $scope.refreshData('expand-right', filtersData);
  383. });
  384. };
  385. var defaultFilterData = {
  386. "idx": 0,
  387. "sum": 10
  388. };
  389. $scope.memoryfilterData = {
  390. "idx": 0,
  391. "sum": 10
  392. }
  393. $scope.ldloading = {};
  394. $scope.refresh = function(style, filterData) {
  395. $scope.selected = { items: [] };
  396. if ($scope.gridApi) {
  397. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  398. $scope.gridApi.grid.selection.selectedCount = 0;
  399. }
  400. $scope.refreshData('expand-right', defaultFilterData);
  401. }
  402. $scope.refreshData = function(style, filterData) {
  403. $scope.ldloading[style.replace('-', '_')] = true;
  404. if (angular.isUndefined(filterData)) {
  405. filterData = defaultFilterData;
  406. }
  407. if (angular.isDefined($scope.searchTypes)) {
  408. filterData['searchType'] = $scope.searchTypes;
  409. }
  410. $scope.myData = [];
  411. // if ($scope.gridApi) {
  412. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  413. // $scope.gridApi.grid.selection.selectedCount = 0;
  414. // }
  415. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  416. var myData = Restangular.stripRestangular(data);
  417. $scope.gridOptions.totalItems = myData.totalNum;
  418. $scope.myData = myData.list;
  419. for (var i = 0; i < $scope.myData.length; i++) {
  420. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  421. }
  422. $scope.ldloading[style.replace('-', '_')] = false;
  423. }, function() {
  424. $scope.ldloading[style.replace('-', '_')] = false;
  425. });
  426. };
  427. $scope.refreshData('expand-right', defaultFilterData);
  428. }]);