inspectPlanCtrl.js 37 KB

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