inspectPlanCtrl.js 34 KB

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