inspectReportCtrl.js 20 KB

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