inspectReportCtrl.js 20 KB

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