inspectReportCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("inspectReportCtrl", [
  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_bpm",
  20. "api_wechatfile",
  21. "api_configure_data",
  22. "moment",
  23. function (
  24. $rootScope,
  25. $scope,
  26. $state,
  27. $timeout,
  28. $interval,
  29. $modal,
  30. SweetAlert,
  31. i18nService,
  32. uiGridConstants,
  33. uiGridGroupingConstants,
  34. Restangular,
  35. api_bpm_schedule,
  36. api_bpm_data,
  37. api_bpm,
  38. api_wechatfile,
  39. api_configure_data,
  40. moment
  41. ) {
  42. $scope.langs = i18nService.getAllLangs();
  43. $scope.lang = "zh-cn";
  44. i18nService.setCurrentLang($scope.lang);
  45. // var loginUser = $rootScope.user;
  46. // $scope.xinzeng = false;
  47. // $scope.shanchu = false;
  48. // $scope.bianji = false;
  49. // $scope.zantingzhixing = false;
  50. // for (var i = 0; i < loginUser.menu.length; i++) {
  51. // if (loginUser.menu[i].link == "xunjianjihua_xinzeng") {
  52. // $scope.xinzeng = true
  53. // }
  54. // if (loginUser.menu[i].link == "xunjianjihua_shanchu") {
  55. // $scope.shanchu = true
  56. // }
  57. // if (loginUser.menu[i].link == "xunjianjihua_bianji") {
  58. // $scope.bianji = true
  59. // }
  60. // if (loginUser.menu[i].link == "xunjianjihua_zantingzhixing") {
  61. // $scope.zantingzhixing = true
  62. // }
  63. // }
  64. // 打印
  65. $scope.print = function () {
  66. ///.ui-grid-viewport
  67. var docHead = document.head.outerHTML; //.ui-grid-viewport
  68. console.log(docHead);
  69. var printContents = document.querySelector(".grid").outerHTML;
  70. console.log(printContents);
  71. var winAttr =
  72. "location=yes, statusbar=no, menubar=no, titlebar=no, toolbar=no,dependent=no, width=865, height=600, resizable=yes, screenX=200, screenY=200, personalbar=no, scrollbars=yes";
  73. var newWin = window.open("", "_blank", winAttr);
  74. var writeDoc = newWin.document;
  75. writeDoc.open();
  76. writeDoc.write(
  77. `<!doctype html>
  78. ${docHead}
  79. <body onLoad="window.print()">
  80. <style>
  81. .ui-grid-viewport{
  82. width:100%!important;
  83. height:100%!important;
  84. }
  85. .ui-grid-header-viewport{
  86. width:100%!important;
  87. }
  88. .xj_img {
  89. width: 50px;
  90. height: 100px;
  91. object-fit: cover;
  92. margin: 0 2px;
  93. cursor: pointer;
  94. }
  95. [ui-grid-cell] .ui-grid-cell-contents {
  96. display: flex;
  97. align-items: center;
  98. justify-content: center;
  99. white-space:normal;
  100. }
  101. [ui-grid-cell] .ui-grid-cell-contents .inspectPar {
  102. overflow: auto;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. white-space:normal;
  107. flex-wrap: wrap;
  108. height: 100%;
  109. }
  110. [ui-grid-cell] .ui-grid-cell-contents .inspectPar p{
  111. text-align: justify;
  112. width: 100%;
  113. margin: 0;
  114. }</style>
  115. ${printContents}
  116. </body>
  117. </html>`
  118. );
  119. writeDoc.close();
  120. newWin.focus();
  121. };
  122. //获取计划主题和批次号,级联
  123. $scope.titles = [];
  124. $scope.batchNos = [];
  125. $scope.isMask = true;
  126. $scope.queryList = { title: "", batchNo: "" };
  127. $scope.getInfo = function () {
  128. var postData = {
  129. idx: 0,
  130. sum: 9999,
  131. inspection: {},
  132. };
  133. api_bpm.fetchDataList("inspection", postData).then(function (result) {
  134. if (result.status == 200) {
  135. $scope.titles = result.list.map((v) => ({
  136. id: v.id,
  137. title: v.title,
  138. batchNos: v.batchNos,
  139. }));
  140. $scope.batchNos = [];
  141. }
  142. });
  143. };
  144. $scope.getInfo();
  145. //选择计划主题
  146. $scope.changeTitle = function () {
  147. console.log($scope.queryList.title);
  148. $scope.queryList.batchNo = "";
  149. if ($scope.queryList.title.batchNos) {
  150. $scope.batchNos = $scope.queryList.title.batchNos.map((v) => ({
  151. id: v,
  152. name: v,
  153. }));
  154. }
  155. };
  156. //选择计划主题和批次号,确定
  157. $scope.onClick = function () {
  158. if (!$scope.queryList.title || !$scope.queryList.batchNo) {
  159. SweetAlert.swal({
  160. title: "数据为空",
  161. text: "请填写必选项",
  162. type: "warning",
  163. });
  164. return;
  165. }
  166. $scope.isMask = false;
  167. $scope.fileData = {
  168. idx: 0,
  169. sum: 10,
  170. batchNo: $scope.queryList.batchNo.name,
  171. };
  172. $scope.refreshData("expand-right", $scope.fileData);
  173. };
  174. // ------------------------------------------------------------------
  175. var defaultFilterData = {
  176. idx: 0,
  177. sum: 10,
  178. };
  179. var inspectPlanParameter = {
  180. idx: 0,
  181. sum: 10,
  182. operation: "",
  183. status: "",
  184. inspection: {
  185. inspectionTypeDTO: {
  186. id: "",
  187. },
  188. },
  189. };
  190. //本地存储
  191. sessionStorage.inspectPlanParameter = JSON.stringify(inspectPlanParameter);
  192. $scope.gridOptions = {};
  193. $scope.gridOptions.data = "myData";
  194. $scope.gridOptions.enableColumnResizing = true;
  195. $scope.gridOptions.enableRowHeaderSelection = false;
  196. $scope.gridOptions.enableFiltering = false;
  197. $scope.gridOptions.enableGridMenu = true;
  198. $scope.gridOptions.enableRowSelection = true;
  199. $scope.gridOptions.showGridFooter = true;
  200. $scope.gridOptions.rowHeight = 252;
  201. $scope.gridOptions.showColumnFooter = false;
  202. $scope.gridOptions.useExternalFiltering = false;
  203. $scope.gridOptions.useExternalPagination = true;
  204. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  205. $scope.gridOptions.paginationPageSize = 10;
  206. $scope.gridOptions.multiSelect = true;
  207. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  208. //行鼠标悬浮变色功能
  209. // $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>';
  210. $scope.gridOptions.rowTemplate =
  211. '<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>';
  212. $scope.gridOptions.rowIdentity = function (row) {
  213. return row.id;
  214. };
  215. $scope.gridOptions.getRowIdentity = function (row) {
  216. return row.id;
  217. };
  218. $scope.gridOptions.columnDefs = [
  219. {
  220. name: "item",
  221. displayName: "序号",
  222. width: 50,
  223. enableFiltering: false,
  224. },
  225. {
  226. name: "startTime",
  227. displayName: "日期",
  228. width: 168,
  229. enableFiltering: true,
  230. cellTemplate:
  231. '<div class="ui-grid-cell-contents">{{row.entity.startTime | date:"yyyy-MM-dd HH:mm:ss"}}</div>',
  232. },
  233. {
  234. name: "type",
  235. displayName: "巡检类型",
  236. width: "17%",
  237. enableFiltering: false,
  238. },
  239. {
  240. name: "inspectItem",
  241. displayName: "巡检项",
  242. width: "25%",
  243. enableFiltering: false,
  244. cellTemplate: `<div class="ui-grid-cell-contents">
  245. <div class="inspectPar">
  246. <p ng-repeat="item in row.entity.xj_items">{{item.name}}:{{item.value=="false"?"异常":"正常"}}</p>
  247. </div>
  248. </div>`,
  249. },
  250. {
  251. name: "pic",
  252. displayName: "巡检图片",
  253. width: "18%",
  254. enableFiltering: false,
  255. cellTemplate:
  256. '<div class="ui-grid-cell-contents"><img class="xj_img" ng-click="grid.appScope.seePic(row.entity,imageurl)" ng-repeat="(index,imageurl) in row.entity.filePath" ng-src="{{imageurl}}"/></div>',
  257. },
  258. // {
  259. // name: "pic1",
  260. // displayName: "巡检图片",
  261. // width: "18%",
  262. // enableFiltering: false,
  263. // cellTemplate:
  264. // '<div class="ui-grid-cell-contents"><img class="xj_img" ng-click="grid.appScope.seePic(row.entity,index)" ng-repeat="(item,index) in [1,2,3]" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp2.itc.cn%2Fq_70%2Fimages03%2F20201101%2F75417504ddc843d78610d1cb8dd9c402.jpeg&refer=http%3A%2F%2Fp2.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1649583898&t=1ead2b8808f10e3da9d6864543d90bce"/></div>',
  265. // },
  266. {
  267. name: "model.descriptionTextarea",
  268. displayName: "整改意见",
  269. width: "18%",
  270. enableFiltering: false,
  271. cellTemplate:
  272. '<div class="ui-grid-cell-contents"><div class="inspectPar"><p>{{row.entity.model.descriptionTextarea}}</p></div></div>',
  273. },
  274. {
  275. name: "userName",
  276. displayName: "巡检人",
  277. width: "12%",
  278. enableFiltering: false,
  279. },
  280. // {
  281. // minWidth: "230",
  282. // name: "操作",
  283. // enableFiltering: false,
  284. // cellTemplate:
  285. // '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  286. // // '<a ng-click="grid.appScope.seeFunction(row.entity)" class="bianjifont">查看</a>' +
  287. // // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" ng-show="{{(row.entity.status.name==\'正常\'||row.entity.status.name==\'停止\')&&grid.appScope.bianji}}" class="bianjifont">编辑</a>' +
  288. // // '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'正常\'&&grid.appScope.zantingzhixing}}" class="bianjifont">执行中</a>' +
  289. // // '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'停止\'&&grid.appScope.zantingzhixing}}" class="bianjifont">暂停中</a>' +
  290. // "</div>",
  291. // },
  292. ];
  293. $scope.selected = {
  294. items: [],
  295. };
  296. $scope.gridOptions.onRegisterApi = function (gridApi) {
  297. //导入gridApi对象
  298. $scope.gridApi = gridApi;
  299. //分页选项
  300. // gridApi.pagination.on.paginationChanged(
  301. // $scope,
  302. // function (newPage, pageSize) {
  303. // var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  304. // var filtersData = {};
  305. // filtersData.idx = newPage - 1;
  306. // filtersData.sum = pageSize;
  307. // $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  308. // // console.log(pp);
  309. // filterData.idx = $scope.pageNum;
  310. // $scope.fileData.idx = newPage - 1;
  311. // $scope.fileData.sum = pageSize;
  312. // sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  313. // $scope.refreshData("expand-right", $scope.fileData);
  314. // }
  315. // );
  316. //跳转到查看列表
  317. $scope.seePic = function (data, imageurl) {
  318. console.log(data, imageurl);
  319. var i = imageurl.lastIndexOf("/");
  320. var title = imageurl.slice(i + 1).split(".")[0];
  321. $modal.open({
  322. backdrop: false,
  323. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  324. controller: function ($scope, scope, $modalInstance) {
  325. $scope.title = title;
  326. $scope.imageurl = imageurl;
  327. $scope.cancel = function () {
  328. $modalInstance.dismiss("cancel");
  329. };
  330. },
  331. resolve: {
  332. scope: function () {
  333. return $scope;
  334. },
  335. },
  336. });
  337. };
  338. //勾选行事件
  339. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  340. if (data.isSelected) {
  341. $scope.selected.items.push(data.entity);
  342. } else {
  343. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  344. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  345. //angular.forEach(objs, function(data,index,array)
  346. angular.forEach(
  347. $scope.selected.items,
  348. function (ObjIndex, index, destObj) {
  349. // console.log(ObjIndex);
  350. // console.log(index);
  351. // console.log(destObj);
  352. if (ObjIndex.id == data.entity.id) {
  353. destObj.splice(index, 1);
  354. }
  355. }
  356. );
  357. }
  358. });
  359. //批量全选
  360. gridApi.selection.on.rowSelectionChangedBatch(
  361. $scope,
  362. function (rows, event) {
  363. // if ($scope.selected.items.length != 0) {
  364. // $scope.selected.items = [];
  365. angular.forEach(rows, function (ObjIndex, index, destObj) {
  366. if (ObjIndex.isSelected) {
  367. $scope.selected.items.push(ObjIndex.entity);
  368. } else {
  369. $scope.selected.items = [];
  370. // $scope.selected.items.splice(index, 1);
  371. }
  372. });
  373. // } else {
  374. // }
  375. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  376. // if ($scope.selected.items.length == 0) {
  377. // $scope.selected.items = $scope.mySelectedRows;
  378. // } else if ($scope.mySelectedRows.length == 0) {
  379. // for (var i = 0; i < $scope.selected.items.length; i++) {
  380. // for (var j = 0; j < rows.length; j++) {
  381. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  382. // $scope.selected.items.splice(i, 1);
  383. // }
  384. // }
  385. // }
  386. // } else {
  387. // angular.forEach($scope.mySelectedRows, function(item) {
  388. // $scope.selected.items.push(item);
  389. // });
  390. // }
  391. }
  392. );
  393. //列过滤事件
  394. gridApi.core.on.filterChanged($scope, function () {
  395. var grid = this.grid;
  396. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  397. angular.forEach(grid.columns, function (item) {
  398. if (item.enableFiltering) {
  399. if (
  400. angular.isDefined(item.filters[0].term) &&
  401. item.filters[0].term != ""
  402. ) {
  403. if (angular.isUndefined(filterData["inspection"])) {
  404. filterData["inspection"] = {};
  405. }
  406. filterData["inspection"]["title"] = item.filters[0].term;
  407. }
  408. }
  409. });
  410. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  411. $scope.refreshData("expand-right", filterData);
  412. });
  413. };
  414. //数据刷新
  415. $scope.refreshData = function (style, filterData) {
  416. $scope.ldloading[style.replace("-", "_")] = true;
  417. if (angular.isUndefined(filterData)) {
  418. filterData = defaultFilterData;
  419. }
  420. $scope.myData = [];
  421. api_bpm.report(filterData).then(
  422. function (data) {
  423. var myData = Restangular.stripRestangular(data);
  424. $scope.gridOptions.totalItems = myData.totalNum;
  425. if (angular.isArray(myData.data)) {
  426. $scope.myData = myData.data;
  427. for (var i = 0; i < $scope.myData.length; i++) {
  428. $scope.myData[i]["item"] =
  429. i + 1 + filterData.idx * filterData.sum;
  430. }
  431. for (var i = 0; i < $scope.myData.length; i++) {
  432. //处理日期
  433. $scope.myData[i].startTime = new Date($scope.myData[i].startTime);
  434. // 处理图片
  435. if ($scope.myData[i].filePath) {
  436. $scope.myData[i].filePath = $scope.myData[i].filePath
  437. .split(",")
  438. .map((v) => imgBaseUrl + "/file" + v);
  439. } else {
  440. $scope.myData[i].filePath = [];
  441. }
  442. //巡检项cnm
  443. $scope.myData[i].xj_items = $scope.myData[i].fields
  444. .filter((v) => {
  445. v.key = (v.key || "").toString();
  446. return v.key.indexOf("sdCheckEnable") > -1;
  447. })
  448. .map((v) => ({
  449. key: v.key,
  450. name: v.templateOptions.label,
  451. value: $scope.myData[i].model[v.key],
  452. }));
  453. }
  454. console.log($scope.myData);
  455. } else {
  456. SweetAlert.swal({
  457. title: "数据为空",
  458. text: myData.data,
  459. type: "warning",
  460. });
  461. }
  462. $scope.ldloading[style.replace("-", "_")] = false;
  463. },
  464. function () {
  465. $scope.ldloading[style.replace("-", "_")] = false;
  466. }
  467. );
  468. };
  469. $scope.refreshData2 = function (style, filterData) {
  470. $scope.ldloading[style.replace("-", "_")] = true;
  471. if (angular.isUndefined(filterData)) {
  472. filterData = defaultFilterData;
  473. }
  474. // $scope.myData = [];
  475. api_bpm.report(filterData).then(
  476. function (data) {
  477. var myData = Restangular.stripRestangular(data);
  478. $scope.gridOptions.totalItems = myData.totalNum;
  479. if (angular.isArray(myData.list)) {
  480. $scope.myData = myData.list;
  481. for (var i = 0; i < $scope.myData.length; i++) {
  482. $scope.myData[i]["item"] =
  483. i + 1 + filterData.idx * filterData.sum;
  484. }
  485. for (var i = 0; i < $scope.myData.length; i++) {
  486. if ($scope.myData[i].status == "正常") {
  487. $scope.myData[i].style = "fa fa-play";
  488. } else if ($scope.myData[i].status == "停止") {
  489. $scope.myData[i].style = "fa fa-pause";
  490. }
  491. }
  492. } else {
  493. SweetAlert.swal({
  494. title: "数据为空",
  495. text: myData.data,
  496. type: "warning",
  497. });
  498. }
  499. $scope.ldloading[style.replace("-", "_")] = false;
  500. },
  501. function () {
  502. $scope.ldloading[style.replace("-", "_")] = false;
  503. }
  504. );
  505. };
  506. $scope.ldloading = {};
  507. // $scope.fileData = {
  508. // idx: 0,
  509. // sum: 10,
  510. // inspection: {},
  511. // };
  512. // $scope.refreshData("expand-right", $scope.fileData);
  513. // $scope.timer = $interval(function () {
  514. // $scope.refreshData2("expand-right", $scope.fileData);
  515. // }, $rootScope.refreshTime);
  516. // $scope.$on("$destroy", function () {
  517. // $interval.cancel($scope.timer);
  518. // });
  519. },
  520. ]);