inspectReportCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. },
  310. resolve: {
  311. scope: function () {
  312. return $scope;
  313. },
  314. },
  315. });
  316. };
  317. //勾选行事件
  318. gridApi.selection.on.rowSelectionChanged($scope, function (data) {
  319. if (data.isSelected) {
  320. $scope.selected.items.push(data.entity);
  321. } else {
  322. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  323. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  324. //angular.forEach(objs, function(data,index,array)
  325. angular.forEach(
  326. $scope.selected.items,
  327. function (ObjIndex, index, destObj) {
  328. // console.log(ObjIndex);
  329. // console.log(index);
  330. // console.log(destObj);
  331. if (ObjIndex.id == data.entity.id) {
  332. destObj.splice(index, 1);
  333. }
  334. }
  335. );
  336. }
  337. });
  338. //批量全选
  339. gridApi.selection.on.rowSelectionChangedBatch(
  340. $scope,
  341. function (rows, event) {
  342. // if ($scope.selected.items.length != 0) {
  343. // $scope.selected.items = [];
  344. angular.forEach(rows, function (ObjIndex, index, destObj) {
  345. if (ObjIndex.isSelected) {
  346. $scope.selected.items.push(ObjIndex.entity);
  347. } else {
  348. $scope.selected.items = [];
  349. // $scope.selected.items.splice(index, 1);
  350. }
  351. });
  352. // } else {
  353. // }
  354. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  355. // if ($scope.selected.items.length == 0) {
  356. // $scope.selected.items = $scope.mySelectedRows;
  357. // } else if ($scope.mySelectedRows.length == 0) {
  358. // for (var i = 0; i < $scope.selected.items.length; i++) {
  359. // for (var j = 0; j < rows.length; j++) {
  360. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  361. // $scope.selected.items.splice(i, 1);
  362. // }
  363. // }
  364. // }
  365. // } else {
  366. // angular.forEach($scope.mySelectedRows, function(item) {
  367. // $scope.selected.items.push(item);
  368. // });
  369. // }
  370. }
  371. );
  372. //列过滤事件
  373. gridApi.core.on.filterChanged($scope, function () {
  374. var grid = this.grid;
  375. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  376. angular.forEach(grid.columns, function (item) {
  377. if (item.enableFiltering) {
  378. if (
  379. angular.isDefined(item.filters[0].term) &&
  380. item.filters[0].term != ""
  381. ) {
  382. if (angular.isUndefined(filterData["inspection"])) {
  383. filterData["inspection"] = {};
  384. }
  385. filterData["inspection"]["title"] = item.filters[0].term;
  386. }
  387. }
  388. });
  389. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  390. $scope.refreshData("expand-right", filterData);
  391. });
  392. };
  393. //数据刷新
  394. $scope.refreshData = function (style, filterData) {
  395. $scope.ldloading[style.replace("-", "_")] = true;
  396. if (angular.isUndefined(filterData)) {
  397. filterData = defaultFilterData;
  398. }
  399. $scope.myData = [];
  400. api_bpm.report(filterData).then(
  401. function (data) {
  402. var myData = Restangular.stripRestangular(data);
  403. $scope.gridOptions.totalItems = myData.totalNum;
  404. if (angular.isArray(myData.data)) {
  405. $scope.myData = myData.data;
  406. for (var i = 0; i < $scope.myData.length; i++) {
  407. $scope.myData[i]["item"] =
  408. i + 1 + filterData.idx * filterData.sum;
  409. }
  410. for (var i = 0; i < $scope.myData.length; i++) {
  411. var descriptionTextareaStr = '';
  412. // 处理整改意见
  413. if($scope.myData[i].descriptionTextarea){
  414. for(var key in $scope.myData[i].descriptionTextarea){
  415. descriptionTextareaStr += $scope.myData[i].descriptionTextarea[key] + '<br>';
  416. }
  417. $scope.myData[i].descriptionTextarea = $sce.trustAsHtml(descriptionTextareaStr);
  418. }
  419. // 处理巡检人
  420. $scope.myData[i].userName = $scope.myData[i].userName || [];
  421. var userNameStr = ''
  422. $scope.myData[i].userName.forEach((v, i)=>{
  423. userNameStr += v + '<br>';
  424. })
  425. $scope.myData[i].userName = $sce.trustAsHtml(userNameStr);
  426. // 处理日期
  427. $scope.myData[i].startTime = new Date($scope.myData[i].startTime);
  428. // 处理图片
  429. // if ($scope.myData[i].filePath) {
  430. // $scope.myData[i].filePath = $scope.myData[i].filePath
  431. // .split(",")
  432. // .map((v) => imgBaseUrl + "/file" + v);
  433. // } else {
  434. // $scope.myData[i].filePath = [];
  435. // }
  436. // ----------------
  437. var descriptionTextareaStr = '';
  438. if($scope.myData[i].filePath){
  439. for(var key in $scope.myData[i].filePath){
  440. $scope.myData[i].filePath[key] = $scope.myData[i].filePath[key].split(",").map((v) => imgBaseUrl + "/file" + v);
  441. }
  442. }
  443. //巡检项
  444. $scope.myData[i].xj_items = $scope.myData[i].fields
  445. .filter((v) => {
  446. v.key = (v.key || "").toString();
  447. return v.key.indexOf("sdCheckEnable") > -1;
  448. })
  449. .map((v) => ({
  450. key: v.key,
  451. name: v.templateOptions.label,
  452. value: $scope.myData[i].model[v.key],
  453. }));
  454. }
  455. console.log($scope.myData);
  456. } else {
  457. SweetAlert.swal({
  458. title: "数据为空",
  459. text: myData.data,
  460. type: "warning",
  461. });
  462. }
  463. $scope.ldloading[style.replace("-", "_")] = false;
  464. },
  465. function () {
  466. $scope.ldloading[style.replace("-", "_")] = false;
  467. }
  468. );
  469. };
  470. $scope.refreshData2 = function (style, filterData) {
  471. $scope.ldloading[style.replace("-", "_")] = true;
  472. if (angular.isUndefined(filterData)) {
  473. filterData = defaultFilterData;
  474. }
  475. // $scope.myData = [];
  476. api_bpm.report(filterData).then(
  477. function (data) {
  478. var myData = Restangular.stripRestangular(data);
  479. $scope.gridOptions.totalItems = myData.totalNum;
  480. if (angular.isArray(myData.list)) {
  481. $scope.myData = myData.list;
  482. for (var i = 0; i < $scope.myData.length; i++) {
  483. $scope.myData[i]["item"] =
  484. i + 1 + filterData.idx * filterData.sum;
  485. }
  486. for (var i = 0; i < $scope.myData.length; i++) {
  487. if ($scope.myData[i].status == "正常") {
  488. $scope.myData[i].style = "fa fa-play";
  489. } else if ($scope.myData[i].status == "停止") {
  490. $scope.myData[i].style = "fa fa-pause";
  491. }
  492. }
  493. } else {
  494. SweetAlert.swal({
  495. title: "数据为空",
  496. text: myData.data,
  497. type: "warning",
  498. });
  499. }
  500. $scope.ldloading[style.replace("-", "_")] = false;
  501. },
  502. function () {
  503. $scope.ldloading[style.replace("-", "_")] = false;
  504. }
  505. );
  506. };
  507. $scope.ldloading = {};
  508. // $scope.fileData = {
  509. // idx: 0,
  510. // sum: 10,
  511. // inspection: {},
  512. // };
  513. // $scope.refreshData("expand-right", $scope.fileData);
  514. // $scope.timer = $interval(function () {
  515. // $scope.refreshData2("expand-right", $scope.fileData);
  516. // }, $rootScope.refreshTime);
  517. // $scope.$on("$destroy", function () {
  518. // $interval.cancel($scope.timer);
  519. // });
  520. },
  521. ]);