inspectPlanCtrl.js 36 KB

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