inspectPlanCtrl.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('inspectPlanCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_wechatfile", "api_configure_data", "moment", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_wechatfile, api_configure_data, moment) {
  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: 'planStrategy.name',
  94. displayName: '执行策略',
  95. width: '10%',
  96. enableFiltering: false
  97. },
  98. {
  99. name: 'planStartTime',
  100. displayName: '计划开始时间',
  101. width: '140',
  102. enableFiltering: false,
  103. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.planStartTime.length>16?grid.appScope.transferTime(row.entity.planStartTime):row.entity.planStartTime}}</div>'
  104. },
  105. {
  106. name: 'planEndTime',
  107. displayName: '计划结束时间',
  108. width: '140',
  109. enableFiltering: false,
  110. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.planEndTime.length>16?grid.appScope.transferTime(row.entity.planEndTime):row.entity.planEndTime}}</div>'
  111. },
  112. // {
  113. // name: 'dictionary.name',
  114. // displayName: '巡检类型',
  115. // width: '109',
  116. // enableFiltering: false
  117. // },
  118. // {
  119. // name: 'executeUser.name',
  120. // displayName: '执行人/组',
  121. // width: '11%',
  122. // enableFiltering: false,
  123. // cellTemplate: '<div class="ui-grid-cell-contents"><span ng-if="row.entity.dictionary.value == 1&&row.entity.executeUser">{{row.entity.executeUser.name }}</span><span ng-if="row.entity.dictionary.value == 3&&row.entity.group">{{row.entity.group.groupName }}</span><span ng-if="row.entity.dictionary.value == 4">无</span></div>'
  124. // },
  125. {
  126. name: 'status.name',
  127. displayName: '状态',
  128. width: '6%',
  129. enableFiltering: false
  130. },
  131. // {
  132. // name: 'executionTime',
  133. // displayName: '执行时长',
  134. // width: '10%',
  135. // enableFiltering: false,
  136. // cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.executionTime + "分钟"}}</div>'
  137. // },
  138. {
  139. name: 'onPercent',
  140. displayName: '当前批次进度(线上)',
  141. width: '12%',
  142. enableFiltering: false,
  143. cellTemplate: `<div class="ui-grid-cell-contents" title="{{row.entity.onPercent}}%">
  144. <progressbar value="row.entity.onPercent" type="success">{{row.entity.onPercent}}%</progressbar>
  145. </div>`
  146. },
  147. {
  148. name: 'offPercent',
  149. displayName: '当前批次进度(线下)',
  150. width: '12%',
  151. enableFiltering: false,
  152. cellTemplate: `<div class="ui-grid-cell-contents" title="{{row.entity.offPercent}}%">
  153. <progressbar value="row.entity.offPercent" type="success">{{row.entity.offPercent}}%</progressbar>
  154. </div>`
  155. },
  156. {
  157. name: 'batchNoDesc',
  158. displayName: '最新批次号',
  159. width: '15%',
  160. enableFiltering: false
  161. },
  162. // {
  163. // name: 'createUser.name',
  164. // displayName: '创建人',
  165. // width: '8%',
  166. // enableFiltering: false
  167. // },
  168. // { name: 'createTime', displayName: '创建时间', width: '12%', enableFiltering: false },
  169. {
  170. minWidth: '230',
  171. name: '操作',
  172. enableFiltering: false,
  173. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  174. // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="right"><i class="icon iconfont icon-bianji bianjifont"></i></a>' +
  175. '<a ng-click="grid.appScope.seeFunction(row.entity)" class="bianjifont">查看</a>' +
  176. '<a ng-click="grid.appScope.selectRowFunction(row.entity)" ng-show="{{(row.entity.status.name==\'配置中\'||row.entity.status.name==\'执行中\'||row.entity.status.name==\'暂停中\')&&grid.appScope.bianji}}" class="bianjifont">编辑</a>' +
  177. // '<a ng-click="grid.appScope.runFunction(row.entity)" tooltip={{row.entity.runStatus}} tooltip-placement="left"><i class={{row.entity.style}}/></a>' +
  178. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'执行中\'&&grid.appScope.zantingzhixing}}" class="bianjifont">暂停计划</a>' +
  179. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'暂停中\'&&grid.appScope.zantingzhixing}}" class="bianjifont">继续执行</a>' +
  180. '<a ng-click="grid.appScope.executeOnce(row.entity)" ng-show="{{row.entity.status.name!=\'配置中\'}}" class="bianjifont">执行一次</a>' +
  181. '</div>'
  182. },
  183. // { name: 'planTime2', displayName: '截止时间', width: 160, enableFiltering: false },
  184. ];
  185. $scope.transferTime = function (time) {
  186. return moment(time).format('YYYY-MM-DD HH:mm');
  187. }
  188. //新增数据
  189. $scope.addData = function () {
  190. $state.go('app.inspection.editor', {
  191. formKey: 'inspectionform',
  192. service: 'api_bpm_data',
  193. });
  194. }
  195. $scope.inspectdata = {};
  196. //跳转到编辑列表
  197. $scope.selectRowFunction = function (data) {
  198. var datas = delete data.item;
  199. datas = delete data.style;
  200. datas = delete data.runStatus;
  201. var filedata = {
  202. model: {
  203. inspection: data
  204. }
  205. };
  206. $state.go('app.inspection.editor', {
  207. formKey: 'inspectionform',
  208. service: 'api_bpm_data',
  209. model: JSON.stringify(filedata)
  210. });
  211. };
  212. //执行一次
  213. $scope.executeOnce = function (data) {
  214. console.log(data);
  215. var modalInstance = $modal.open({
  216. // templateUrl: 'assets/views/inspect/changRun.html',
  217. templateUrl: 'assets/views/delete.html',
  218. // size: "sm",
  219. controller: function ($scope, $modalInstance) {
  220. $scope.title = '提示';
  221. $scope.connect = '是否执行一次该巡检计划?';
  222. $scope.ok = function () {
  223. $modalInstance.close(data);
  224. };
  225. $scope.cancel = function () {
  226. $modalInstance.dismiss('cancel');
  227. };
  228. },
  229. size: 'sm'
  230. })
  231. modalInstance.result.then(function (result) {
  232. console.log(result);
  233. if (result) {
  234. api_bpm_data.executeOnce({inspection:data}).then(function (response) {
  235. if(response.status == 200){
  236. SweetAlert.swal({
  237. title: "操作成功!",
  238. type: "success",
  239. });
  240. }else{
  241. SweetAlert.swal({
  242. title: "操作失败!",
  243. type: "error",
  244. });
  245. }
  246. })
  247. }
  248. });
  249. };
  250. //跳转到查看列表
  251. $scope.seeFunction = function (data) {
  252. var filedata = {
  253. model: {
  254. inspection: data
  255. }
  256. };
  257. $state.go('app.inspection.form', {
  258. formKey: 'inspection__detailform',
  259. service: 'api_bpm_data',
  260. model: JSON.stringify(filedata)
  261. });
  262. }
  263. // $scope.onDblClick = function(data) {
  264. // var filedata = {
  265. // model: {
  266. // inspection: data.entity
  267. // }
  268. // };
  269. // $state.go('app.inspection.form', {
  270. // formKey: 'inspection__detailform',
  271. // service: 'api_bpm_data',
  272. // model: JSON.stringify(filedata)
  273. // });
  274. // };
  275. //跳转到查看列表
  276. $scope.lookFunction = function (data) {
  277. var filedata = {
  278. model: {
  279. inspection: data
  280. }
  281. };
  282. $state.go('app.inspection.form', {
  283. formKey: 'inspection__detailform',
  284. service: 'api_bpm_data',
  285. model: JSON.stringify(filedata)
  286. });
  287. };
  288. //巡检暂停/恢复
  289. $scope.runFunction = function (data) {
  290. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  291. var upData = {};
  292. upData.id = data.id;
  293. upData.operation = 1;
  294. var modalInstance = $modal.open({
  295. // templateUrl: 'assets/views/inspect/changRun.html',
  296. templateUrl: 'assets/views/delete.html',
  297. // size: "sm",
  298. controller: function ($scope, $modalInstance) {
  299. $scope.isRunFunction = true;
  300. var status = "";
  301. if (data.status.name == "执行中") {
  302. $scope.title = '暂停巡检计划';
  303. $scope.connect = '确定要暂停该巡检计划?';
  304. // $scope.textLog = "是否暂停该巡检计划";
  305. } else if (data.status.name == "暂停中") {
  306. $scope.title = '开始巡检计划';
  307. $scope.connect = '确定要开始该巡检计划?';
  308. // $scope.textLog = "是否开始该巡检计划";
  309. }
  310. $scope.ok = function () {
  311. // var groupdata = "123";
  312. // $modalInstance.dismiss('cancel');
  313. if (data.status.name == "执行中") {
  314. upData.status = "暂停中";
  315. // data.style = "fa fa-pause";
  316. } else if (data.status.name == "暂停中") {
  317. upData.status = "执行中";
  318. // data.style = "fa fa-play";
  319. }
  320. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  321. // $modalInstance.close(upData);
  322. $modalInstance.close(data);
  323. };
  324. $scope.cancel = function () {
  325. $modalInstance.dismiss('cancel');
  326. };
  327. },
  328. size: 'sm'
  329. })
  330. modalInstance.result.then(function (result) {
  331. if (result) {
  332. // if(result.status=="暂停中"){
  333. // result.status={"id":$scope.statusData[1].id}
  334. // }else{
  335. // result.status={"id":$scope.statusData[2].id}
  336. // }
  337. // var upData = {
  338. // "inspection":{
  339. // "id": result.id,
  340. // "operation": result.operation,
  341. // "status": result.status
  342. // }
  343. // };
  344. if (result.status.value == "1") {
  345. result.status.id = $scope.statusData[1].id
  346. } else if (result.status.value == "2") {
  347. result.status.id = $scope.statusData[0].id
  348. }
  349. var toData = {
  350. "inspection": result
  351. };
  352. api_bpm_data.updData('inspection', toData).then(function (response) {
  353. var myData = Restangular.stripRestangular(response);
  354. if (myData.status == 200) {
  355. var showData = {
  356. "idx": filterData.idx,
  357. "sum": filterData.sum,
  358. "inspection": {
  359. "inspectionTypeDTO": {
  360. "id": ""
  361. }
  362. }
  363. }
  364. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  365. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  366. } else {
  367. showData.inspection.inspectionTypeDTO.id = -1
  368. }
  369. $scope.refreshData('expand-right', $scope.fileData);
  370. }
  371. }, function () {
  372. // $scope.ldloading[style.replace('-', '_')] = false;
  373. });
  374. }
  375. });
  376. };
  377. // $scope.newincident = function(data) {
  378. // $state.go('app.incident.editor', {});
  379. // };
  380. //行删除
  381. $scope.removeData = function () {
  382. console.log($scope.selected.items);
  383. var modalInstance = $modal.open({
  384. templateUrl: 'assets/views/delete.html',
  385. controller: function ($scope, $modalInstance) {
  386. // $scope.textLog = "是否删除巡检计划";
  387. $scope.title = '巡检计划删除';
  388. $scope.connect = '确定要删除巡检计划?';
  389. $scope.ok = function () {
  390. $modalInstance.close("start");
  391. };
  392. $scope.cancel = function () {
  393. $modalInstance.dismiss('cancel');
  394. };
  395. },
  396. size: 'sm'
  397. })
  398. modalInstance.result.then(function (result) {
  399. if (result) {
  400. if ($scope.selected.items.length != 0) {
  401. $rootScope.isMask = true;
  402. }
  403. var rmvList = [];
  404. angular.forEach($scope.selected.items, function (item) {
  405. rmvList.push(item.id);
  406. });
  407. if (rmvList.length > 0) {
  408. api_bpm_data.rmvData('inspection', rmvList).then(function (response) {
  409. if (response.status == 200) {
  410. $rootScope.isMask = false;
  411. SweetAlert.swal({
  412. title: "删除成功!",
  413. type: "success",
  414. confirmButtonColor: "#007AFF"
  415. }, function () {
  416. $scope.myData = _.reject($scope.myData, function (o) {
  417. return _.includes(rmvList, o.id);
  418. });
  419. $scope.selected = {
  420. items: []
  421. };
  422. });
  423. $scope.gridApi.selection.clearSelectedRows();
  424. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  425. var showData = {
  426. "idx": filterData.idx,
  427. "sum": filterData.sum,
  428. "inspection": {
  429. "inspectionTypeDTO": {
  430. "id": ""
  431. }
  432. }
  433. }
  434. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  435. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  436. } else {
  437. showData.inspection.inspectionTypeDTO.id = -1
  438. }
  439. $scope.refreshData('expand-right', $scope.fileData);
  440. //取消遮罩层
  441. // $scope.isMask = false;
  442. } else {
  443. $rootScope.isMask = false;
  444. SweetAlert.swal({
  445. title: "操作异常!",
  446. text: "系统异常,请稍后重试,或者联系管理员!",
  447. type: "error"
  448. });
  449. }
  450. })
  451. }
  452. }
  453. }, function () {
  454. // $scope.ldloading[style.replace('-', '_')] = false;
  455. });
  456. }
  457. $scope.selected = {
  458. items: []
  459. }
  460. $scope.editted = {
  461. items: []
  462. }
  463. $scope.testRow = [];
  464. $scope.gridOptions.onRegisterApi = function (gridApi) {
  465. //导入gridApi对象
  466. $scope.gridApi = gridApi;
  467. //分页选项
  468. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  469. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  470. var filtersData = {};
  471. filtersData.idx = newPage - 1;
  472. filtersData.sum = pageSize;
  473. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  474. // console.log(pp);
  475. filterData.idx = $scope.pageNum;
  476. $scope.fileData.idx = newPage - 1;
  477. $scope.fileData.sum = pageSize;
  478. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  479. $scope.refreshData('expand-right', $scope.fileData);
  480. });
  481. //勾选行事件
  482. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  483. if (data.isSelected) {
  484. $scope.selected.items.push(data.entity);
  485. } else {
  486. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  487. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  488. //angular.forEach(objs, function(data,index,array)
  489. angular.forEach($scope.selected.items, function (ObjIndex, index, destObj) {
  490. // console.log(ObjIndex);
  491. // console.log(index);
  492. // console.log(destObj);
  493. if (ObjIndex.id == data.entity.id) {
  494. destObj.splice(index, 1)
  495. }
  496. })
  497. }
  498. });
  499. //批量全选
  500. gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows, event) {
  501. // if ($scope.selected.items.length != 0) {
  502. // $scope.selected.items = [];
  503. angular.forEach(rows, function (ObjIndex, index, destObj) {
  504. if (ObjIndex.isSelected) {
  505. $scope.selected.items.push(ObjIndex.entity);
  506. } else {
  507. $scope.selected.items = [];
  508. // $scope.selected.items.splice(index, 1);
  509. }
  510. });
  511. // } else {
  512. // }
  513. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  514. // if ($scope.selected.items.length == 0) {
  515. // $scope.selected.items = $scope.mySelectedRows;
  516. // } else if ($scope.mySelectedRows.length == 0) {
  517. // for (var i = 0; i < $scope.selected.items.length; i++) {
  518. // for (var j = 0; j < rows.length; j++) {
  519. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  520. // $scope.selected.items.splice(i, 1);
  521. // }
  522. // }
  523. // }
  524. // } else {
  525. // angular.forEach($scope.mySelectedRows, function(item) {
  526. // $scope.selected.items.push(item);
  527. // });
  528. // }
  529. });
  530. //列过滤事件
  531. gridApi.core.on.filterChanged($scope, function () {
  532. var grid = this.grid;
  533. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  534. angular.forEach(grid.columns, function (item) {
  535. if (item.enableFiltering) {
  536. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  537. if (angular.isUndefined(filterData['inspection'])) {
  538. filterData['inspection'] = {};
  539. }
  540. filterData['inspection']['title'] = item.filters[0].term;
  541. }
  542. }
  543. });
  544. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  545. $scope.refreshData('expand-right', filterData);
  546. });
  547. };
  548. // //刷新按钮
  549. // $scope.reload = function() {
  550. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  551. // var showData = {
  552. // "idx": filterData.idx,
  553. // "sum": filterData.sum,
  554. // "inspection": {
  555. // "inspectionTypeDTO": {
  556. // "id": ""
  557. // }
  558. // }
  559. // }
  560. // if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  561. // showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  562. // } else {
  563. // showData.inspection.inspectionTypeDTO.id = -1
  564. // }
  565. // $scope.refreshData('expand-right', showData);
  566. // }
  567. //重置按钮
  568. $scope.reload = function () {
  569. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  570. // var data={
  571. // "idx":filterData.idx,
  572. // "sum":filterData.sum
  573. // }
  574. // $scope.inspectdata={};
  575. delete $scope.fileData.inspection.inspectionTypeDTO;
  576. delete $scope.fileData.inspection.title;
  577. delete $scope.fileData.inspection.executeUser;
  578. delete $scope.fileData.inspection.createUser;
  579. delete $scope.fileData.inspection.status;
  580. $scope.try_async_load();
  581. $scope.refreshData('expand-right', $scope.fileData);
  582. }
  583. //数据刷新
  584. $scope.refreshData = function (style, filterData) {
  585. $scope.ldloading[style.replace('-', '_')] = true;
  586. if (angular.isUndefined(filterData)) {
  587. filterData = defaultFilterData;
  588. }
  589. $scope.myData = [];
  590. api_bpm_data.fetchDataList('inspection', filterData).then(function (data) {
  591. var myData = Restangular.stripRestangular(data);
  592. $scope.gridOptions.totalItems = myData.totalNum;
  593. if (angular.isArray(myData.list)) {
  594. $scope.myData = myData.list;
  595. for (var i = 0; i < $scope.myData.length; i++) {
  596. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  597. if($scope.myData[i].onDoing + $scope.myData[i].onCompleted != 0){
  598. $scope.myData[i].onPercent = ($scope.myData[i].onCompleted*100/($scope.myData[i].onDoing + $scope.myData[i].onCompleted)).toFixed(1);
  599. }else if($scope.myData[i].onCompleted == 0){
  600. $scope.myData[i].onPercent = '0.0';
  601. }else{
  602. $scope.myData[i].onPercent = '0.0';
  603. }
  604. if($scope.myData[i].offDoing + $scope.myData[i].offCompleted != 0){
  605. $scope.myData[i].offPercent = ($scope.myData[i].offCompleted*100/($scope.myData[i].offDoing + $scope.myData[i].offCompleted)).toFixed(1);
  606. }else if($scope.myData[i].offCompleted == 0){
  607. $scope.myData[i].offPercent = '0.0';
  608. }else{
  609. $scope.myData[i].offPercent = '0.0';
  610. }
  611. }
  612. console.log($scope.myData)
  613. for (var i = 0; i < $scope.myData.length; i++) {
  614. if ($scope.myData[i].status == "执行中") {
  615. $scope.myData[i].style = "fa fa-play";
  616. } else if ($scope.myData[i].status == "暂停中") {
  617. $scope.myData[i].style = "fa fa-pause";
  618. };
  619. $scope.myData[i].runStatus = $scope.transfer($scope.myData[i].status);
  620. }
  621. } else {
  622. SweetAlert.swal({
  623. title: "数据为空",
  624. text: myData.data,
  625. type: "warning"
  626. });
  627. }
  628. $scope.ldloading[style.replace('-', '_')] = false;
  629. }, function () {
  630. $scope.ldloading[style.replace('-', '_')] = false;
  631. });
  632. };
  633. $scope.refreshData2 = function (style, filterData) {
  634. $scope.ldloading[style.replace('-', '_')] = true;
  635. if (angular.isUndefined(filterData)) {
  636. filterData = defaultFilterData;
  637. }
  638. // $scope.myData = [];
  639. api_bpm_data.fetchDataList('inspection', filterData).then(function (data) {
  640. var myData = Restangular.stripRestangular(data);
  641. $scope.gridOptions.totalItems = myData.totalNum;
  642. if (angular.isArray(myData.list)) {
  643. $scope.myData = myData.list;
  644. for (var i = 0; i < $scope.myData.length; i++) {
  645. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  646. if($scope.myData[i].doing + $scope.myData[i].completed != 0){
  647. $scope.myData[i].percent = ($scope.myData[i].completed*100/($scope.myData[i].doing + $scope.myData[i].completed)).toFixed(1);
  648. }else if($scope.myData[i].completed == 0){
  649. $scope.myData[i].percent = '0.0';
  650. }else{
  651. $scope.myData[i].percent = '0.0';
  652. }
  653. }
  654. console.log($scope.myData)
  655. for (var i = 0; i < $scope.myData.length; i++) {
  656. if ($scope.myData[i].status == "执行中") {
  657. $scope.myData[i].style = "fa fa-play";
  658. } else if ($scope.myData[i].status == "暂停中") {
  659. $scope.myData[i].style = "fa fa-pause";
  660. };
  661. $scope.myData[i].runStatus = $scope.transfer($scope.myData[i].status);
  662. }
  663. } else {
  664. SweetAlert.swal({
  665. title: "数据为空",
  666. text: myData.data,
  667. type: "warning"
  668. });
  669. }
  670. $scope.ldloading[style.replace('-', '_')] = false;
  671. }, function () {
  672. $scope.ldloading[style.replace('-', '_')] = false;
  673. });
  674. };
  675. $scope.ldloading = {};
  676. //树形控件点击事件
  677. $scope.my_tree_handler = function (branch) {
  678. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  679. filterData.inspection.inspectionTypeDTO.id = branch.id;
  680. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  681. var showData = {
  682. "idx": filterData.id,
  683. "sum": filterData.sum,
  684. "inspection": {
  685. "inspectionTypeDTO": {
  686. "id": branch.id
  687. }
  688. }
  689. }
  690. // $scope.refreshData('expand-right', showData);
  691. }
  692. $scope.fileData = {
  693. "idx": 0,
  694. "sum": 10,
  695. "inspection": {
  696. }
  697. }
  698. $scope.onFilterCallback = function (data) {
  699. $scope.fileData.inspection.inspectionTypeDTO = {
  700. "id": data.id
  701. }
  702. }
  703. $scope.inspecttype = {};
  704. $scope.searchinspe = function (item) {
  705. $scope.refreshData('expand-right', $scope.fileData);
  706. }
  707. //树形控件加载
  708. $scope.my_tree = {};
  709. $scope.try_async_load = function () {
  710. $scope.my_data = [];
  711. $scope.doing_async = true;
  712. api_bpm_data.fetchDataList('inspectionType', {
  713. "idx": 0,
  714. "sum": 1000
  715. }).then(function (response) {
  716. if (response.status == 200) {
  717. var data = response.list;
  718. var objects = [];
  719. for (var i = 0; i < data.length; i++) {
  720. var object = {};
  721. object.id = data[i].id;
  722. if (data[i].parent && data[i].parent.id != 0) {
  723. object.parent = data[i].parent.id;
  724. }
  725. object.label = data[i].type;
  726. objects.push(object);
  727. }
  728. $scope.my_data = convertParentToChildList(objects);
  729. $scope.tree_data = angular.copy($scope.my_data);
  730. if ($scope.my_data.length > 0) {
  731. $scope.doing_async = false;
  732. }
  733. // return $scope.my_tree.expand_all()
  734. } else {
  735. SweetAlert.swal({
  736. title: "系统错误!",
  737. text: "请刷新重试!",
  738. type: "error"
  739. });
  740. }
  741. });
  742. };
  743. function convertListToTree(data, treeMap) {
  744. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  745. var root = null; //Initially set our loop to null
  746. var parentNode = null;
  747. //loop over data
  748. for (var i = 0; i < data.length; i++) {
  749. var datum = data[i];
  750. //each node will have children, so let's give it a "children" poperty
  751. datum.children = [];
  752. //add an entry for this node to the map so that any future children can
  753. //lookup the parent
  754. idToNodeMap[datum.id] = datum;
  755. //Does this node have a parent?
  756. if (typeof datum.parent === "undefined" || datum.parent == null) {
  757. //Doesn't look like it, so this node is the root of the tree
  758. root = datum;
  759. treeMap[datum.id] = root;
  760. } else {
  761. //This node has a parent, so let's look it up using the id
  762. parentNode = idToNodeMap[datum.parent];
  763. //We don't need this property, so let's delete it.
  764. delete datum.parent;
  765. //Let's add the current node as a child of the parent node.
  766. parentNode.children.push(datum);
  767. }
  768. }
  769. return root;
  770. }
  771. // 获取状态
  772. $scope.getStatusDictroy = function () {
  773. var data = {
  774. key: "inspection_status",
  775. type: "list"
  776. }
  777. api_wechatfile.getDictionary(data).then(function (res) {
  778. $scope.statusData = res
  779. })
  780. }
  781. $scope.getStatusDictroy();
  782. // 获取执行人
  783. $scope.getExecuteUser = function () {
  784. api_configure_data.fetchDataList("user", {
  785. "idx": 0,
  786. "sum": 1000,
  787. "user": {
  788. "roledata": {
  789. "rolecode": "inspectman"
  790. },
  791. "simple": true
  792. }
  793. }).then(function (res) {
  794. $scope.executeUserData = res.list
  795. })
  796. }
  797. $scope.getExecuteUser()
  798. // 获取创建人
  799. $scope.getCreateUser = function () {
  800. api_configure_data.fetchDataList("user", {
  801. "idx": 0,
  802. "sum": 1000,
  803. "user":{
  804. "simple": true
  805. }
  806. }).then(function (res) {
  807. $scope.createUserData = res.list
  808. })
  809. }
  810. $scope.getCreateUser()
  811. $scope.open = function ($event) {
  812. $event.preventDefault();
  813. $event.stopPropagation();
  814. $scope.opened = !$scope.opened;
  815. };
  816. $scope.endOpen = function ($event) {
  817. $event.preventDefault();
  818. $event.stopPropagation();
  819. $scope.startOpened = false;
  820. $scope.endOpened = !$scope.endOpened;
  821. };
  822. $scope.startOpen = function ($event) {
  823. $event.preventDefault();
  824. $event.stopPropagation();
  825. $scope.endOpened = false;
  826. $scope.startOpened = !$scope.startOpened;
  827. };
  828. function convertParentToChildList(data) {
  829. var treeMap = {};
  830. var list = [];
  831. convertListToTree(data, treeMap);
  832. angular.forEach(treeMap, function (item) {
  833. list.push(item);
  834. });
  835. return list;
  836. }
  837. $scope.refresh = function () {
  838. var jry_filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  839. var intervalData = {};
  840. if ($scope.inspectdata.type) {
  841. $scope.inspectdata.inspectionTypeDTO = $scope.inspectdata.type.id;
  842. }
  843. if ($scope.inspectdata.createTime) {
  844. $scope.inspectdata.createTime = moment($scope.inspectdata.createTime).format('YYYY-MM-DD');
  845. }
  846. intervalData.idx = jry_filterData.idx;
  847. intervalData.sum = jry_filterData.sum;
  848. intervalData.inspection = $scope.inspectdata;
  849. $scope.refreshData('expand-right', intervalData);
  850. }
  851. $scope.try_async_load();
  852. $scope.refreshData('expand-right', $scope.fileData);
  853. $scope.timer = $interval(function () {
  854. $scope.refreshData2('expand-right', $scope.fileData);
  855. }, $rootScope.refreshTime);
  856. $scope.$on('$destroy', function () {
  857. $interval.cancel($scope.timer)
  858. })
  859. }]);
  860. app.factory('inspectListMobileCtrlTree', ['api_bpm_data', function (api_bpm_data) {
  861. function convertListToTree(data, treeMap) {
  862. var idToNodeMap = {};
  863. var root = null;
  864. var parentNode = null;
  865. for (var i = 0; i < data.length; i++) {
  866. var datum = data[i];
  867. datum.children = [];
  868. idToNodeMap[datum.id] = datum;
  869. if (typeof datum.parent === "undefined" || datum.parent == null) {
  870. root = datum;
  871. treeMap[datum.id] = root;
  872. } else {
  873. parentNode = idToNodeMap[datum.parent];
  874. delete datum.parent;
  875. parentNode.children.push(datum);
  876. }
  877. }
  878. return root;
  879. };
  880. function convertParentToChildList(data) {
  881. var treeMap = {};
  882. var list = [];
  883. convertListToTree(data, treeMap);
  884. angular.forEach(treeMap, function (item) {
  885. list.push(item);
  886. });
  887. return list;
  888. };
  889. var forEachEelement = function forEachEelement(response) {
  890. var objects = [];
  891. angular.forEach(response.list, function (ObjIndex, index, destObj) {
  892. var object = {};
  893. object.id = ObjIndex.id;
  894. object.label = ObjIndex.type;
  895. if (ObjIndex.parent && ObjIndex.parent.id != 0) {
  896. object.parent = ObjIndex.parent.id;
  897. };
  898. if (ObjIndex.formUiEdit) {
  899. object.formUiEdit = ObjIndex.formUiEdit;
  900. };
  901. if (ObjIndex.formUiName) {
  902. object.formUiName = ObjIndex.formUiName;
  903. };
  904. if (ObjIndex.processKey) {
  905. object.processKey = ObjIndex.processKey;
  906. };
  907. if (ObjIndex.formUiStart) {
  908. object.formUiStart = ObjIndex.formUiStart;
  909. };
  910. objects.push(object);
  911. });
  912. var my_data = convertParentToChildList(objects);
  913. var tree_data = angular.copy(my_data);
  914. return {
  915. 'my_data': my_data,
  916. 'tree_data': tree_data
  917. }
  918. }
  919. return forEachEelement;
  920. }]);