worktimeCtrl.js 19 KB

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