inspectPlanCtrl.js 34 KB

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