summaryCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("summaryCtrl", [
  6. "$rootScope",
  7. "$scope",
  8. "$state",
  9. "$timeout",
  10. "$interval",
  11. "$modal",
  12. "SweetAlert",
  13. "i18nService",
  14. "uiGridConstants",
  15. "uiGridGroupingConstants",
  16. "Restangular",
  17. "api_bpm_schedule",
  18. "api_bpm_data",
  19. "api_wechatfile",
  20. "api_configure_data",
  21. "moment",
  22. function (
  23. $rootScope,
  24. $scope,
  25. $state,
  26. $timeout,
  27. $interval,
  28. $modal,
  29. SweetAlert,
  30. i18nService,
  31. uiGridConstants,
  32. uiGridGroupingConstants,
  33. Restangular,
  34. api_bpm_schedule,
  35. api_bpm_data,
  36. api_wechatfile,
  37. api_configure_data,
  38. moment
  39. ) {
  40. $scope.langs = i18nService.getAllLangs();
  41. $scope.lang = "zh-cn";
  42. i18nService.setCurrentLang($scope.lang);
  43. var loginUser = $rootScope.user;
  44. $scope.chakan = false;
  45. $scope.shanchu = false;
  46. $scope.shenhe = false;
  47. for (var i = 0; i < loginUser.menu.length; i++) {
  48. if (loginUser.menu[i].link == "summary_chakan") {
  49. $scope.chakan = true;
  50. }
  51. if (loginUser.menu[i].link == "summary_shanchu") {
  52. $scope.shanchu = true;
  53. }
  54. if (loginUser.menu[i].link == "summary_shenhe") {
  55. $scope.shenhe = true;
  56. }
  57. }
  58. var defaultFilterData = {
  59. idx: 0,
  60. sum: 10,
  61. };
  62. var repairSummaryParameter = {
  63. idx: 0,
  64. sum: 10,
  65. operation: "",
  66. status: "",
  67. repairSummary: {},
  68. };
  69. //本地存储
  70. sessionStorage.repairSummaryParameter = JSON.stringify(repairSummaryParameter);
  71. $scope.memoryfilterData = {
  72. idx: 0,
  73. sum: 10,
  74. };
  75. // $scope.isMask = false;
  76. $scope.gridOptions = {};
  77. $scope.gridOptions.data = "myData";
  78. $scope.gridOptions.enableColumnResizing = true;
  79. $scope.gridOptions.enableFiltering = false;
  80. $scope.gridOptions.enableGridMenu = true;
  81. $scope.gridOptions.enableRowSelection = true;
  82. $scope.gridOptions.showGridFooter = true;
  83. $scope.gridOptions.showColumnFooter = false;
  84. $scope.gridOptions.useExternalFiltering = false;
  85. $scope.gridOptions.useExternalPagination = true;
  86. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  87. $scope.gridOptions.paginationPageSize = 10;
  88. $scope.gridOptions.multiSelect = true;
  89. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  90. //行鼠标悬浮变色功能
  91. // $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>';
  92. $scope.gridOptions.rowTemplate =
  93. '<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>';
  94. $scope.gridOptions.rowIdentity = function (row) {
  95. return row.id;
  96. };
  97. $scope.gridOptions.getRowIdentity = function (row) {
  98. return row.id;
  99. };
  100. $scope.transfer = function (status) {
  101. if (status === "正常") {
  102. return "执行中";
  103. } else if (status === "停止") {
  104. return "暂停中";
  105. }
  106. };
  107. $scope.gridOptions.columnDefs = [
  108. {
  109. name: "item",
  110. displayName: "序号",
  111. width: 50,
  112. enableFiltering: false,
  113. },
  114. {
  115. name: "incidentSign",
  116. displayName: "事件单号",
  117. width: "10%",
  118. enableFiltering: false,
  119. },
  120. {
  121. name: "description",
  122. displayName: "故障描述",
  123. width: "400",
  124. enableFiltering: false,
  125. // cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.planStartTime.length>16?grid.appScope.transferTime(row.entity.planStartTime):row.entity.planStartTime}}</div>'
  126. },
  127. {
  128. name: "maintainer",
  129. displayName: "维修人",
  130. width: "10%",
  131. enableFiltering: false,
  132. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.maintainer ? row.entity.maintainer.name : ""}}</div>'
  133. },
  134. {
  135. name: "totalMaintenancePrice",
  136. displayName: "维修总价",
  137. width: "10%",
  138. enableFiltering: false,
  139. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.totalMaintenancePrice || 0}}元</div>'
  140. },
  141. {
  142. name: "createTime",
  143. displayName: "生成时间",
  144. width: "11%",
  145. enableFiltering: false,
  146. cellTemplate: '<div class="ui-grid-cell-contents">{{ grid.appScope.transferTime(row.entity.createTime) }}</div>'
  147. },
  148. {
  149. name: "state",
  150. displayName: "状态",
  151. width: "6%",
  152. enableFiltering: false,
  153. cellTemplate:
  154. '<div class="ui-grid-cell-contents"><span ng-if="row.entity.state == 1">暂存</span><span ng-if="row.entity.state == 2">未审核</span><span ng-if="row.entity.state == 3">审核通过</span></div>',
  155. },
  156. {
  157. minWidth: "230",
  158. name: "操作",
  159. enableFiltering: false,
  160. cellTemplate:
  161. '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  162. '<a ng-click="grid.appScope.seeFunction(row.entity)" ng-if="grid.appScope.chakan" class="bianjifont">查看</a>' +
  163. '<a ng-click="grid.appScope.removeData(row.entity)" ng-if="grid.appScope.shanchu" class="bianjifont">删除</a>' +
  164. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-if="grid.appScope.shenhe && row.entity.state == 2" class="bianjifont">审核通过</a>' +
  165. "</div>",
  166. },
  167. // { name: 'planTime2', displayName: '截止时间', width: 160, enableFiltering: false },
  168. ];
  169. $scope.transferTime = function (time) {
  170. if(time){
  171. return moment(time).format("YYYY-MM-DD HH:mm");
  172. }else{
  173. return '';
  174. }
  175. };
  176. $scope.inspectdata = {};
  177. //跳转到查看列表
  178. $scope.seeFunction = function (data) {
  179. console.log(data)
  180. $state.go("app.incident.summaryDetail", {
  181. incidentId: data.incidentId,
  182. id: data.id,
  183. });
  184. };
  185. //审核通过
  186. $scope.runFunction = function (data) {
  187. var modalInstance = $modal.open({
  188. // templateUrl: 'assets/views/inspect/changRun.html',
  189. templateUrl: "assets/views/delete.html",
  190. // size: "sm",
  191. controller: function ($scope, $modalInstance) {
  192. $scope.isRunFunction = true;
  193. var status = "";
  194. $scope.title = "审核通过";
  195. $scope.connect = "确定要审核通过?";
  196. $scope.ok = function () {
  197. $modalInstance.close(data);
  198. };
  199. $scope.cancel = function () {
  200. $modalInstance.dismiss("cancel");
  201. };
  202. },
  203. size: "sm",
  204. });
  205. modalInstance.result.then(function (result) {
  206. if (result) {
  207. var toData = {
  208. summaryId: result.id,
  209. };
  210. api_bpm_data.approved(toData).then(
  211. function (response) {
  212. var myData = Restangular.stripRestangular(response);
  213. if (myData.status == 200) {
  214. $scope.refreshData("expand-right", $scope.fileData);
  215. }
  216. },
  217. function () {
  218. // $scope.ldloading[style.replace('-', '_')] = false;
  219. }
  220. );
  221. }
  222. });
  223. };
  224. //行删除
  225. $scope.removeData = function (item) {
  226. console.log($scope.selected.items);
  227. var rmDatas = [item] || $scope.selected.items;
  228. var modalInstance = $modal.open({
  229. templateUrl: "assets/views/delete.html",
  230. controller: function ($scope, $modalInstance) {
  231. $scope.title = "删除";
  232. $scope.connect = "确定要删除?";
  233. $scope.ok = function () {
  234. $modalInstance.close("start");
  235. };
  236. $scope.cancel = function () {
  237. $modalInstance.dismiss("cancel");
  238. };
  239. },
  240. size: "sm",
  241. });
  242. modalInstance.result.then(
  243. function (result) {
  244. if (result) {
  245. if (rmDatas.length != 0) {
  246. $rootScope.isMask = true;
  247. }
  248. var rmvList = [];
  249. angular.forEach(rmDatas, function (item) {
  250. rmvList.push(item.id);
  251. });
  252. if (rmvList.length > 0) {
  253. api_bpm_data
  254. .rmvData("repairSummary", rmvList)
  255. .then(function (response) {
  256. if (response.status == 200) {
  257. $rootScope.isMask = false;
  258. SweetAlert.swal(
  259. {
  260. title: "删除成功!",
  261. type: "success",
  262. confirmButtonColor: "#007AFF",
  263. },
  264. function () {
  265. $scope.myData = _.reject($scope.myData, function (o) {
  266. return _.includes(rmvList, o.id);
  267. });
  268. $scope.selected = {
  269. items: [],
  270. };
  271. }
  272. );
  273. $scope.gridApi.selection.clearSelectedRows();
  274. $scope.refreshData("expand-right", $scope.fileData);
  275. //取消遮罩层
  276. // $scope.isMask = false;
  277. } else {
  278. $rootScope.isMask = false;
  279. SweetAlert.swal({
  280. title: "操作异常!",
  281. text: "系统异常,请稍后重试,或者联系管理员!",
  282. type: "error",
  283. });
  284. }
  285. });
  286. }
  287. }
  288. },
  289. function () {
  290. // $scope.ldloading[style.replace('-', '_')] = false;
  291. }
  292. );
  293. };
  294. $scope.selected = {
  295. items: [],
  296. };
  297. $scope.editted = {
  298. items: [],
  299. };
  300. $scope.testRow = [];
  301. $scope.gridOptions.onRegisterApi = function (gridApi) {
  302. //导入gridApi对象
  303. $scope.gridApi = gridApi;
  304. //分页选项
  305. gridApi.pagination.on.paginationChanged(
  306. $scope,
  307. function (newPage, pageSize) {
  308. var filterData = JSON.parse(sessionStorage.repairSummaryParameter);
  309. var filtersData = {};
  310. filtersData.idx = newPage - 1;
  311. filtersData.sum = pageSize;
  312. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  313. // console.log(pp);
  314. filterData.idx = $scope.pageNum;
  315. $scope.fileData.idx = newPage - 1;
  316. $scope.fileData.sum = pageSize;
  317. sessionStorage.repairSummaryParameter = JSON.stringify(filterData);
  318. $scope.refreshData("expand-right", $scope.fileData);
  319. }
  320. );
  321. //勾选行事件
  322. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  323. if (data.isSelected) {
  324. $scope.selected.items.push(data.entity);
  325. } else {
  326. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  327. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  328. //angular.forEach(objs, function(data,index,array)
  329. angular.forEach(
  330. $scope.selected.items,
  331. function (ObjIndex, index, destObj) {
  332. // console.log(ObjIndex);
  333. // console.log(index);
  334. // console.log(destObj);
  335. if (ObjIndex.id == data.entity.id) {
  336. destObj.splice(index, 1);
  337. }
  338. }
  339. );
  340. }
  341. });
  342. //批量全选
  343. gridApi.selection.on.rowSelectionChangedBatch(
  344. $scope,
  345. function (rows, event) {
  346. // if ($scope.selected.items.length != 0) {
  347. // $scope.selected.items = [];
  348. angular.forEach(rows, function (ObjIndex, index, destObj) {
  349. if (ObjIndex.isSelected) {
  350. $scope.selected.items.push(ObjIndex.entity);
  351. } else {
  352. $scope.selected.items = [];
  353. // $scope.selected.items.splice(index, 1);
  354. }
  355. });
  356. // } else {
  357. // }
  358. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  359. // if ($scope.selected.items.length == 0) {
  360. // $scope.selected.items = $scope.mySelectedRows;
  361. // } else if ($scope.mySelectedRows.length == 0) {
  362. // for (var i = 0; i < $scope.selected.items.length; i++) {
  363. // for (var j = 0; j < rows.length; j++) {
  364. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  365. // $scope.selected.items.splice(i, 1);
  366. // }
  367. // }
  368. // }
  369. // } else {
  370. // angular.forEach($scope.mySelectedRows, function(item) {
  371. // $scope.selected.items.push(item);
  372. // });
  373. // }
  374. }
  375. );
  376. //列过滤事件
  377. gridApi.core.on.filterChanged($scope, function () {
  378. var grid = this.grid;
  379. var filterData = JSON.parse(sessionStorage.repairSummaryParameter);
  380. angular.forEach(grid.columns, function (item) {
  381. if (item.enableFiltering) {
  382. if (
  383. angular.isDefined(item.filters[0].term) &&
  384. item.filters[0].term != ""
  385. ) {
  386. if (angular.isUndefined(filterData["repairSummary"])) {
  387. filterData["repairSummary"] = {};
  388. }
  389. filterData["repairSummary"]["title"] = item.filters[0].term;
  390. }
  391. }
  392. });
  393. sessionStorage.repairSummaryParameter = JSON.stringify(filterData);
  394. $scope.refreshData("expand-right", filterData);
  395. });
  396. };
  397. //数据刷新
  398. $scope.refreshData = function (style, filterData) {
  399. $scope.ldloading[style.replace("-", "_")] = true;
  400. if (angular.isUndefined(filterData)) {
  401. filterData = defaultFilterData;
  402. }
  403. $scope.myData = [];
  404. if($rootScope.user.duty){
  405. filterData.repairSummary.dutyId = $rootScope.user.duty.id;
  406. }else if($rootScope.user.branch){
  407. filterData.repairSummary.branch = $rootScope.user.branch.id;
  408. }
  409. api_bpm_data.fetchDataList("repairSummary", filterData).then(
  410. function (data) {
  411. var myData = Restangular.stripRestangular(data);
  412. $scope.gridOptions.totalItems = myData.totalNum;
  413. if (angular.isArray(myData.list)) {
  414. $scope.myData = myData.list;
  415. for (var i = 0; i < $scope.myData.length; i++) {
  416. $scope.myData[i]["item"] =
  417. i + 1 + filterData.idx * filterData.sum;
  418. if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
  419. $scope.myData[i].percent = (
  420. ($scope.myData[i].completed * 100) /
  421. ($scope.myData[i].doing + $scope.myData[i].completed)
  422. ).toFixed(1);
  423. } else if ($scope.myData[i].completed == 0) {
  424. $scope.myData[i].percent = "0.0";
  425. } else {
  426. $scope.myData[i].percent = "0.0";
  427. }
  428. }
  429. console.log($scope.myData);
  430. for (var i = 0; i < $scope.myData.length; i++) {
  431. if ($scope.myData[i].status == "正常") {
  432. $scope.myData[i].style = "fa fa-play";
  433. } else if ($scope.myData[i].status == "停止") {
  434. $scope.myData[i].style = "fa fa-pause";
  435. }
  436. $scope.myData[i].runStatus = $scope.transfer(
  437. $scope.myData[i].status
  438. );
  439. }
  440. } else {
  441. SweetAlert.swal({
  442. title: "数据为空",
  443. text: myData.data,
  444. type: "warning",
  445. });
  446. }
  447. $scope.ldloading[style.replace("-", "_")] = false;
  448. },
  449. function () {
  450. $scope.ldloading[style.replace("-", "_")] = false;
  451. }
  452. );
  453. };
  454. $scope.refreshData2 = function (style, filterData) {
  455. $scope.ldloading[style.replace("-", "_")] = true;
  456. if (angular.isUndefined(filterData)) {
  457. filterData = defaultFilterData;
  458. }
  459. // $scope.myData = [];
  460. if($rootScope.user.duty){
  461. filterData.repairSummary.dutyId = $rootScope.user.duty.id;
  462. }else if($rootScope.user.branch){
  463. filterData.repairSummary.branch = $rootScope.user.branch.id;
  464. }
  465. api_bpm_data.fetchDataList("repairSummary", filterData).then(
  466. function (data) {
  467. var myData = Restangular.stripRestangular(data);
  468. $scope.gridOptions.totalItems = myData.totalNum;
  469. if (angular.isArray(myData.list)) {
  470. $scope.myData = myData.list;
  471. for (var i = 0; i < $scope.myData.length; i++) {
  472. $scope.myData[i]["item"] =
  473. i + 1 + filterData.idx * filterData.sum;
  474. if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
  475. $scope.myData[i].percent = (
  476. ($scope.myData[i].completed * 100) /
  477. ($scope.myData[i].doing + $scope.myData[i].completed)
  478. ).toFixed(1);
  479. } else if ($scope.myData[i].completed == 0) {
  480. $scope.myData[i].percent = "0.0";
  481. } else {
  482. $scope.myData[i].percent = "0.0";
  483. }
  484. }
  485. console.log($scope.myData);
  486. for (var i = 0; i < $scope.myData.length; i++) {
  487. if ($scope.myData[i].status == "正常") {
  488. $scope.myData[i].style = "fa fa-play";
  489. } else if ($scope.myData[i].status == "停止") {
  490. $scope.myData[i].style = "fa fa-pause";
  491. }
  492. $scope.myData[i].runStatus = $scope.transfer(
  493. $scope.myData[i].status
  494. );
  495. }
  496. } else {
  497. SweetAlert.swal({
  498. title: "数据为空",
  499. text: myData.data,
  500. type: "warning",
  501. });
  502. }
  503. $scope.ldloading[style.replace("-", "_")] = false;
  504. },
  505. function () {
  506. $scope.ldloading[style.replace("-", "_")] = false;
  507. }
  508. );
  509. };
  510. $scope.ldloading = {};
  511. $scope.fileData = {
  512. idx: 0,
  513. sum: 10,
  514. repairSummary: {},
  515. };
  516. $scope.inspecttype = {};
  517. $scope.searchinspe = function (item) {
  518. $scope.refreshData("expand-right", $scope.fileData);
  519. };
  520. $scope.refresh = function () {
  521. var jry_filterData = JSON.parse(sessionStorage.repairSummaryParameter);
  522. var intervalData = {};
  523. intervalData.idx = jry_filterData.idx;
  524. intervalData.sum = jry_filterData.sum;
  525. intervalData.repairSummary = $scope.inspectdata;
  526. $scope.refreshData("expand-right", intervalData);
  527. };
  528. $scope.refreshData("expand-right", $scope.fileData);
  529. $scope.timer = $interval(function () {
  530. $scope.refreshData2("expand-right", $scope.fileData);
  531. }, $rootScope.refreshTime);
  532. $scope.$on("$destroy", function () {
  533. $interval.cancel($scope.timer);
  534. });
  535. },
  536. ]);