inspectReportCtrl.js 20 KB

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