notice.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('noticeCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login) {
  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 = true;
  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 = true;
  26. $scope.gridOptions.rowTemplate = "<div ng-dblclick=\"grid.appScope.onDblClick(row.entity)\" 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. $scope.transferStatus = function(flag) {
  44. return (flag == 0) ? "有效" : "无效";
  45. }
  46. $scope.transfergroup = function(group) {
  47. var groupData = '';
  48. angular.forEach(group, function(item) {
  49. if (groupData == '') {
  50. groupData = item.groupName;
  51. } else {
  52. groupData = groupData + "/" + item.groupName;
  53. }
  54. })
  55. return groupData;
  56. }
  57. //remote data
  58. $scope.gridOptions.columnDefs = [{
  59. name: 'item',
  60. displayName: '序号',
  61. enableFiltering: false,
  62. width: 50
  63. },
  64. { name: 'title', displayName: '标题', width: '10%', enableFiltering: false },
  65. { name: 'createUser.name', displayName: '创建人', width: '10%', enableFiltering: false },
  66. // { name: 'areaDTO.area', displayName: '区域', width: '12%', enableFiltering: false },
  67. // { name: 'placeDTO.place', displayName: '地点', width: '12%', enableFiltering: false },
  68. { name: 'createTime', displayName: '创建时间', width: '15%', enableFiltering: false },
  69. { name: 'content', displayName: '内容', enableFiltering: false }
  70. //'<div class="links cl-effect-1">' +
  71. // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>'+
  72. // '</div>' , width:100, enableFiltering:false}
  73. ];
  74. //区域地点过滤
  75. $scope.key = {};
  76. api_user_data.fetchDataList('area', { "idx": 0, "sum": 1000 }).then(function(response) {
  77. if (response) {
  78. if (response.status = 200) {
  79. $scope.outarea = response.list;
  80. }
  81. }
  82. })
  83. $scope.onChangearea = function(data) {
  84. delete $scope.key.place;
  85. if ($scope.memoryfilterData.incident) {
  86. delete $scope.memoryfilterData.incident.place;
  87. }
  88. var fildata = { "idx": 0, "sum": 1000, "place": { areaId: data.area.id } };
  89. api_user_data.fetchDataList('place', fildata).then(function(response) {
  90. if (response) {
  91. if (response.status = 200) {
  92. $scope.outplace = response.list;
  93. }
  94. }
  95. })
  96. };
  97. //列表操作按钮-编辑
  98. $scope.saveData = function(data) {
  99. var modelData = { model: { notice: data } };
  100. $state.go('app.system.form', { formKey: 'noticeEditor', service: 'api_user_data', model: JSON.stringify(modelData) });
  101. };
  102. //列表操作按钮-查看
  103. $scope.onDblClick = function(data) {
  104. var modelfile = { model: { notice: data } };
  105. $state.go('app.system.form_editor', { formKey: 'noticeDetail', service: 'api_user_data', model: JSON.stringify(modelfile) });
  106. };
  107. //列表操作按钮-新增
  108. $scope.addData = function() {
  109. $state.go('app.system.form', { formKey: 'noticeEditor', service: 'api_user_data' });
  110. }
  111. $scope.removeData = function() {
  112. var modalInstance = $modal.open({
  113. templateUrl: 'assets/views/delete.html',
  114. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  115. var rmvList = [];
  116. $scope.title = '公告删除';
  117. $scope.connect = '确定要删除此公告?';
  118. angular.forEach(scope.selected.items, function(item) {
  119. rmvList.push(item.id);
  120. });
  121. $scope.ok = function() {
  122. $modalInstance.close(rmvList);
  123. };
  124. $scope.cancel = function() {
  125. $modalInstance.dismiss('cancel');
  126. };
  127. },
  128. size: 'sm',
  129. resolve: {
  130. scope: function() {
  131. return $scope;
  132. }
  133. }
  134. });
  135. modalInstance.result.then(function(selectedItem) {
  136. if (selectedItem) {
  137. if (selectedItem.length > 0) {
  138. api_user_data.rmvData('notice', selectedItem).then(function(response) {
  139. if (response.data) {
  140. SweetAlert.swal({
  141. title: "删除成功!",
  142. type: "success",
  143. confirmButtonColor: "#007AFF"
  144. }, function() {
  145. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  146. $scope.selected = {
  147. items: []
  148. };
  149. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  150. $scope.gridApi.grid.selection.selectedCount = 0;
  151. });
  152. } else {
  153. SweetAlert.swal({
  154. title: "操作异常!",
  155. text: "系统异常,请稍后重试,或者联系管理员!",
  156. type: "error"
  157. });
  158. }
  159. })
  160. }
  161. }
  162. })
  163. }
  164. $scope.selected = {
  165. items: []
  166. }
  167. $scope.editted = {
  168. items: []
  169. }
  170. $scope.gridOptions.onRegisterApi = function(gridApi) {
  171. $scope.gridApi = gridApi;
  172. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  173. // // console.log(rowEntity);
  174. // });
  175. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  176. var filtersData = $scope.memoryfilterData;
  177. filtersData.idx = newPage - 1;
  178. filtersData.sum = pageSize;
  179. defaultFilterData = filtersData;
  180. $scope.refreshData('expand-right', filtersData);
  181. });
  182. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  183. console.log("ok");
  184. var j = 0;
  185. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  186. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  187. j++;
  188. break;
  189. }
  190. }
  191. // console.log("j="+j)
  192. if (j == 1) {
  193. scope.grid.appScope.selected.items.splice(i, 1);
  194. } else {
  195. scope.grid.appScope.selected.items.push(scope.entity)
  196. }
  197. });
  198. gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows) {
  199. var selectitem = [];
  200. selectitem = angular.copy($scope.selected.items);
  201. for (var j = 0; j < rows.length; j++) {
  202. if (rows[j].isSelected == true) {
  203. selectitem.push(rows[j].entity);
  204. } else {
  205. delete selectitem[j];
  206. // rows.splice(j, 1);
  207. }
  208. }
  209. $scope.selected.items = [];
  210. for (var i = 0; i < selectitem.length; i++) {
  211. if (selectitem[i]) {
  212. $scope.selected.items.push(selectitem[i]);
  213. }
  214. }
  215. });
  216. gridApi.core.on.filterChanged($scope, function() {
  217. var grid = this.grid;
  218. // var filtersData = {
  219. // idx: 0,
  220. // sum: 10
  221. // };
  222. var filtersData = $scope.memoryfilterData;
  223. angular.forEach(grid.columns, function(item) {
  224. if (item.enableFiltering) {
  225. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  226. if (angular.isUndefined(filtersData['user'])) {
  227. filtersData['notice'] = {};
  228. // filtersData['user']['flag'] = -1;
  229. filtersData['notice'][item.field] = item.filters[0].term;
  230. } else {
  231. // filtersData.user.flag = -1;
  232. filtersData.notice[item.field] = item.filters[0].term;
  233. }
  234. // filtersData['user']['flag'] = -1;
  235. // filtersData['user'][item.field] = item.filters[0].term;
  236. }
  237. }
  238. });
  239. $scope.memoryfilterData = filtersData;
  240. $scope.refreshData('expand-right', filtersData);
  241. });
  242. };
  243. var defaultFilterData = {
  244. "idx": 0,
  245. "sum": 10
  246. };
  247. $scope.memoryfilterData = {
  248. "idx": 0,
  249. "sum": 10
  250. }
  251. $scope.ldloading = {};
  252. $scope.refresh = function(style, filterData) {
  253. $scope.selected = { items: [] };
  254. if ($scope.gridApi) {
  255. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  256. $scope.gridApi.grid.selection.selectedCount = 0;
  257. }
  258. $scope.refreshData('expand-right', defaultFilterData);
  259. }
  260. //获取数据
  261. $scope.refreshData = function(style, filterData) {
  262. $scope.ldloading[style.replace('-', '_')] = true;
  263. if (angular.isUndefined(filterData)) {
  264. filterData = defaultFilterData;
  265. }
  266. if (angular.isDefined($scope.searchTypes)) {
  267. filterData['searchType'] = $scope.searchTypes;
  268. }
  269. $scope.myData = [];
  270. // filterData['flag'] = -1;
  271. // console.log("filterData=" + JSON.stringify(filterData))
  272. api_user_data.fetchDataList('notice', filterData).then(function(data) {
  273. var myData = Restangular.stripRestangular(data);
  274. $scope.gridOptions.totalItems = myData.totalNum;
  275. $scope.myData = myData.list;
  276. for (var i = 0; i < $scope.myData.length; i++) {
  277. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  278. $scope.myData[i]['createTime']=$scope.myData[i]['createTime'].split('.')[0]
  279. }
  280. $scope.ldloading[style.replace('-', '_')] = false;
  281. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  282. }, function() {
  283. $scope.ldloading[style.replace('-', '_')] = false;
  284. });
  285. };
  286. $scope.refreshData('expand-right', defaultFilterData);
  287. }]);