inspectReportCtrl.js 18 KB

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