inspectReportCtrl.js 19 KB

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