worktimeCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. var modalInstance = $modal.open({
  88. resolve: {
  89. scope: function () {
  90. return $scope;
  91. }
  92. },
  93. templateUrl: 'assets/views/system/tpl/systemworktime.html',
  94. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  95. $scope.title = "修改班次";
  96. $scope.worktimedata = {};
  97. selectdata.sendMsg = selectdata.sendMsg?selectdata.sendMsg:0;
  98. selectdata.sendTime = selectdata.sendTime?moment(selectdata.sendTime).format('YYYY-MM-DD HH:mm:ss'):moment().format('YYYY-MM-DD HH:mm:ss');
  99. $scope.worktimedata = angular.copy(selectdata);
  100. $scope.dictionary = [];
  101. api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  102. if (data) {
  103. $scope.dictionary = data;
  104. }
  105. })
  106. $scope.cancel = function() {
  107. $modalInstance.dismiss('cancel');
  108. };
  109. $scope.savercode = function(worktimedata) {
  110. var fildata = {
  111. "scheduleclass": {
  112. "id": worktimedata.id,
  113. // "code": worktimedata.code,
  114. "name": worktimedata.name,
  115. "person": worktimedata.person,
  116. "description": worktimedata.description,
  117. "startTime": moment(worktimedata.startTime).format('YYYY-MM-DD HH:mm:ss'),
  118. "endTime": moment(worktimedata.endTime).format('YYYY-MM-DD HH:mm:ss'),
  119. "shiftTime": worktimedata.shiftTime,
  120. "succeedTime": worktimedata.succeedTime,
  121. "dictionaryDTO": worktimedata.dictionaryDTO,
  122. "isTemplate": worktimedata.isTemplate,
  123. "deleteFlag": worktimedata.deleteFlag,
  124. "sendMsg": worktimedata.sendMsg,
  125. "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
  126. }
  127. }
  128. // api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  129. // if (data.status == 200) {
  130. // $scope.dictionary = data;
  131. // }
  132. // })
  133. api_bpm_data.updData('scheduleclass', fildata).then(function(response) {
  134. if (response) {
  135. if (response.status == 200) {
  136. SweetAlert.swal({
  137. title: "修改成功!",
  138. type: "success"
  139. }, function() {
  140. scope.refreshData('expand-right');
  141. })
  142. } else {
  143. SweetAlert.swal({
  144. title: "修改失败!",
  145. type: "error"
  146. })
  147. }
  148. }
  149. })
  150. $modalInstance.close();
  151. }
  152. }
  153. });
  154. }
  155. $scope.addData = function() {
  156. var modalInstance = $modal.open({
  157. templateUrl: 'assets/views/system/tpl/systemworktime.html',
  158. controller: function($scope, $modalInstance, api_bpm_data) {
  159. $scope.title = "新增班次";
  160. $scope.dictionary = [];
  161. api_wechatfile.getDictionary({ "type": "list", "key": "incident_scheduleclass" }).then(function(data) {
  162. if (data) {
  163. $scope.dictionary = data;
  164. }
  165. })
  166. $scope.worktimedata = { "startTime": new Date(), "endTime": new Date(), "isTemplate": false, sendMsg:0,sendTime:new Date() }
  167. $scope.cancel = function() {
  168. $modalInstance.dismiss('cancel');
  169. };
  170. $scope.savercode = function(worktimedata) {
  171. $modalInstance.close(worktimedata);
  172. };
  173. }
  174. });
  175. modalInstance.result.then(function(selectedItem) {
  176. if (selectedItem) {
  177. var fildata = {
  178. "scheduleclass": {
  179. // "code": selectedItem.code,
  180. "name": selectedItem.name,
  181. "person": selectedItem.person,
  182. "description": selectedItem.description,
  183. "startTime": moment(selectedItem.startTime).format('YYYY-MM-DD HH:mm:ss'),
  184. "endTime": moment(selectedItem.endTime).format('YYYY-MM-DD HH:mm:ss'),
  185. "shiftTime": selectedItem.shiftTime,
  186. "succeedTime": selectedItem.succeedTime,
  187. "dictionaryDTO": selectedItem.dictionaryDTO,
  188. "isTemplate": selectedItem.isTemplate,
  189. "deleteFlag": selectedItem.deleteFlag,
  190. "sendMsg": selectedItem.sendMsg,
  191. "sendTime": selectedItem.sendMsg == 1?moment(selectedItem.sendTime).format('YYYY-MM-DD HH:mm:ss'):undefined
  192. }
  193. }
  194. if (!fildata.scheduleclass.name) {
  195. SweetAlert.swal({
  196. title: "新增失败!",
  197. text: "班次未填",
  198. type: "error"
  199. })
  200. } else if (!fildata.scheduleclass.startTime) {
  201. SweetAlert.swal({
  202. title: "新增失败!",
  203. text: "班次开始时间未填",
  204. type: "error"
  205. })
  206. } else if (!fildata.scheduleclass.endTime) {
  207. SweetAlert.swal({
  208. title: "新增失败!",
  209. text: "班次结束时间未填",
  210. type: "error"
  211. })
  212. } else if (!fildata.scheduleclass.person) {
  213. SweetAlert.swal({
  214. title: "新增失败!",
  215. text: "本班次人数未填",
  216. type: "error"
  217. })
  218. } else {
  219. api_bpm_data.addData('scheduleclass', fildata).then(function(response) {
  220. if (response.status == 200) {
  221. SweetAlert.swal({
  222. title: "新增成功!",
  223. type: "success"
  224. }, function() {
  225. $scope.refreshData('expand-right', defaultFilterData);
  226. })
  227. } else {
  228. SweetAlert.swal({
  229. title: "新增失败!",
  230. type: "error"
  231. })
  232. }
  233. })
  234. }
  235. }
  236. });
  237. }
  238. $scope.removeData = function() {
  239. var modalInstance = $modal.open({
  240. templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html',
  241. controller: function($scope, scope, $modalInstance, api_user_data) {
  242. var rmvList = [];
  243. $scope.title = "删除";
  244. $scope.connect = "确定要删除本班次?";
  245. rmvList.push(scope.selected.items[0].id);
  246. $scope.ok = function() {
  247. $modalInstance.close(rmvList);
  248. };
  249. $scope.cancel = function() {
  250. $modalInstance.dismiss('cancel');
  251. };
  252. },
  253. size: 'sm',
  254. resolve: {
  255. scope: function() {
  256. return $scope;
  257. }
  258. }
  259. });
  260. modalInstance.result.then(function(selectedItem) {
  261. if (selectedItem) {
  262. if (selectedItem.length > 0) {
  263. api_bpm_data.rmvData('scheduleclass', selectedItem).then(function(response) {
  264. if (response.status == 200) {
  265. SweetAlert.swal({
  266. title: "删除成功!",
  267. type: "success",
  268. confirmButtonColor: "#007AFF"
  269. }, function() {
  270. $scope.refreshData('expand-right', defaultFilterData);
  271. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  272. // $scope.selected = {
  273. // items: []
  274. // };
  275. // $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  276. $scope.gridApi.grid.selection.selectedCount = 0;
  277. });
  278. } else {
  279. SweetAlert.swal({
  280. title: "操作异常!",
  281. text: "系统异常,请稍后重试,或者联系管理员!",
  282. type: "error"
  283. });
  284. }
  285. })
  286. }
  287. }
  288. })
  289. }
  290. $scope.selected = {
  291. items: []
  292. }
  293. $scope.editted = {
  294. items: []
  295. }
  296. $scope.gridOptions.onRegisterApi = function(gridApi) {
  297. $scope.gridApi = gridApi;
  298. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  299. // console.log(rowEntity);
  300. // });
  301. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  302. var filtersData = $scope.memoryfilterData;
  303. filtersData.idx = newPage - 1;
  304. filtersData.sum = pageSize;
  305. defaultFilterData = filtersData;
  306. $scope.refreshData('expand-right', filtersData);
  307. });
  308. // gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  309. // scope.grid.appScope.selected.items[0] = scope.entity
  310. // });
  311. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  312. if (data.isSelected) {
  313. data.grid.appScope.selected.items[0] = data.entity;
  314. } else {
  315. if (data.grid.appScope.selected.items[0].id == data.entity.id) {
  316. data.grid.appScope.selected.items = [];
  317. }
  318. }
  319. });
  320. };
  321. var defaultFilterData = {
  322. "idx": 0,
  323. "sum": 10
  324. };
  325. $scope.memoryfilterData = {
  326. "idx": 0,
  327. "sum": 10
  328. }
  329. $scope.ldloading = {};
  330. $scope.refresh = function(style, filterData) {
  331. $scope.selected = { items: [] };
  332. if ($scope.gridApi) {
  333. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  334. $scope.gridApi.grid.selection.selectedCount = 0;
  335. }
  336. $scope.refreshData('expand-right', defaultFilterData);
  337. }
  338. $scope.refreshData = function(style, filterData) {
  339. $scope.ldloading[style.replace('-', '_')] = true;
  340. if (angular.isUndefined(filterData)) {
  341. filterData = defaultFilterData;
  342. }
  343. $scope.myData = [];
  344. // $scope.selected = { items: [] };
  345. // if ($scope.gridApi) {
  346. // $scope.gridApi.grid.selection.selectedCount = 0;
  347. // }
  348. api_bpm_schedule.getScheduleClass().then(function(response) {
  349. if (response.status == 200) {
  350. $scope.ldloading[style.replace('-', '_')] = false;
  351. var scheduleClassList = response.list;
  352. $scope.gridOptions.totalItems = response.totalNum;
  353. angular.forEach(scheduleClassList, function(item) {
  354. var templateEvent = {
  355. id: item.id,
  356. name: item['name'],
  357. // code: item['code'],
  358. startTime: item.startTime,
  359. person: item.person,
  360. //starts_at:
  361. endTime: item.endTime,
  362. dictionaryDTO: item.dictionaryDTO,
  363. succeedTime: item.succeedTime,
  364. shiftTime: item.shiftTime,
  365. description: item.description,
  366. deleteFlag: item.deleteFlag,
  367. isTemplate: item.isTemplate,
  368. draggable: true,
  369. sendMsg: item.sendMsg,
  370. sendTime: item.sendTime
  371. };
  372. $scope.myData.push(templateEvent);
  373. })
  374. for (var i = 0; i < $scope.myData.length; i++) {
  375. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  376. }
  377. }
  378. })
  379. // $scope.myData = [];
  380. // api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
  381. // var myData = Restangular.stripRestangular(data);
  382. // $scope.gridOptions.totalItems = myData.totalNum;
  383. // $scope.myData = myData.list;
  384. // $scope.ldloading[style.replace('-', '_')] = false;
  385. // },function(){
  386. // $scope.ldloading[style.replace('-', '_')] = false;
  387. // });
  388. };
  389. $scope.refreshData('expand-right', defaultFilterData);
  390. }]);