worktimeCtrl.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('woketimeCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_wechatfile) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. $scope.gridOptions = {};
  11. $scope.gridOptions.data = 'myData';
  12. $scope.gridOptions.enableColumnResizing = true;
  13. $scope.gridOptions.enableFiltering = true;
  14. $scope.gridOptions.enableGridMenu = false;
  15. $scope.gridOptions.enableRowSelection = true;
  16. $scope.gridOptions.showGridFooter = true;
  17. $scope.gridOptions.showColumnFooter = false;
  18. $scope.gridOptions.fastWatch = true;
  19. $scope.gridOptions.useExternalFiltering = true;
  20. $scope.gridOptions.useExternalPagination = true;
  21. $scope.gridOptions.paginationPageSizes = [10];
  22. $scope.gridOptions.paginationPageSize = 10;
  23. $scope.gridOptions.multiSelect = false;
  24. //$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>";
  25. $scope.gridOptions.rowIdentity = function(row) {
  26. return row.id;
  27. };
  28. $scope.gridOptions.getRowIdentity = function(row) {
  29. return row.id;
  30. };
  31. $scope.transfer = function(deleteFlag) {
  32. if (deleteFlag == true) { return "是" } else { return "否" }
  33. }
  34. $scope.transferstatus = function(deleteFlag) {
  35. if (deleteFlag == true) { return "停用" } else { return "使用" }
  36. }
  37. $scope.translate = function(item) {
  38. return moment(item).format('HH:mm')
  39. }
  40. $scope.gridOptions.columnDefs = [
  41. { name: 'item', displayName: '序号', width: 50, enableFiltering: false },
  42. { name: 'name', displayName: '班次', width: '10%', enableFiltering: false },
  43. {
  44. name: 'startTime',
  45. displayName: '开始时间',
  46. width: '10%',
  47. enableFiltering: false,
  48. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.translate(row.entity.startTime)}}</div>'
  49. },
  50. {
  51. name: 'endTime',
  52. displayName: '结束时间',
  53. width: '10%',
  54. enableFiltering: false,
  55. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.translate(row.entity.endTime)}}</div>'
  56. },
  57. { name: 'person', displayName: '本班次人数', width: '10%', enableFiltering: false },
  58. { name: 'dictionaryDTO.name', displayName: '季节', width: '10%', enableFiltering: false },
  59. { name: 'description', displayName: '班次描述', width: '12%', enableFiltering: false },
  60. { name: 'deleteFlag', displayName: '使用状态', width: '10%', enableFiltering: false, cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferstatus(row.entity.deleteFlag)}}</div>' },
  61. { name: 'isTemplate', displayName: '是否为模版', width: '10%', enableFiltering: false, cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transfer(row.entity.isTemplate)}}</div>' },
  62. {
  63. name: '编辑',
  64. cellTemplate: '<div><div class="links cl-effect-1 ui-grid-cell-contents" >' +
  65. '<a ng-click="grid.appScope.saveData(row.entity)" class="bianjifont">编辑</a>' +
  66. '</div></div>',
  67. enableFiltering: false
  68. },
  69. ];
  70. $scope.saveData = function(selectdata) {
  71. var modalInstance = $modal.open({
  72. templateUrl: 'assets/views/system/tpl/systemworktime.html',
  73. controller: function($scope, $modalInstance, api_bpm_data) {
  74. $scope.title = "修改班次";
  75. $scope.worktimedata = {};
  76. $scope.worktimedata = selectdata;
  77. $scope.dictionary = [];
  78. api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  79. if (data) {
  80. $scope.dictionary = data;
  81. }
  82. })
  83. $scope.cancel = function() {
  84. $modalInstance.dismiss('cancel');
  85. };
  86. $scope.savercode = function(worktimedata) {
  87. var fildata = {
  88. "scheduleclass": {
  89. "id": worktimedata.id,
  90. // "code": worktimedata.code,
  91. "name": worktimedata.name,
  92. "person": worktimedata.person,
  93. "description": worktimedata.description,
  94. "startTime": moment(worktimedata.startTime).format('YYYY-MM-DD HH:mm:ss'),
  95. "endTime": moment(worktimedata.endTime).format('YYYY-MM-DD HH:mm:ss'),
  96. "shiftTime": worktimedata.shiftTime,
  97. "succeedTime": worktimedata.succeedTime,
  98. "dictionaryDTO": worktimedata.dictionaryDTO,
  99. "isTemplate": worktimedata.isTemplate,
  100. "deleteFlag": worktimedata.deleteFlag
  101. }
  102. }
  103. // api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  104. // if (data.status == 200) {
  105. // $scope.dictionary = data;
  106. // }
  107. // })
  108. api_bpm_data.updData('scheduleclass', fildata).then(function(response) {
  109. if (response) {
  110. if (response.status == 200) {
  111. SweetAlert.swal({
  112. title: "修改成功!",
  113. type: "success"
  114. }, function() {
  115. // $scope.refreshData('expand-right', defaultFilterData);
  116. })
  117. } else {
  118. SweetAlert.swal({
  119. title: "修改失败!",
  120. type: "error"
  121. })
  122. }
  123. }
  124. })
  125. $modalInstance.close();
  126. }
  127. }
  128. });
  129. }
  130. $scope.addData = function() {
  131. var modalInstance = $modal.open({
  132. templateUrl: 'assets/views/system/tpl/systemworktime.html',
  133. controller: function($scope, $modalInstance, api_bpm_data) {
  134. $scope.title = "新增班次";
  135. $scope.dictionary = [];
  136. api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  137. if (data) {
  138. $scope.dictionary = data;
  139. }
  140. })
  141. $scope.worktimedata = { "startTime": new Date(), "endTime": new Date(), "isTemplate": false }
  142. $scope.cancel = function() {
  143. $modalInstance.dismiss('cancel');
  144. };
  145. $scope.savercode = function(worktimedata) {
  146. $modalInstance.close(worktimedata);
  147. };
  148. }
  149. });
  150. modalInstance.result.then(function(selectedItem) {
  151. if (selectedItem) {
  152. var fildata = {
  153. "scheduleclass": {
  154. // "code": selectedItem.code,
  155. "name": selectedItem.name,
  156. "person": selectedItem.person,
  157. "description": selectedItem.description,
  158. "startTime": moment(selectedItem.startTime).format('YYYY-MM-DD HH:mm:ss'),
  159. "endTime": moment(selectedItem.endTime).format('YYYY-MM-DD HH:mm:ss'),
  160. "shiftTime": selectedItem.shiftTime,
  161. "succeedTime": selectedItem.succeedTime,
  162. "dictionaryDTO": selectedItem.dictionaryDTO,
  163. "isTemplate": selectedItem.isTemplate,
  164. "deleteFlag": selectedItem.deleteFlag
  165. }
  166. }
  167. if (!fildata.scheduleclass.name) {
  168. SweetAlert.swal({
  169. title: "新增失败!",
  170. text: "班次未填",
  171. type: "error"
  172. })
  173. } else if (!fildata.scheduleclass.startTime) {
  174. SweetAlert.swal({
  175. title: "新增失败!",
  176. text: "班次开始时间未填",
  177. type: "error"
  178. })
  179. } else if (!fildata.scheduleclass.endTime) {
  180. SweetAlert.swal({
  181. title: "新增失败!",
  182. text: "班次结束时间未填",
  183. type: "error"
  184. })
  185. } else if (!fildata.scheduleclass.person) {
  186. SweetAlert.swal({
  187. title: "新增失败!",
  188. text: "本班次人数未填",
  189. type: "error"
  190. })
  191. } else {
  192. api_bpm_data.addData('scheduleclass', fildata).then(function(response) {
  193. if (response.status == 200) {
  194. SweetAlert.swal({
  195. title: "新增成功!",
  196. type: "success"
  197. }, function() {
  198. $scope.refreshData('expand-right', defaultFilterData);
  199. })
  200. } else {
  201. SweetAlert.swal({
  202. title: "新增失败!",
  203. type: "error"
  204. })
  205. }
  206. })
  207. }
  208. }
  209. });
  210. }
  211. $scope.removeData = function() {
  212. var modalInstance = $modal.open({
  213. templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html',
  214. controller: function($scope, scope, $modalInstance, api_user_data) {
  215. var rmvList = [];
  216. $scope.title = "删除";
  217. $scope.connect = "确定要删除本班次?";
  218. rmvList.push(scope.selected.items[0].id);
  219. $scope.ok = function() {
  220. $modalInstance.close(rmvList);
  221. };
  222. $scope.cancel = function() {
  223. $modalInstance.dismiss('cancel');
  224. };
  225. },
  226. size: 'sm',
  227. resolve: {
  228. scope: function() {
  229. return $scope;
  230. }
  231. }
  232. });
  233. modalInstance.result.then(function(selectedItem) {
  234. if (selectedItem) {
  235. if (selectedItem.length > 0) {
  236. api_bpm_data.rmvData('scheduleclass', selectedItem).then(function(response) {
  237. if (response.status == 200) {
  238. SweetAlert.swal({
  239. title: "删除成功!",
  240. type: "success",
  241. confirmButtonColor: "#007AFF"
  242. }, function() {
  243. $scope.refreshData('expand-right', defaultFilterData);
  244. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  245. // $scope.selected = {
  246. // items: []
  247. // };
  248. // $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  249. $scope.gridApi.grid.selection.selectedCount = 0;
  250. });
  251. } else {
  252. SweetAlert.swal({
  253. title: "操作异常!",
  254. text: "系统异常,请稍后重试,或者联系管理员!",
  255. type: "error"
  256. });
  257. }
  258. })
  259. }
  260. }
  261. })
  262. }
  263. $scope.selected = {
  264. items: []
  265. }
  266. $scope.editted = {
  267. items: []
  268. }
  269. $scope.gridOptions.onRegisterApi = function(gridApi) {
  270. $scope.gridApi = gridApi;
  271. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  272. // console.log(rowEntity);
  273. // });
  274. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  275. var filtersData = $scope.memoryfilterData;
  276. filtersData.idx = newPage - 1;
  277. filtersData.sum = pageSize;
  278. defaultFilterData = filtersData;
  279. $scope.refreshData('expand-right', filtersData);
  280. });
  281. // gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  282. // scope.grid.appScope.selected.items[0] = scope.entity
  283. // });
  284. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  285. if (data.isSelected) {
  286. data.grid.appScope.selected.items[0] = data.entity;
  287. } else {
  288. if (data.grid.appScope.selected.items[0].id == data.entity.id) {
  289. data.grid.appScope.selected.items = [];
  290. }
  291. }
  292. });
  293. };
  294. var defaultFilterData = {
  295. "idx": 0,
  296. "sum": 10
  297. };
  298. $scope.memoryfilterData = {
  299. "idx": 0,
  300. "sum": 10
  301. }
  302. $scope.ldloading = {};
  303. $scope.refresh = function(style, filterData) {
  304. $scope.selected = { items: [] };
  305. if ($scope.gridApi) {
  306. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  307. $scope.gridApi.grid.selection.selectedCount = 0;
  308. }
  309. $scope.refreshData('expand-right', defaultFilterData);
  310. }
  311. $scope.refreshData = function(style, filterData) {
  312. $scope.ldloading[style.replace('-', '_')] = true;
  313. if (angular.isUndefined(filterData)) {
  314. filterData = defaultFilterData;
  315. }
  316. $scope.myData = [];
  317. // $scope.selected = { items: [] };
  318. // if ($scope.gridApi) {
  319. // $scope.gridApi.grid.selection.selectedCount = 0;
  320. // }
  321. api_bpm_schedule.getScheduleClass().then(function(response) {
  322. if (response.status == 200) {
  323. $scope.ldloading[style.replace('-', '_')] = false;
  324. var scheduleClassList = response.list;
  325. $scope.gridOptions.totalItems = response.totalNum;
  326. angular.forEach(scheduleClassList, function(item) {
  327. var templateEvent = {
  328. id: item.id,
  329. name: item['name'],
  330. // code: item['code'],
  331. startTime: item.startTime,
  332. person: item.person,
  333. //starts_at:
  334. endTime: item.endTime,
  335. dictionaryDTO: item.dictionaryDTO,
  336. succeedTime: item.succeedTime,
  337. shiftTime: item.shiftTime,
  338. description: item.description,
  339. deleteFlag: item.deleteFlag,
  340. isTemplate: item.isTemplate,
  341. draggable: true
  342. };
  343. $scope.myData.push(templateEvent);
  344. })
  345. for (var i = 0; i < $scope.myData.length; i++) {
  346. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  347. }
  348. }
  349. })
  350. // $scope.myData = [];
  351. // api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
  352. // var myData = Restangular.stripRestangular(data);
  353. // $scope.gridOptions.totalItems = myData.totalNum;
  354. // $scope.myData = myData.list;
  355. // $scope.ldloading[style.replace('-', '_')] = false;
  356. // },function(){
  357. // $scope.ldloading[style.replace('-', '_')] = false;
  358. // });
  359. };
  360. $scope.refreshData('expand-right', defaultFilterData);
  361. }]);