timingMessageSendingCtrl.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('timingMessageSendingCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_wechatfile", "api_configure_data", "moment", "api_sysinfo", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_wechatfile, api_configure_data, moment, api_sysinfo) {
  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. $scope.zantingzhixing = false;
  14. for (var i = 0; i < loginUser.menu.length; i++) {
  15. if (loginUser.menu[i].link == "xunjianjihua_xinzeng") {
  16. $scope.xinzeng = true
  17. }
  18. if (loginUser.menu[i].link == "xunjianjihua_shanchu") {
  19. $scope.shanchu = true
  20. }
  21. if (loginUser.menu[i].link == "xunjianjihua_bianji") {
  22. $scope.bianji = true
  23. }
  24. if (loginUser.menu[i].link == "xunjianjihua_zantingzhixing") {
  25. $scope.zantingzhixing = true
  26. }
  27. }
  28. var defaultFilterData = {
  29. "idx": 0,
  30. "sum": 10
  31. };
  32. var inspectPlanParameter = {
  33. "idx": 0,
  34. "sum": 10,
  35. "operation": "",
  36. "status": "",
  37. "inspection": {
  38. "inspectionTypeDTO": {
  39. "id": ""
  40. }
  41. }
  42. };
  43. //本地存储
  44. sessionStorage.inspectPlanParameter = JSON.stringify(inspectPlanParameter);
  45. $scope.memoryfilterData = {
  46. "idx": 0,
  47. "sum": 10
  48. }
  49. // $scope.isMask = false;
  50. $scope.gridOptions = {};
  51. $scope.gridOptions.data = 'myData';
  52. $scope.gridOptions.enableColumnResizing = true;
  53. $scope.gridOptions.enableFiltering = false;
  54. $scope.gridOptions.enableGridMenu = true;
  55. $scope.gridOptions.enableRowSelection = true;
  56. $scope.gridOptions.showGridFooter = true;
  57. $scope.gridOptions.showColumnFooter = false;
  58. $scope.gridOptions.useExternalFiltering = false;
  59. $scope.gridOptions.useExternalPagination = true;
  60. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  61. $scope.gridOptions.paginationPageSize = 10;
  62. $scope.gridOptions.multiSelect = true;
  63. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  64. //行鼠标悬浮变色功能
  65. // $scope.gridOptions.rowTemplate = '<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ng-mouseover="grid.appScope.hoveredIndex = rowRenderIndex" ng-mouseleave="grid.appScope.hoveredIndex = null" ui-grid-one-bind-id-grid="rowRenderIndex + \'-\' + col.uid + \'-cell\'" class="ui-grid-cell" ng-class="{\'ui-grid-row-header-cell\': col.isRowHeader, \'your-hover-class\': grid.appScope.hoveredIndex === rowRenderIndex}" role="{{col.isRowHeader ? \'rowheader\' : \'gridcell\'}}" ui-grid-cell></div>';
  66. $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>";
  67. $scope.gridOptions.rowIdentity = function (row) {
  68. return row.id;
  69. };
  70. $scope.gridOptions.getRowIdentity = function (row) {
  71. return row.id;
  72. };
  73. $scope.transfer = function (status) {
  74. if (status === "正常") {
  75. return "执行中"
  76. } else if (status === "停止") {
  77. return "暂停中"
  78. }
  79. }
  80. $scope.gridOptions.columnDefs = [{
  81. name: 'item',
  82. displayName: '序号',
  83. width: 50,
  84. enableFiltering: false
  85. },
  86. {
  87. name: 'title',
  88. displayName: '标题',
  89. width: '10%',
  90. enableFiltering: true
  91. },
  92. {
  93. name: 'content',
  94. displayName: '发送内容',
  95. width: '35%',
  96. enableFiltering: false,
  97. cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.content}}">{{row.entity.content}}</div>'
  98. },
  99. {
  100. name: 'timeStep1',
  101. displayName: '重复策略',
  102. width: '10%',
  103. enableFiltering: false,
  104. cellTemplate: '<div class="ui-grid-cell-contents" ng-switch="row.entity.timeStep"><ng-container ng-switch-when="day">每日</ng-container><ng-container ng-switch-when="week">每周</ng-container><ng-container ng-switch-when="month">每月</ng-container><ng-container ng-switch-when="year">每年</ng-container></div>'
  105. },
  106. {
  107. name: 'timeStep2',
  108. displayName: '定时发送时间',
  109. width: '12%',
  110. enableFiltering: false,
  111. cellTemplate: '<div class="ui-grid-cell-contents" ng-switch="row.entity.timeStep"><ng-container ng-switch-when="day">{{ row.entity.executeTime|date:"HH时mm分" }}</ng-container><ng-container ng-switch-when="week">{{row.entity.weekName}} {{ row.entity.executeTime|date:"HH时mm分" }}</ng-container><ng-container ng-switch-when="month">{{row.entity.extra1}}日 {{ row.entity.executeTime|date:"HH时mm分" }}</ng-container><ng-container ng-switch-when="year">{{ row.entity.executeTime|date:"MM月dd日HH时mm分" }}</ng-container></div>'
  112. },
  113. {
  114. name: 'active',
  115. displayName: '状态',
  116. width: 50,
  117. enableFiltering: false,
  118. cellTemplate: '<div class="ui-grid-cell-contents">{{ row.entity.active?"开启":"关闭" }}</div>'
  119. },
  120. {
  121. name: 'usersName',
  122. displayName: '接收人',
  123. width: '10%',
  124. enableFiltering: false
  125. },
  126. {
  127. minWidth: '230',
  128. name: '操作',
  129. enableFiltering: false,
  130. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  131. '<a ng-click="grid.appScope.selectRowFunction(row.entity)" class="bianjifont">编辑</a>' +
  132. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="row.entity.active" class="bianjifont">停用</a>' +
  133. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="!row.entity.active" class="bianjifont">启用</a>' +
  134. '</div>'
  135. },
  136. ];
  137. $scope.transferTime = function (time) {
  138. return moment(time).format('YYYY-MM-DD HH:mm');
  139. }
  140. //新增数据
  141. $scope.addData = function () {
  142. $state.go('app.inspection.editor', {
  143. formKey: 'inspectionform',
  144. service: 'api_bpm_data',
  145. });
  146. }
  147. $scope.inspectdata = {};
  148. //打开编辑弹出框
  149. $scope.hc_eject_big = false;
  150. $scope.edit_obj = {};//编辑的对象
  151. $scope.isWarehousing = 'day';//重复策略
  152. $scope.isActive = 0;//是否启用
  153. $scope.t_title = '';//标题
  154. $scope.userIds = [];//接收人ids
  155. $scope.t_userList = [];//接收人
  156. $scope.hourAndMinute = null;//选择小时,分钟
  157. $scope.doWeek = null;//选择周
  158. $scope.doMonth = '';//选择日
  159. $scope.weeks = [
  160. { id: 1, name: '周一' },
  161. { id: 2, name: '周二' },
  162. { id: 3, name: '周三' },
  163. { id: 4, name: '周四' },
  164. { id: 5, name: '周五' },
  165. { id: 6, name: '周六' },
  166. { id: 7, name: '周日' }
  167. ];
  168. $scope.months = [...Array(32).keys()].slice(1);
  169. $scope.selectRowFunction = function (data) {
  170. console.log(data);
  171. $scope.edit_obj = data;
  172. $scope.hc_eject_big = true;
  173. //回显数据
  174. $scope.t_title = data.title;
  175. $scope.isWarehousing = data.timeStep;
  176. switch (data.timeStep) {
  177. case 'week':
  178. $scope.doWeek = $scope.weeks.find(v => v.id == data.extra1);
  179. break;
  180. case 'month':
  181. $scope.doMonth = data.extra1;
  182. break;
  183. case 'year':
  184. $scope.starttimesModel = moment(data.executeTime);
  185. break;
  186. }
  187. $scope.hourAndMinute = moment(data.executeTime);
  188. $scope.isActive = data.active;
  189. $scope.userIds = data.users;
  190. };
  191. // 关闭编辑弹出框
  192. $scope.close = function () {
  193. $scope.hc_eject_big = false;
  194. }
  195. $scope.changeWeek = function (selected) {
  196. $scope.doWeek = selected;
  197. }
  198. $scope.changeMonth = function (selected) {
  199. $scope.doMonth = selected;
  200. }
  201. //保存
  202. $scope.preservation = function () {
  203. //判空 start
  204. if(!$scope.t_title){
  205. SweetAlert.swal({
  206. title: "标题不能为空",
  207. text: "标题不能为空",
  208. type: "error"
  209. });
  210. return;
  211. }else if($scope.userIds.length === 0){
  212. SweetAlert.swal({
  213. title: "接收人不能为空",
  214. text: "接收人不能为空",
  215. type: "error"
  216. });
  217. return;
  218. }else{
  219. switch($scope.isWarehousing){
  220. case 'week':
  221. if(!$scope.doWeek){
  222. SweetAlert.swal({
  223. title: "计划执行(每周)不能为空",
  224. text: "计划执行(每周)不能为空",
  225. type: "error"
  226. });
  227. return;
  228. }
  229. break;
  230. case 'month':
  231. if(!$scope.doMonth){
  232. SweetAlert.swal({
  233. title: "计划执行(每月)不能为空",
  234. text: "计划执行(每月)不能为空",
  235. type: "error"
  236. });
  237. return;
  238. }
  239. break;
  240. case 'year':
  241. if(!$scope.starttimesModel){
  242. SweetAlert.swal({
  243. title: "计划执行(每年)不能为空",
  244. text: "计划执行(每年)不能为空",
  245. type: "error"
  246. });
  247. return;
  248. }
  249. break;
  250. }
  251. }
  252. //判空 end
  253. var toData = {
  254. "messageJob": {}
  255. };
  256. //处理数据 start
  257. toData.messageJob.content = $scope.edit_obj.content;
  258. toData.messageJob.id = $scope.edit_obj.id;
  259. toData.messageJob.key = $scope.edit_obj.key;
  260. toData.messageJob.title = $scope.t_title;
  261. toData.messageJob.timeStep = $scope.isWarehousing;
  262. switch($scope.isWarehousing){
  263. case 'day':
  264. break;
  265. case 'week':
  266. toData.messageJob.extra1 = $scope.doWeek.id;
  267. break;
  268. case 'month':
  269. toData.messageJob.extra1 = $scope.doMonth;
  270. break;
  271. case 'year':
  272. break;
  273. }
  274. toData.messageJob.executeTime = moment($scope.hourAndMinute).valueOf();
  275. toData.messageJob.active = $scope.isActive;
  276. toData.messageJob.userIds = $scope.userIds.map(v=>v.id).toString();
  277. // 当前所属院区或责任科室
  278. if($rootScope.user.duty){
  279. toData.messageJob.branch = $rootScope.user.duty.branch;
  280. }else if($rootScope.user.branch){
  281. toData.messageJob.branch = $rootScope.user.branch.id;
  282. }
  283. console.log(toData.messageJob)
  284. //处理数据 end
  285. api_bpm_data.updData('messageJob', toData).then(function (response) {
  286. $scope.close();
  287. var myData = Restangular.stripRestangular(response);
  288. if (myData.status == 200) {
  289. SweetAlert.swal({
  290. title: "保存成功!",
  291. type: "success",
  292. confirmButtonColor: "#007AFF"
  293. }, function () {
  294. $scope.refreshData('expand-right', $scope.fileData);
  295. });
  296. } else {
  297. SweetAlert.swal({
  298. title: "操作失败",
  299. text: "操作失败",
  300. type: "error"
  301. });
  302. }
  303. }, function () {
  304. });
  305. }
  306. //切换重复策略
  307. $scope.changeWarehousing = function (type) {
  308. $scope.isWarehousing = type;
  309. $scope.doWeek = null;
  310. $scope.doMonth = '';
  311. $scope.starttimesModel = null;
  312. }
  313. //切换是否启用
  314. $scope.changeActive = function (type) {
  315. $scope.isActive = type;
  316. }
  317. // 接收人查询
  318. $scope.d_name = '';//防止抖动
  319. $scope.refreshDat_users = function (name, userIds = []) {
  320. $scope.t_userList = [];
  321. name = name || "";
  322. $scope.d_name = name;
  323. userIds = userIds || [];
  324. var dat = {
  325. "user": {
  326. name: name
  327. },
  328. "idx": 0,
  329. "sum": 999
  330. }
  331. api_sysinfo.fetchDataList("user", dat).then(function (data) {
  332. if (data.status == 200) {
  333. if($scope.d_name == name){
  334. if (userIds.length) {
  335. userIds.forEach(v => {
  336. data.list.forEach((v1, i) => {
  337. if (v.id == v1.id) {
  338. data.list.splice(i, 1)
  339. }
  340. })
  341. })
  342. }
  343. $scope.t_userList = data.list;
  344. }
  345. }
  346. });
  347. }
  348. $scope.refreshDat_users();
  349. // 修改接收人
  350. $scope.changeUser = function (userIds) {
  351. $scope.userIds = userIds;
  352. }
  353. //打开每天定时发送时间--日期选择框
  354. $scope.starttimesModel = null;
  355. $scope.startOpened = false;
  356. //跳转到查看列表
  357. $scope.seeFunction = function (data) {
  358. var filedata = {
  359. model: {
  360. inspection: data
  361. }
  362. };
  363. $state.go('app.inspection.form', {
  364. formKey: 'inspection__detailform',
  365. service: 'api_bpm_data',
  366. model: JSON.stringify(filedata)
  367. });
  368. }
  369. // $scope.onDblClick = function(data) {
  370. // var filedata = {
  371. // model: {
  372. // inspection: data.entity
  373. // }
  374. // };
  375. // $state.go('app.inspection.form', {
  376. // formKey: 'inspection__detailform',
  377. // service: 'api_bpm_data',
  378. // model: JSON.stringify(filedata)
  379. // });
  380. // };
  381. //跳转到查看列表
  382. $scope.lookFunction = function (data) {
  383. var filedata = {
  384. model: {
  385. inspection: data
  386. }
  387. };
  388. $state.go('app.inspection.form', {
  389. formKey: 'inspection__detailform',
  390. service: 'api_bpm_data',
  391. model: JSON.stringify(filedata)
  392. });
  393. };
  394. //启用/停用
  395. $scope.runFunction = function (data) {
  396. console.log(data)
  397. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  398. var upData = {};
  399. upData.id = data.id;
  400. upData.operation = 1;
  401. var modalInstance = $modal.open({
  402. // templateUrl: 'assets/views/inspect/changRun.html',
  403. templateUrl: 'assets/views/delete.html',
  404. // size: "sm",
  405. controller: function ($scope, $modalInstance) {
  406. $scope.isRunFunction = true;
  407. if (data.active) {
  408. $scope.title = '停用';
  409. $scope.connect = '确定要停用?';
  410. } else {
  411. $scope.title = '启用';
  412. $scope.connect = '确定要启用?';
  413. }
  414. $scope.ok = function () {
  415. $modalInstance.close(data);
  416. };
  417. $scope.cancel = function () {
  418. $modalInstance.dismiss('cancel');
  419. };
  420. },
  421. size: 'sm'
  422. })
  423. modalInstance.result.then(function (result) {
  424. console.log(result)
  425. if (result) {
  426. result.active = !result.active;
  427. var toData = {
  428. "messageJob": result
  429. };
  430. // 当前所属院区或责任科室
  431. if($rootScope.user.duty){
  432. toData.messageJob.branch = $rootScope.user.duty.branch;
  433. }else if($rootScope.user.branch){
  434. toData.messageJob.branch = $rootScope.user.branch.id;
  435. }
  436. api_bpm_data.updData('messageJob', toData).then(function (response) {
  437. var myData = Restangular.stripRestangular(response);
  438. if (myData.status == 200) {
  439. SweetAlert.swal({
  440. title: (myData.data.active ? '启动' : '停用') + "成功!",
  441. type: "success",
  442. confirmButtonColor: "#007AFF"
  443. }, function () {
  444. $scope.refreshData('expand-right', $scope.fileData);
  445. });
  446. } else {
  447. SweetAlert.swal({
  448. title: "操作失败",
  449. text: "操作失败",
  450. type: "error"
  451. });
  452. }
  453. }, function () {
  454. });
  455. }
  456. });
  457. };
  458. // $scope.newincident = function(data) {
  459. // $state.go('app.incident.editor', {});
  460. // };
  461. //行删除
  462. $scope.removeData = function () {
  463. console.log($scope.selected.items);
  464. var modalInstance = $modal.open({
  465. templateUrl: 'assets/views/delete.html',
  466. controller: function ($scope, $modalInstance) {
  467. // $scope.textLog = "是否删除巡检计划";
  468. $scope.title = '巡检计划删除';
  469. $scope.connect = '确定要删除巡检计划?';
  470. $scope.ok = function () {
  471. $modalInstance.close("start");
  472. };
  473. $scope.cancel = function () {
  474. $modalInstance.dismiss('cancel');
  475. };
  476. },
  477. size: 'sm'
  478. })
  479. modalInstance.result.then(function (result) {
  480. if (result) {
  481. if ($scope.selected.items.length != 0) {
  482. $rootScope.isMask = true;
  483. }
  484. var rmvList = [];
  485. angular.forEach($scope.selected.items, function (item) {
  486. rmvList.push(item.id);
  487. });
  488. if (rmvList.length > 0) {
  489. api_bpm_data.rmvData('inspection', rmvList).then(function (response) {
  490. if (response.status == 200) {
  491. $rootScope.isMask = false;
  492. SweetAlert.swal({
  493. title: "删除成功!",
  494. type: "success",
  495. confirmButtonColor: "#007AFF"
  496. }, function () {
  497. $scope.myData = _.reject($scope.myData, function (o) {
  498. return _.includes(rmvList, o.id);
  499. });
  500. $scope.selected = {
  501. items: []
  502. };
  503. });
  504. $scope.gridApi.selection.clearSelectedRows();
  505. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  506. var showData = {
  507. "idx": filterData.idx,
  508. "sum": filterData.sum,
  509. "inspection": {
  510. "inspectionTypeDTO": {
  511. "id": ""
  512. }
  513. }
  514. }
  515. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  516. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  517. } else {
  518. showData.inspection.inspectionTypeDTO.id = -1
  519. }
  520. $scope.refreshData('expand-right', $scope.fileData);
  521. //取消遮罩层
  522. // $scope.isMask = false;
  523. } else {
  524. $rootScope.isMask = false;
  525. SweetAlert.swal({
  526. title: "操作异常!",
  527. text: "系统异常,请稍后重试,或者联系管理员!",
  528. type: "error"
  529. });
  530. }
  531. })
  532. }
  533. }
  534. }, function () {
  535. // $scope.ldloading[style.replace('-', '_')] = false;
  536. });
  537. }
  538. $scope.selected = {
  539. items: []
  540. }
  541. $scope.editted = {
  542. items: []
  543. }
  544. $scope.testRow = [];
  545. $scope.gridOptions.onRegisterApi = function (gridApi) {
  546. //导入gridApi对象
  547. $scope.gridApi = gridApi;
  548. //分页选项
  549. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  550. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  551. var filtersData = {};
  552. filtersData.idx = newPage - 1;
  553. filtersData.sum = pageSize;
  554. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  555. // console.log(pp);
  556. filterData.idx = $scope.pageNum;
  557. $scope.fileData.idx = newPage - 1;
  558. $scope.fileData.sum = pageSize;
  559. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  560. $scope.refreshData('expand-right', $scope.fileData);
  561. });
  562. //勾选行事件
  563. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  564. if (data.isSelected) {
  565. $scope.selected.items.push(data.entity);
  566. } else {
  567. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  568. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  569. //angular.forEach(objs, function(data,index,array)
  570. angular.forEach($scope.selected.items, function (ObjIndex, index, destObj) {
  571. // console.log(ObjIndex);
  572. // console.log(index);
  573. // console.log(destObj);
  574. if (ObjIndex.id == data.entity.id) {
  575. destObj.splice(index, 1)
  576. }
  577. })
  578. }
  579. });
  580. //批量全选
  581. gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows, event) {
  582. // if ($scope.selected.items.length != 0) {
  583. // $scope.selected.items = [];
  584. angular.forEach(rows, function (ObjIndex, index, destObj) {
  585. if (ObjIndex.isSelected) {
  586. $scope.selected.items.push(ObjIndex.entity);
  587. } else {
  588. $scope.selected.items = [];
  589. // $scope.selected.items.splice(index, 1);
  590. }
  591. });
  592. // } else {
  593. // }
  594. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  595. // if ($scope.selected.items.length == 0) {
  596. // $scope.selected.items = $scope.mySelectedRows;
  597. // } else if ($scope.mySelectedRows.length == 0) {
  598. // for (var i = 0; i < $scope.selected.items.length; i++) {
  599. // for (var j = 0; j < rows.length; j++) {
  600. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  601. // $scope.selected.items.splice(i, 1);
  602. // }
  603. // }
  604. // }
  605. // } else {
  606. // angular.forEach($scope.mySelectedRows, function(item) {
  607. // $scope.selected.items.push(item);
  608. // });
  609. // }
  610. });
  611. //列过滤事件
  612. gridApi.core.on.filterChanged($scope, function () {
  613. var grid = this.grid;
  614. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  615. angular.forEach(grid.columns, function (item) {
  616. if (item.enableFiltering) {
  617. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  618. if (angular.isUndefined(filterData['inspection'])) {
  619. filterData['inspection'] = {};
  620. }
  621. filterData['inspection']['title'] = item.filters[0].term;
  622. }
  623. }
  624. });
  625. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  626. $scope.refreshData('expand-right', filterData);
  627. });
  628. };
  629. // //刷新按钮
  630. // $scope.reload = function() {
  631. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  632. // var showData = {
  633. // "idx": filterData.idx,
  634. // "sum": filterData.sum,
  635. // "inspection": {
  636. // "inspectionTypeDTO": {
  637. // "id": ""
  638. // }
  639. // }
  640. // }
  641. // if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  642. // showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  643. // } else {
  644. // showData.inspection.inspectionTypeDTO.id = -1
  645. // }
  646. // $scope.refreshData('expand-right', showData);
  647. // }
  648. //重置按钮
  649. $scope.reload = function () {
  650. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  651. // var data={
  652. // "idx":filterData.idx,
  653. // "sum":filterData.sum
  654. // }
  655. // $scope.inspectdata={};
  656. delete $scope.fileData.inspection.inspectionTypeDTO;
  657. delete $scope.fileData.inspection.title;
  658. delete $scope.fileData.inspection.executeUser;
  659. delete $scope.fileData.inspection.createUser;
  660. delete $scope.fileData.inspection.status;
  661. $scope.try_async_load();
  662. $scope.refreshData('expand-right', $scope.fileData);
  663. }
  664. //数据刷新
  665. $scope.refreshData = function (style, filterData, isEmpty = true) {
  666. $scope.ldloading[style.replace('-', '_')] = true;
  667. if (angular.isUndefined(filterData)) {
  668. filterData = defaultFilterData;
  669. }
  670. if (isEmpty) {
  671. $scope.myData = [];
  672. }
  673. // 当前所属院区或责任科室
  674. if($rootScope.user.duty){
  675. filterData.messageJob.branch = $rootScope.user.duty.branch;
  676. }else if($rootScope.user.branch){
  677. filterData.messageJob.branch = $rootScope.user.branch.id;
  678. }
  679. api_bpm_data.fetchDataList('messageJob', filterData).then(function (data) {
  680. var myData = Restangular.stripRestangular(data);
  681. $scope.gridOptions.totalItems = myData.totalNum;
  682. if (angular.isArray(myData.list)) {
  683. // -----seimin start ----
  684. myData.list.forEach((item) => {
  685. if (item.timeStep == "week") {
  686. let weeks = [
  687. "周一",
  688. "周二",
  689. "周三",
  690. "周四",
  691. "周五",
  692. "周六",
  693. "周日",
  694. ];
  695. item.weekName = weeks[item.extra1 - 1];
  696. }
  697. item.usersName = item.users.map((value) => value.name).join();
  698. });
  699. // -----seimin end ----
  700. $scope.myData = myData.list;
  701. for (var i = 0; i < $scope.myData.length; i++) {
  702. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  703. }
  704. for (var i = 0; i < $scope.myData.length; i++) {
  705. if ($scope.myData[i].status == "正常") {
  706. $scope.myData[i].style = "fa fa-play";
  707. } else if ($scope.myData[i].status == "停止") {
  708. $scope.myData[i].style = "fa fa-pause";
  709. };
  710. $scope.myData[i].runStatus = $scope.transfer($scope.myData[i].status);
  711. }
  712. } else {
  713. SweetAlert.swal({
  714. title: "数据为空",
  715. text: myData.data,
  716. type: "warning"
  717. });
  718. }
  719. $scope.ldloading[style.replace('-', '_')] = false;
  720. }, function () {
  721. $scope.ldloading[style.replace('-', '_')] = false;
  722. });
  723. };
  724. $scope.ldloading = {};
  725. //树形控件点击事件
  726. $scope.my_tree_handler = function (branch) {
  727. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  728. filterData.inspection.inspectionTypeDTO.id = branch.id;
  729. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  730. var showData = {
  731. "idx": filterData.id,
  732. "sum": filterData.sum,
  733. "inspection": {
  734. "inspectionTypeDTO": {
  735. "id": branch.id
  736. }
  737. }
  738. }
  739. // $scope.refreshData('expand-right', showData);
  740. }
  741. $scope.fileData = {
  742. "idx": 0,
  743. "sum": 10,
  744. "messageJob": {
  745. }
  746. }
  747. $scope.onFilterCallback = function (data) {
  748. $scope.fileData.inspection.inspectionTypeDTO = {
  749. "id": data.id
  750. }
  751. }
  752. $scope.inspecttype = {};
  753. $scope.searchinspe = function (item) {
  754. $scope.refreshData('expand-right', $scope.fileData);
  755. }
  756. //树形控件加载
  757. $scope.my_tree = {};
  758. $scope.try_async_load = function () {
  759. $scope.my_data = [];
  760. $scope.doing_async = true;
  761. api_bpm_data.fetchDataList('inspectionType', {
  762. "idx": 0,
  763. "sum": 1000
  764. }).then(function (response) {
  765. if (response.status == 200) {
  766. var data = response.list;
  767. var objects = [];
  768. for (var i = 0; i < data.length; i++) {
  769. var object = {};
  770. object.id = data[i].id;
  771. if (data[i].parent && data[i].parent.id != 0) {
  772. object.parent = data[i].parent.id;
  773. }
  774. object.label = data[i].type;
  775. objects.push(object);
  776. }
  777. $scope.my_data = convertParentToChildList(objects);
  778. $scope.tree_data = angular.copy($scope.my_data);
  779. if ($scope.my_data.length > 0) {
  780. $scope.doing_async = false;
  781. }
  782. // return $scope.my_tree.expand_all()
  783. } else {
  784. SweetAlert.swal({
  785. title: "系统错误!",
  786. text: "请刷新重试!",
  787. type: "error"
  788. });
  789. }
  790. });
  791. };
  792. function convertListToTree(data, treeMap) {
  793. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  794. var root = null; //Initially set our loop to null
  795. var parentNode = null;
  796. //loop over data
  797. for (var i = 0; i < data.length; i++) {
  798. var datum = data[i];
  799. //each node will have children, so let's give it a "children" poperty
  800. datum.children = [];
  801. //add an entry for this node to the map so that any future children can
  802. //lookup the parent
  803. idToNodeMap[datum.id] = datum;
  804. //Does this node have a parent?
  805. if (typeof datum.parent === "undefined" || datum.parent == null) {
  806. //Doesn't look like it, so this node is the root of the tree
  807. root = datum;
  808. treeMap[datum.id] = root;
  809. } else {
  810. //This node has a parent, so let's look it up using the id
  811. parentNode = idToNodeMap[datum.parent];
  812. //We don't need this property, so let's delete it.
  813. delete datum.parent;
  814. //Let's add the current node as a child of the parent node.
  815. parentNode.children.push(datum);
  816. }
  817. }
  818. return root;
  819. }
  820. // 获取状态
  821. $scope.getStatusDictroy = function () {
  822. var data = {
  823. key: "inspection_status",
  824. type: "list"
  825. }
  826. api_wechatfile.getDictionary(data).then(function (res) {
  827. $scope.statusData = res
  828. })
  829. }
  830. $scope.getStatusDictroy();
  831. // 获取执行人
  832. $scope.getExecuteUser = function () {
  833. api_configure_data.fetchDataList("user", {
  834. "idx": 0,
  835. "sum": 1000,
  836. "user": {
  837. "roledata": {
  838. "rolecode": "inspectman"
  839. },
  840. "simple": true
  841. }
  842. }).then(function (res) {
  843. $scope.executeUserData = res.list
  844. })
  845. }
  846. $scope.getExecuteUser()
  847. // 获取创建人
  848. $scope.getCreateUser = function () {
  849. api_configure_data.fetchDataList("user", {
  850. "idx": 0,
  851. "sum": 1000,
  852. "user": {
  853. "simple": true
  854. }
  855. }).then(function (res) {
  856. $scope.createUserData = res.list
  857. })
  858. }
  859. $scope.getCreateUser()
  860. $scope.open = function ($event) {
  861. $event.preventDefault();
  862. $event.stopPropagation();
  863. $scope.opened = !$scope.opened;
  864. };
  865. $scope.endOpen = function ($event) {
  866. $event.preventDefault();
  867. $event.stopPropagation();
  868. $scope.startOpened = false;
  869. $scope.endOpened = !$scope.endOpened;
  870. };
  871. $scope.startOpen = function ($event) {
  872. $event.preventDefault();
  873. $event.stopPropagation();
  874. $scope.endOpened = false;
  875. $scope.startOpened = !$scope.startOpened;
  876. };
  877. function convertParentToChildList(data) {
  878. var treeMap = {};
  879. var list = [];
  880. convertListToTree(data, treeMap);
  881. angular.forEach(treeMap, function (item) {
  882. list.push(item);
  883. });
  884. return list;
  885. }
  886. $scope.refresh = function () {
  887. var jry_filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  888. var intervalData = {};
  889. if ($scope.inspectdata.type) {
  890. $scope.inspectdata.inspectionTypeDTO = $scope.inspectdata.type.id;
  891. }
  892. if ($scope.inspectdata.createTime) {
  893. $scope.inspectdata.createTime = moment($scope.inspectdata.createTime).format('YYYY-MM-DD');
  894. }
  895. intervalData.idx = jry_filterData.idx;
  896. intervalData.sum = jry_filterData.sum;
  897. intervalData.inspection = $scope.inspectdata;
  898. $scope.refreshData('expand-right', intervalData);
  899. }
  900. $scope.try_async_load();
  901. $scope.refreshData('expand-right', $scope.fileData);
  902. $scope.timer = $interval(function () {
  903. $scope.refreshData('expand-right', $scope.fileData, false);
  904. }, $rootScope.refreshTime);
  905. $scope.$on('$destroy', function () {
  906. $interval.cancel($scope.timer)
  907. })
  908. }]);
  909. app.factory('inspectListMobileCtrlTree', ['api_bpm_data', function (api_bpm_data) {
  910. function convertListToTree(data, treeMap) {
  911. var idToNodeMap = {};
  912. var root = null;
  913. var parentNode = null;
  914. for (var i = 0; i < data.length; i++) {
  915. var datum = data[i];
  916. datum.children = [];
  917. idToNodeMap[datum.id] = datum;
  918. if (typeof datum.parent === "undefined" || datum.parent == null) {
  919. root = datum;
  920. treeMap[datum.id] = root;
  921. } else {
  922. parentNode = idToNodeMap[datum.parent];
  923. delete datum.parent;
  924. parentNode.children.push(datum);
  925. }
  926. }
  927. return root;
  928. };
  929. function convertParentToChildList(data) {
  930. var treeMap = {};
  931. var list = [];
  932. convertListToTree(data, treeMap);
  933. angular.forEach(treeMap, function (item) {
  934. list.push(item);
  935. });
  936. return list;
  937. };
  938. var forEachEelement = function forEachEelement(response) {
  939. var objects = [];
  940. angular.forEach(response.list, function (ObjIndex, index, destObj) {
  941. var object = {};
  942. object.id = ObjIndex.id;
  943. object.label = ObjIndex.type;
  944. if (ObjIndex.parent && ObjIndex.parent.id != 0) {
  945. object.parent = ObjIndex.parent.id;
  946. };
  947. if (ObjIndex.formUiEdit) {
  948. object.formUiEdit = ObjIndex.formUiEdit;
  949. };
  950. if (ObjIndex.formUiName) {
  951. object.formUiName = ObjIndex.formUiName;
  952. };
  953. if (ObjIndex.processKey) {
  954. object.processKey = ObjIndex.processKey;
  955. };
  956. if (ObjIndex.formUiStart) {
  957. object.formUiStart = ObjIndex.formUiStart;
  958. };
  959. objects.push(object);
  960. });
  961. var my_data = convertParentToChildList(objects);
  962. var tree_data = angular.copy(my_data);
  963. return {
  964. 'my_data': my_data,
  965. 'tree_data': tree_data
  966. }
  967. }
  968. return forEachEelement;
  969. }]);