timingMessageSendingCtrl.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. console.log(toData.messageJob)
  278. //处理数据 end
  279. api_bpm_data.updData('messageJob', toData).then(function (response) {
  280. $scope.close();
  281. var myData = Restangular.stripRestangular(response);
  282. if (myData.status == 200) {
  283. SweetAlert.swal({
  284. title: "保存成功!",
  285. type: "success",
  286. confirmButtonColor: "#007AFF"
  287. }, function () {
  288. $scope.refreshData('expand-right', $scope.fileData);
  289. });
  290. } else {
  291. SweetAlert.swal({
  292. title: "操作失败",
  293. text: "操作失败",
  294. type: "error"
  295. });
  296. }
  297. }, function () {
  298. });
  299. }
  300. //切换重复策略
  301. $scope.changeWarehousing = function (type) {
  302. $scope.isWarehousing = type;
  303. $scope.doWeek = null;
  304. $scope.doMonth = '';
  305. $scope.starttimesModel = null;
  306. }
  307. //切换是否启用
  308. $scope.changeActive = function (type) {
  309. $scope.isActive = type;
  310. }
  311. // 接收人查询
  312. $scope.d_name = '';//防止抖动
  313. $scope.refreshDat_users = function (name, userIds = []) {
  314. $scope.t_userList = [];
  315. name = name || "";
  316. $scope.d_name = name;
  317. userIds = userIds || [];
  318. var dat = {
  319. "user": {
  320. name: name
  321. },
  322. "idx": 0,
  323. "sum": 999
  324. }
  325. api_sysinfo.fetchDataList("user", dat).then(function (data) {
  326. if (data.status == 200) {
  327. if($scope.d_name == name){
  328. if (userIds.length) {
  329. userIds.forEach(v => {
  330. data.list.forEach((v1, i) => {
  331. if (v.id == v1.id) {
  332. data.list.splice(i, 1)
  333. }
  334. })
  335. })
  336. }
  337. $scope.t_userList = data.list;
  338. }
  339. }
  340. });
  341. }
  342. $scope.refreshDat_users();
  343. // 修改接收人
  344. $scope.changeUser = function (userIds) {
  345. $scope.userIds = userIds;
  346. }
  347. //打开每天定时发送时间--日期选择框
  348. $scope.starttimesModel = null;
  349. $scope.startOpened = false;
  350. //跳转到查看列表
  351. $scope.seeFunction = function (data) {
  352. var filedata = {
  353. model: {
  354. inspection: data
  355. }
  356. };
  357. $state.go('app.inspection.form', {
  358. formKey: 'inspection__detailform',
  359. service: 'api_bpm_data',
  360. model: JSON.stringify(filedata)
  361. });
  362. }
  363. // $scope.onDblClick = function(data) {
  364. // var filedata = {
  365. // model: {
  366. // inspection: data.entity
  367. // }
  368. // };
  369. // $state.go('app.inspection.form', {
  370. // formKey: 'inspection__detailform',
  371. // service: 'api_bpm_data',
  372. // model: JSON.stringify(filedata)
  373. // });
  374. // };
  375. //跳转到查看列表
  376. $scope.lookFunction = function (data) {
  377. var filedata = {
  378. model: {
  379. inspection: data
  380. }
  381. };
  382. $state.go('app.inspection.form', {
  383. formKey: 'inspection__detailform',
  384. service: 'api_bpm_data',
  385. model: JSON.stringify(filedata)
  386. });
  387. };
  388. //启用/停用
  389. $scope.runFunction = function (data) {
  390. console.log(data)
  391. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  392. var upData = {};
  393. upData.id = data.id;
  394. upData.operation = 1;
  395. var modalInstance = $modal.open({
  396. // templateUrl: 'assets/views/inspect/changRun.html',
  397. templateUrl: 'assets/views/delete.html',
  398. // size: "sm",
  399. controller: function ($scope, $modalInstance) {
  400. $scope.isRunFunction = true;
  401. if (data.active) {
  402. $scope.title = '停用';
  403. $scope.connect = '确定要停用?';
  404. } else {
  405. $scope.title = '启用';
  406. $scope.connect = '确定要启用?';
  407. }
  408. $scope.ok = function () {
  409. $modalInstance.close(data);
  410. };
  411. $scope.cancel = function () {
  412. $modalInstance.dismiss('cancel');
  413. };
  414. },
  415. size: 'sm'
  416. })
  417. modalInstance.result.then(function (result) {
  418. console.log(result)
  419. if (result) {
  420. result.active = !result.active;
  421. var toData = {
  422. "messageJob": result
  423. };
  424. api_bpm_data.updData('messageJob', toData).then(function (response) {
  425. var myData = Restangular.stripRestangular(response);
  426. if (myData.status == 200) {
  427. SweetAlert.swal({
  428. title: (myData.data.active ? '启动' : '停用') + "成功!",
  429. type: "success",
  430. confirmButtonColor: "#007AFF"
  431. }, function () {
  432. $scope.refreshData('expand-right', $scope.fileData);
  433. });
  434. } else {
  435. SweetAlert.swal({
  436. title: "操作失败",
  437. text: "操作失败",
  438. type: "error"
  439. });
  440. }
  441. }, function () {
  442. });
  443. }
  444. });
  445. };
  446. // $scope.newincident = function(data) {
  447. // $state.go('app.incident.editor', {});
  448. // };
  449. //行删除
  450. $scope.removeData = function () {
  451. console.log($scope.selected.items);
  452. var modalInstance = $modal.open({
  453. templateUrl: 'assets/views/delete.html',
  454. controller: function ($scope, $modalInstance) {
  455. // $scope.textLog = "是否删除巡检计划";
  456. $scope.title = '巡检计划删除';
  457. $scope.connect = '确定要删除巡检计划?';
  458. $scope.ok = function () {
  459. $modalInstance.close("start");
  460. };
  461. $scope.cancel = function () {
  462. $modalInstance.dismiss('cancel');
  463. };
  464. },
  465. size: 'sm'
  466. })
  467. modalInstance.result.then(function (result) {
  468. if (result) {
  469. if ($scope.selected.items.length != 0) {
  470. $rootScope.isMask = true;
  471. }
  472. var rmvList = [];
  473. angular.forEach($scope.selected.items, function (item) {
  474. rmvList.push(item.id);
  475. });
  476. if (rmvList.length > 0) {
  477. api_bpm_data.rmvData('inspection', rmvList).then(function (response) {
  478. if (response.status == 200) {
  479. $rootScope.isMask = false;
  480. SweetAlert.swal({
  481. title: "删除成功!",
  482. type: "success",
  483. confirmButtonColor: "#007AFF"
  484. }, function () {
  485. $scope.myData = _.reject($scope.myData, function (o) {
  486. return _.includes(rmvList, o.id);
  487. });
  488. $scope.selected = {
  489. items: []
  490. };
  491. });
  492. $scope.gridApi.selection.clearSelectedRows();
  493. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  494. var showData = {
  495. "idx": filterData.idx,
  496. "sum": filterData.sum,
  497. "inspection": {
  498. "inspectionTypeDTO": {
  499. "id": ""
  500. }
  501. }
  502. }
  503. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  504. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  505. } else {
  506. showData.inspection.inspectionTypeDTO.id = -1
  507. }
  508. $scope.refreshData('expand-right', $scope.fileData);
  509. //取消遮罩层
  510. // $scope.isMask = false;
  511. } else {
  512. $rootScope.isMask = false;
  513. SweetAlert.swal({
  514. title: "操作异常!",
  515. text: "系统异常,请稍后重试,或者联系管理员!",
  516. type: "error"
  517. });
  518. }
  519. })
  520. }
  521. }
  522. }, function () {
  523. // $scope.ldloading[style.replace('-', '_')] = false;
  524. });
  525. }
  526. $scope.selected = {
  527. items: []
  528. }
  529. $scope.editted = {
  530. items: []
  531. }
  532. $scope.testRow = [];
  533. $scope.gridOptions.onRegisterApi = function (gridApi) {
  534. //导入gridApi对象
  535. $scope.gridApi = gridApi;
  536. //分页选项
  537. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  538. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  539. var filtersData = {};
  540. filtersData.idx = newPage - 1;
  541. filtersData.sum = pageSize;
  542. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  543. // console.log(pp);
  544. filterData.idx = $scope.pageNum;
  545. $scope.fileData.idx = newPage - 1;
  546. $scope.fileData.sum = pageSize;
  547. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  548. $scope.refreshData('expand-right', $scope.fileData);
  549. });
  550. //勾选行事件
  551. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  552. if (data.isSelected) {
  553. $scope.selected.items.push(data.entity);
  554. } else {
  555. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  556. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  557. //angular.forEach(objs, function(data,index,array)
  558. angular.forEach($scope.selected.items, function (ObjIndex, index, destObj) {
  559. // console.log(ObjIndex);
  560. // console.log(index);
  561. // console.log(destObj);
  562. if (ObjIndex.id == data.entity.id) {
  563. destObj.splice(index, 1)
  564. }
  565. })
  566. }
  567. });
  568. //批量全选
  569. gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows, event) {
  570. // if ($scope.selected.items.length != 0) {
  571. // $scope.selected.items = [];
  572. angular.forEach(rows, function (ObjIndex, index, destObj) {
  573. if (ObjIndex.isSelected) {
  574. $scope.selected.items.push(ObjIndex.entity);
  575. } else {
  576. $scope.selected.items = [];
  577. // $scope.selected.items.splice(index, 1);
  578. }
  579. });
  580. // } else {
  581. // }
  582. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  583. // if ($scope.selected.items.length == 0) {
  584. // $scope.selected.items = $scope.mySelectedRows;
  585. // } else if ($scope.mySelectedRows.length == 0) {
  586. // for (var i = 0; i < $scope.selected.items.length; i++) {
  587. // for (var j = 0; j < rows.length; j++) {
  588. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  589. // $scope.selected.items.splice(i, 1);
  590. // }
  591. // }
  592. // }
  593. // } else {
  594. // angular.forEach($scope.mySelectedRows, function(item) {
  595. // $scope.selected.items.push(item);
  596. // });
  597. // }
  598. });
  599. //列过滤事件
  600. gridApi.core.on.filterChanged($scope, function () {
  601. var grid = this.grid;
  602. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  603. angular.forEach(grid.columns, function (item) {
  604. if (item.enableFiltering) {
  605. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  606. if (angular.isUndefined(filterData['inspection'])) {
  607. filterData['inspection'] = {};
  608. }
  609. filterData['inspection']['title'] = item.filters[0].term;
  610. }
  611. }
  612. });
  613. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  614. $scope.refreshData('expand-right', filterData);
  615. });
  616. };
  617. // //刷新按钮
  618. // $scope.reload = function() {
  619. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  620. // var showData = {
  621. // "idx": filterData.idx,
  622. // "sum": filterData.sum,
  623. // "inspection": {
  624. // "inspectionTypeDTO": {
  625. // "id": ""
  626. // }
  627. // }
  628. // }
  629. // if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  630. // showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  631. // } else {
  632. // showData.inspection.inspectionTypeDTO.id = -1
  633. // }
  634. // $scope.refreshData('expand-right', showData);
  635. // }
  636. //重置按钮
  637. $scope.reload = function () {
  638. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  639. // var data={
  640. // "idx":filterData.idx,
  641. // "sum":filterData.sum
  642. // }
  643. // $scope.inspectdata={};
  644. delete $scope.fileData.inspection.inspectionTypeDTO;
  645. delete $scope.fileData.inspection.title;
  646. delete $scope.fileData.inspection.executeUser;
  647. delete $scope.fileData.inspection.createUser;
  648. delete $scope.fileData.inspection.status;
  649. $scope.try_async_load();
  650. $scope.refreshData('expand-right', $scope.fileData);
  651. }
  652. //数据刷新
  653. $scope.refreshData = function (style, filterData, isEmpty = true) {
  654. $scope.ldloading[style.replace('-', '_')] = true;
  655. if (angular.isUndefined(filterData)) {
  656. filterData = defaultFilterData;
  657. }
  658. if (isEmpty) {
  659. $scope.myData = [];
  660. }
  661. api_bpm_data.fetchDataList('messageJob', filterData).then(function (data) {
  662. var myData = Restangular.stripRestangular(data);
  663. $scope.gridOptions.totalItems = myData.totalNum;
  664. if (angular.isArray(myData.list)) {
  665. // -----seimin start ----
  666. myData.list.forEach((item) => {
  667. if (item.timeStep == "week") {
  668. let weeks = [
  669. "周一",
  670. "周二",
  671. "周三",
  672. "周四",
  673. "周五",
  674. "周六",
  675. "周日",
  676. ];
  677. item.weekName = weeks[item.extra1 - 1];
  678. }
  679. item.usersName = item.users.map((value) => value.name).join();
  680. });
  681. // -----seimin end ----
  682. $scope.myData = myData.list;
  683. for (var i = 0; i < $scope.myData.length; i++) {
  684. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  685. }
  686. for (var i = 0; i < $scope.myData.length; i++) {
  687. if ($scope.myData[i].status == "正常") {
  688. $scope.myData[i].style = "fa fa-play";
  689. } else if ($scope.myData[i].status == "停止") {
  690. $scope.myData[i].style = "fa fa-pause";
  691. };
  692. $scope.myData[i].runStatus = $scope.transfer($scope.myData[i].status);
  693. }
  694. } else {
  695. SweetAlert.swal({
  696. title: "数据为空",
  697. text: myData.data,
  698. type: "warning"
  699. });
  700. }
  701. $scope.ldloading[style.replace('-', '_')] = false;
  702. }, function () {
  703. $scope.ldloading[style.replace('-', '_')] = false;
  704. });
  705. };
  706. $scope.ldloading = {};
  707. //树形控件点击事件
  708. $scope.my_tree_handler = function (branch) {
  709. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  710. filterData.inspection.inspectionTypeDTO.id = branch.id;
  711. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  712. var showData = {
  713. "idx": filterData.id,
  714. "sum": filterData.sum,
  715. "inspection": {
  716. "inspectionTypeDTO": {
  717. "id": branch.id
  718. }
  719. }
  720. }
  721. // $scope.refreshData('expand-right', showData);
  722. }
  723. $scope.fileData = {
  724. "idx": 0,
  725. "sum": 10,
  726. "messageJob": {
  727. }
  728. }
  729. $scope.onFilterCallback = function (data) {
  730. $scope.fileData.inspection.inspectionTypeDTO = {
  731. "id": data.id
  732. }
  733. }
  734. $scope.inspecttype = {};
  735. $scope.searchinspe = function (item) {
  736. $scope.refreshData('expand-right', $scope.fileData);
  737. }
  738. //树形控件加载
  739. $scope.my_tree = {};
  740. $scope.try_async_load = function () {
  741. $scope.my_data = [];
  742. $scope.doing_async = true;
  743. api_bpm_data.fetchDataList('inspectionType', {
  744. "idx": 0,
  745. "sum": 1000
  746. }).then(function (response) {
  747. if (response.status == 200) {
  748. var data = response.list;
  749. var objects = [];
  750. for (var i = 0; i < data.length; i++) {
  751. var object = {};
  752. object.id = data[i].id;
  753. if (data[i].parent && data[i].parent.id != 0) {
  754. object.parent = data[i].parent.id;
  755. }
  756. object.label = data[i].type;
  757. objects.push(object);
  758. }
  759. $scope.my_data = convertParentToChildList(objects);
  760. $scope.tree_data = angular.copy($scope.my_data);
  761. if ($scope.my_data.length > 0) {
  762. $scope.doing_async = false;
  763. }
  764. // return $scope.my_tree.expand_all()
  765. } else {
  766. SweetAlert.swal({
  767. title: "系统错误!",
  768. text: "请刷新重试!",
  769. type: "error"
  770. });
  771. }
  772. });
  773. };
  774. function convertListToTree(data, treeMap) {
  775. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  776. var root = null; //Initially set our loop to null
  777. var parentNode = null;
  778. //loop over data
  779. for (var i = 0; i < data.length; i++) {
  780. var datum = data[i];
  781. //each node will have children, so let's give it a "children" poperty
  782. datum.children = [];
  783. //add an entry for this node to the map so that any future children can
  784. //lookup the parent
  785. idToNodeMap[datum.id] = datum;
  786. //Does this node have a parent?
  787. if (typeof datum.parent === "undefined" || datum.parent == null) {
  788. //Doesn't look like it, so this node is the root of the tree
  789. root = datum;
  790. treeMap[datum.id] = root;
  791. } else {
  792. //This node has a parent, so let's look it up using the id
  793. parentNode = idToNodeMap[datum.parent];
  794. //We don't need this property, so let's delete it.
  795. delete datum.parent;
  796. //Let's add the current node as a child of the parent node.
  797. parentNode.children.push(datum);
  798. }
  799. }
  800. return root;
  801. }
  802. // 获取状态
  803. $scope.getStatusDictroy = function () {
  804. var data = {
  805. key: "inspection_status",
  806. type: "list"
  807. }
  808. api_wechatfile.getDictionary(data).then(function (res) {
  809. $scope.statusData = res
  810. })
  811. }
  812. $scope.getStatusDictroy();
  813. // 获取执行人
  814. $scope.getExecuteUser = function () {
  815. api_configure_data.fetchDataList("user", {
  816. "idx": 0,
  817. "sum": 1000,
  818. "user": {
  819. "roledata": {
  820. "rolecode": "inspectman"
  821. },
  822. "simple": true
  823. }
  824. }).then(function (res) {
  825. $scope.executeUserData = res.list
  826. })
  827. }
  828. $scope.getExecuteUser()
  829. // 获取创建人
  830. $scope.getCreateUser = function () {
  831. api_configure_data.fetchDataList("user", {
  832. "idx": 0,
  833. "sum": 1000,
  834. "user": {
  835. "simple": true
  836. }
  837. }).then(function (res) {
  838. $scope.createUserData = res.list
  839. })
  840. }
  841. $scope.getCreateUser()
  842. $scope.open = function ($event) {
  843. $event.preventDefault();
  844. $event.stopPropagation();
  845. $scope.opened = !$scope.opened;
  846. };
  847. $scope.endOpen = function ($event) {
  848. $event.preventDefault();
  849. $event.stopPropagation();
  850. $scope.startOpened = false;
  851. $scope.endOpened = !$scope.endOpened;
  852. };
  853. $scope.startOpen = function ($event) {
  854. $event.preventDefault();
  855. $event.stopPropagation();
  856. $scope.endOpened = false;
  857. $scope.startOpened = !$scope.startOpened;
  858. };
  859. function convertParentToChildList(data) {
  860. var treeMap = {};
  861. var list = [];
  862. convertListToTree(data, treeMap);
  863. angular.forEach(treeMap, function (item) {
  864. list.push(item);
  865. });
  866. return list;
  867. }
  868. $scope.refresh = function () {
  869. var jry_filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  870. var intervalData = {};
  871. if ($scope.inspectdata.type) {
  872. $scope.inspectdata.inspectionTypeDTO = $scope.inspectdata.type.id;
  873. }
  874. if ($scope.inspectdata.createTime) {
  875. $scope.inspectdata.createTime = moment($scope.inspectdata.createTime).format('YYYY-MM-DD');
  876. }
  877. intervalData.idx = jry_filterData.idx;
  878. intervalData.sum = jry_filterData.sum;
  879. intervalData.inspection = $scope.inspectdata;
  880. $scope.refreshData('expand-right', intervalData);
  881. }
  882. $scope.try_async_load();
  883. $scope.refreshData('expand-right', $scope.fileData);
  884. $scope.timer = $interval(function () {
  885. $scope.refreshData('expand-right', $scope.fileData, false);
  886. }, $rootScope.refreshTime);
  887. $scope.$on('$destroy', function () {
  888. $interval.cancel($scope.timer)
  889. })
  890. }]);
  891. app.factory('inspectListMobileCtrlTree', ['api_bpm_data', function (api_bpm_data) {
  892. function convertListToTree(data, treeMap) {
  893. var idToNodeMap = {};
  894. var root = null;
  895. var parentNode = null;
  896. for (var i = 0; i < data.length; i++) {
  897. var datum = data[i];
  898. datum.children = [];
  899. idToNodeMap[datum.id] = datum;
  900. if (typeof datum.parent === "undefined" || datum.parent == null) {
  901. root = datum;
  902. treeMap[datum.id] = root;
  903. } else {
  904. parentNode = idToNodeMap[datum.parent];
  905. delete datum.parent;
  906. parentNode.children.push(datum);
  907. }
  908. }
  909. return root;
  910. };
  911. function convertParentToChildList(data) {
  912. var treeMap = {};
  913. var list = [];
  914. convertListToTree(data, treeMap);
  915. angular.forEach(treeMap, function (item) {
  916. list.push(item);
  917. });
  918. return list;
  919. };
  920. var forEachEelement = function forEachEelement(response) {
  921. var objects = [];
  922. angular.forEach(response.list, function (ObjIndex, index, destObj) {
  923. var object = {};
  924. object.id = ObjIndex.id;
  925. object.label = ObjIndex.type;
  926. if (ObjIndex.parent && ObjIndex.parent.id != 0) {
  927. object.parent = ObjIndex.parent.id;
  928. };
  929. if (ObjIndex.formUiEdit) {
  930. object.formUiEdit = ObjIndex.formUiEdit;
  931. };
  932. if (ObjIndex.formUiName) {
  933. object.formUiName = ObjIndex.formUiName;
  934. };
  935. if (ObjIndex.processKey) {
  936. object.processKey = ObjIndex.processKey;
  937. };
  938. if (ObjIndex.formUiStart) {
  939. object.formUiStart = ObjIndex.formUiStart;
  940. };
  941. objects.push(object);
  942. });
  943. var my_data = convertParentToChildList(objects);
  944. var tree_data = angular.copy(my_data);
  945. return {
  946. 'my_data': my_data,
  947. 'tree_data': tree_data
  948. }
  949. }
  950. return forEachEelement;
  951. }]);