inspectReportCtrl.js 18 KB

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