inspectPlanCtrl.js 34 KB

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