inspectListCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('inspectListCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", "api_configure_data", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data, api_configure_data) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. $scope.chuli = false;
  11. for (var i = 0; i < loginUser.menu.length; i++) {
  12. if (loginUser.menu[i].link == "xunjianliebiao_chuli") {
  13. $scope.chuli = true
  14. }
  15. }
  16. var defaultFilterData = {
  17. "assignee": loginUser.id,
  18. // "assignee": "1",
  19. "idx": 0,
  20. "sum": 10,
  21. "status": '',
  22. "searchType": "todo"
  23. };
  24. var inspectListParameter = {
  25. "assignee": loginUser.id,
  26. // "assignee": "1",
  27. "idx": 0,
  28. "sum": 10,
  29. "status": ''
  30. };
  31. // $scope.memoryfilterData = {
  32. // "idx": 0,
  33. // "sum": 10
  34. // }
  35. //本地存储
  36. sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
  37. //ui-grid设置
  38. $scope.gridOptions = {};
  39. $scope.gridOptions.data = 'myData';
  40. $scope.gridOptions.enableColumnResizing = true;
  41. $scope.gridOptions.enableFiltering = true;
  42. $scope.gridOptions.enableGridMenu = true;
  43. $scope.gridOptions.enableRowSelection = true;
  44. $scope.gridOptions.showGridFooter = true;
  45. $scope.gridOptions.showColumnFooter = false;
  46. $scope.gridOptions.fastWatch = true;
  47. $scope.gridOptions.useExternalFiltering = true;
  48. $scope.gridOptions.useExternalPagination = true;
  49. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  50. $scope.gridOptions.paginationPageSize = 10;
  51. $scope.gridOptions.multiSelect = true;
  52. // $scope.gridOptions.rowTemplate = '<div style="background: red"><a>123</a></div';
  53. // $scope.gridOptions.rowTemplate = "<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>";
  54. $scope.gridOptions.rowIdentity = function (row) {
  55. return row.id;
  56. };
  57. $scope.gridOptions.getRowIdentity = function (row) {
  58. return row.id;
  59. };
  60. $scope.transferColor = function (item) {
  61. var color = "icon iconfont icon-zhengchang greenfont";
  62. if (item && item.colourInfo) {
  63. if (item.colourInfo.id == 1) {
  64. color = "icon iconfont icon-yiyuqi redfont";
  65. } else if (item.colourInfo.id == 2) {
  66. color = "iconfont icon-yuqixinxiu yellofont";
  67. }
  68. } else {
  69. // color = "white";
  70. }
  71. return color;
  72. }
  73. $scope.transfertip = function (item) {
  74. var tip = "正常";
  75. if (item && item.colourInfo) {
  76. if (item.colourInfo.id == 1) {
  77. tip = "逾期";
  78. } else if (item.colourInfo.id == 2) {
  79. tip = "即将逾期";
  80. }
  81. } else {
  82. // color = "white";
  83. }
  84. return tip;
  85. }
  86. $scope.gridOptions.columnDefs = [{
  87. name: 'id',
  88. displayName: '',
  89. width: 40,
  90. enableFiltering: false,
  91. cellTemplate: '<div>' +
  92. '<div class="ui-grid-cell-contents" tooltip={{grid.appScope.transfertip(row.entity.ruleColour)}} tooltip-placement="right"><i style="font-size: 18px !important;" class="{{grid.appScope.transferColor(row.entity.ruleColour)}}"></i></div></div>'
  93. },
  94. {
  95. name: 'sign',
  96. displayName: '单号',
  97. width: '12%',
  98. minWidth: 120,
  99. enableFiltering: false
  100. },
  101. {
  102. name: 'inspection.inspectionType.type',
  103. displayName: '巡检分类',
  104. width: '12%',
  105. minWidth: 120,
  106. enableFiltering: false
  107. },
  108. {
  109. name: 'inspection.title',
  110. displayName: '计划主题',
  111. width: '12%',
  112. minWidth: 120,
  113. enableFiltering: false
  114. },
  115. {
  116. name: 'inspection.createUser.name',
  117. displayName: '创建人',
  118. width: '8%',
  119. minWidth: 80,
  120. enableFiltering: false
  121. },
  122. {
  123. name: 'stateName',
  124. displayName: '状态',
  125. width: '8%',
  126. minWidth: 80,
  127. enableFiltering: false
  128. },
  129. {
  130. name: 'inspection.executeUser.name',
  131. displayName: '处理人',
  132. width: '8%',
  133. minWidth: 80,
  134. enableFiltering: false
  135. },
  136. {
  137. name: 'startDate',
  138. displayName: '开始时间',
  139. width: '15%',
  140. minWidth: 160,
  141. enableFiltering: false,
  142. cellTemplate: '<div>' +
  143. '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.startDate)}}</div>' +
  144. '</div>'
  145. },
  146. {
  147. name: 'overdueTime',
  148. displayName: '逾期时间',
  149. width: '15%',
  150. width: 160,
  151. enableFiltering: false,
  152. cellTemplate: '<div>' +
  153. '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.overdueTime)}}</div>' +
  154. '</div>'
  155. },
  156. {
  157. name: '操作',
  158. minWidth: '150',
  159. enableFiltering: false,
  160. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  161. '<a ng-click="grid.appScope.lookFunction(row.entity)" tooltip="查看" tooltip-placement="right" class="bianjifont">查看</a>' +
  162. '<a ng-show="{{grid.appScope.showChuli(row.entity)&&grid.appScope.chuli}}" ng-click="grid.appScope.selectRowFunction(row.entity)" class="bianjifont">处理</a>' +
  163. // '<a ng-show="{{!row.entity.state==1}}" ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"/></a>' +
  164. '</div>'
  165. },
  166. ];
  167. // $scope.addData = function() {
  168. // $state.go('app.inspection.inspectList.editor', {
  169. // formKey: 'inspectionform',
  170. // service: 'api_bpm_data'
  171. // });
  172. // }
  173. $scope.transferTime = function (time) {
  174. return moment(time).format('YYYY-MM-DD HH:mm');
  175. }
  176. $scope.showChuli=function(data){
  177. if(data.processUser.id==loginUser.id&&data.stateName=="执行中"){
  178. return true
  179. } else {
  180. return false
  181. }
  182. }
  183. $scope.selectRowFunction = function (data) {
  184. var filedata = {
  185. model: {
  186. inspectionProcessActual: data
  187. }
  188. }
  189. $state.go('app.inspection.inspectListEditor', {
  190. "taskId": data.taskId,
  191. 'dataId': data.id,
  192. "processInstanceId": data.processInstanceId,
  193. "pdKey": data.processKey,
  194. "formUiEdit": data.inspection.inspectionType.formUiEdit,
  195. // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  196. "model": JSON.stringify(filedata)
  197. });
  198. };
  199. $scope.lookFunction = function (data) {
  200. var filedata = {
  201. model: {
  202. inspectionProcessActual: data
  203. }
  204. // model:data
  205. }
  206. $state.go('app.inspection.inspectListdetail', {
  207. "formKey": data.inspection.inspectionType.formUiName,
  208. "dataId": data.id,
  209. "taskId": data.taskId,
  210. "processInstanceId": data.processInstanceId,
  211. "pdKey": data.processKey,
  212. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  213. "formUiName": data.inspection.inspectionType.formUiName,
  214. "model": JSON.stringify(filedata)
  215. });
  216. };
  217. $scope.model = {
  218. "assignee": JSON.parse(sessionStorage.inspectListParameter).assignee,
  219. "idx": 0,
  220. "sum": 10,
  221. "searchType": "todo",
  222. "inspectionProcessActual": {
  223. "inspection": {}
  224. }
  225. };
  226. // $scope.removeData = function() {
  227. // // var rmvList = [$scope.selected.items.id]
  228. // var rmvList = [];
  229. // angular.forEach($scope.selected.items, function(item) {
  230. // rmvList.push(item.id);
  231. // });
  232. // if (rmvList.length > 0) {
  233. // api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
  234. // if (response.status == 200) {
  235. // SweetAlert.swal({
  236. // title: "删除成功!",
  237. // type: "success",
  238. // confirmButtonColor: "#007AFF"
  239. // }, function() {
  240. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  241. // $scope.selected = {
  242. // items: []
  243. // };
  244. // });
  245. // } else {
  246. // SweetAlert.swal({
  247. // title: "操作异常!",
  248. // text: "系统异常,请稍后重试,或者联系管理员!",
  249. // type: "error"
  250. // });
  251. // }
  252. // })
  253. // }
  254. // }
  255. $scope.selected = {
  256. items: []
  257. }
  258. $scope.editted = {
  259. items: []
  260. }
  261. $scope.jry_idx = 0;
  262. $scope.jry_sum = 10;
  263. //分页控制
  264. $scope.gridOptions.onRegisterApi = function (gridApi) {
  265. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  266. console.log("ok");
  267. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  268. filterData.idx = newPage - 1;
  269. filterData.sum = pageSize;
  270. $scope.jry_idx = newPage - 1;
  271. $scope.jry_sum = pageSize;
  272. $scope.model.idx = newPage - 1;
  273. $scope.model.sum = pageSize;
  274. $scope.refreshData('expand-right', $scope.model);
  275. });
  276. // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  277. // data.grid.appScope.selected.items = data.entity
  278. // console.log(data);
  279. // });
  280. }
  281. // var data = JSON.parse(sessionStorage.inspectListParameter);
  282. // sessionStorage.inspectListParameter = JSON.stringify(data);
  283. $scope.ldloading = {};
  284. $scope.statusData = {};
  285. //搜索事件
  286. $scope.searchinspectlist = function (item) {
  287. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  288. // console.log(filterData);
  289. // if (item.type) {
  290. // filterData.inspection = { 'inspectionTypeDTO': { 'id':item.type.id}};
  291. // }
  292. // if (item.title) {
  293. // filterData.inspection = { 'title': item.title};
  294. // }
  295. $scope.model.idx = $scope.jry_idx;
  296. $scope.model.sum = $scope.jry_sum;
  297. if ($scope.model.inspectionProcessActual.inspectionType) {
  298. $scope.model.inspectionTypeId = $scope.model.inspectionProcessActual.inspectionType.id;
  299. delete $scope.model.inspectionProcessActual.inspectionType
  300. }
  301. if ($scope.statusData.state) {
  302. $scope.model.inspectionProcessActual.state = $scope.statusData.state.state
  303. }
  304. // filterData.status = item;
  305. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  306. $scope.refreshData('expand-right', $scope.model);
  307. };
  308. $scope.clean = function () {
  309. delete $scope.model.inspectionProcessActual.inspection.title;
  310. delete $scope.model.inspectionProcessActual.inspectionType;
  311. delete $scope.model.inspectionTypeId;
  312. delete $scope.model.inspectionProcessActual.inspection.executeUser;
  313. delete $scope.model.inspectionProcessActual.inspection.createUser;
  314. delete $scope.model.inspectionProcessActual.state;
  315. $scope.statusData = {};
  316. $scope.try_async_load();
  317. $scope.refreshData('expand-right', $scope.model);
  318. }
  319. //树形控件点击事件
  320. $scope.my_tree_handler = function (branch) {
  321. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  322. filterData.status = branch.id;
  323. // if (filterData.inspectionProcessActual) {
  324. // filterData.inspectionProcessActual.inspectionTypeId = branch.id;
  325. // } else {
  326. // filterData = angular.extend(filterData, {
  327. // "inspectionProcessActual": {
  328. // "inspectionTypeId": branch.id
  329. // }
  330. // })
  331. // }
  332. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  333. $scope.refreshData('expand-right', filterData);
  334. };
  335. //搜索栏点击事件
  336. $scope.searchstate = 'todo';
  337. $scope.onChange = function (searchType) {
  338. $scope.searchstate = searchType;
  339. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  340. filterData.searchType = searchType;
  341. $scope.model.searchType = searchType;
  342. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  343. $scope.refreshData('expand-right', $scope.model);
  344. }
  345. $scope.reload = function () {
  346. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  347. $scope.refreshData('expand-right', filterData);
  348. }
  349. $scope.refreshData = function (style, filterData) {
  350. $scope.ldloading[style.replace('-', '_')] = true;
  351. if (angular.isUndefined(filterData)) {
  352. filterData = defaultFilterData;
  353. }
  354. $scope.myData = [];
  355. $scope.memoryfilterData = filterData;
  356. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function (data) {
  357. var myData = Restangular.stripRestangular(data);
  358. $scope.gridOptions.totalItems = myData.resultCount;
  359. if (angular.isArray(myData.data)) {
  360. $scope.myData = myData.data;
  361. for (var i = 0; i < $scope.myData.length; i++) {
  362. //添加序号
  363. $scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
  364. }
  365. $scope.ldloading[style.replace('-', '_')] = false;
  366. } else {
  367. $scope.ldloading[style.replace('-', '_')] = false;
  368. SweetAlert.swal({
  369. title: "数据为空",
  370. text: myData.data,
  371. type: "warning"
  372. });
  373. }
  374. }, function () {
  375. $scope.ldloading[style.replace('-', '_')] = false;
  376. });
  377. };
  378. $scope.refreshData2 = function (style, filterData) {
  379. $scope.ldloading[style.replace('-', '_')] = true;
  380. if (angular.isUndefined(filterData)) {
  381. filterData = defaultFilterData;
  382. }
  383. // $scope.myData = [];
  384. $scope.memoryfilterData = filterData;
  385. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function (data) {
  386. var myData = Restangular.stripRestangular(data);
  387. $scope.gridOptions.totalItems = myData.resultCount;
  388. if (angular.isArray(myData.data)) {
  389. $scope.myData = myData.data;
  390. for (var i = 0; i < $scope.myData.length; i++) {
  391. //添加序号
  392. $scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
  393. }
  394. $scope.ldloading[style.replace('-', '_')] = false;
  395. } else {
  396. $scope.ldloading[style.replace('-', '_')] = false;
  397. SweetAlert.swal({
  398. title: "数据为空",
  399. text: myData.data,
  400. type: "warning"
  401. });
  402. }
  403. }, function () {
  404. $scope.ldloading[style.replace('-', '_')] = false;
  405. });
  406. };
  407. $scope.inspecttype = {};
  408. // 获取处理人
  409. $scope.getExecuteUser = function () {
  410. api_configure_data.fetchDataList("user", {
  411. "idx": 0,
  412. "sum": 1000,
  413. "user": {
  414. "roledata": {
  415. "rolecode": "inspectman"
  416. },
  417. "simple": true
  418. }
  419. }).then(function (res) {
  420. $scope.executeUserData = res.list
  421. })
  422. }
  423. $scope.getExecuteUser()
  424. $scope.statusData = [{
  425. "name": "执行中",
  426. "state": 0
  427. },
  428. {
  429. "name": "已完成",
  430. "state": 1
  431. }
  432. ]
  433. // 获取创建人
  434. $scope.getCreateUser = function () {
  435. api_configure_data.fetchDataList("user", {
  436. "idx": 0,
  437. "sum": 1000,
  438. "user":{
  439. "simple": true
  440. }
  441. }).then(function (res) {
  442. $scope.createUserData = res.list
  443. })
  444. }
  445. $scope.getCreateUser()
  446. $scope.open = function ($event) {
  447. $event.preventDefault();
  448. $event.stopPropagation();
  449. $scope.opened = !$scope.opened;
  450. };
  451. $scope.endOpen = function ($event) {
  452. $event.preventDefault();
  453. $event.stopPropagation();
  454. $scope.startOpened = false;
  455. $scope.endOpened = !$scope.endOpened;
  456. };
  457. $scope.startOpen = function ($event) {
  458. $event.preventDefault();
  459. $event.stopPropagation();
  460. $scope.endOpened = false;
  461. $scope.startOpened = !$scope.startOpened;
  462. };
  463. //树形控件加载
  464. $scope.my_tree = {};
  465. $scope.try_async_load = function () {
  466. $scope.my_data = [];
  467. $scope.doing_async = true;
  468. api_bpm_data.fetchDataList('inspectionType', {
  469. "idx": 0,
  470. "sum": 1000
  471. }).then(function (response) {
  472. if (response.status == 200) {
  473. var data = response.list;
  474. var objects = [];
  475. for (var i = 0; i < data.length; i++) {
  476. var object = {};
  477. object.id = data[i].id;
  478. if (data[i].parent && data[i].parent.id != 0) {
  479. object.parent = data[i].parent.id;
  480. }
  481. object.label = data[i].type;
  482. objects.push(object);
  483. }
  484. $scope.my_data = convertParentToChildList(objects);
  485. $scope.tree_data = angular.copy($scope.my_data);
  486. if ($scope.my_data.length > 0) {
  487. $scope.doing_async = false;
  488. }
  489. // return $scope.my_tree.expand_all()
  490. } else {
  491. SweetAlert.swal({
  492. title: "系统错误!",
  493. text: "请刷新重试!",
  494. type: "error"
  495. });
  496. }
  497. });
  498. };
  499. function convertListToTree(data, treeMap) {
  500. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  501. var root = null; //Initially set our loop to null
  502. var parentNode = null;
  503. //loop over data
  504. for (var i = 0; i < data.length; i++) {
  505. var datum = data[i];
  506. //each node will have children, so let's give it a "children" poperty
  507. datum.children = [];
  508. //add an entry for this node to the map so that any future children can
  509. //lookup the parent
  510. idToNodeMap[datum.id] = datum;
  511. //Does this node have a parent?
  512. if (typeof datum.parent === "undefined" || datum.parent == null) {
  513. //Doesn't look like it, so this node is the root of the tree
  514. root = datum;
  515. treeMap[datum.id] = root;
  516. } else {
  517. //This node has a parent, so let's look it up using the id
  518. parentNode = idToNodeMap[datum.parent];
  519. //We don't need this property, so let's delete it.
  520. delete datum.parent;
  521. //Let's add the current node as a child of the parent node.
  522. parentNode.children.push(datum);
  523. }
  524. }
  525. return root;
  526. }
  527. function convertParentToChildList(data) {
  528. var treeMap = {};
  529. var list = [];
  530. convertListToTree(data, treeMap);
  531. angular.forEach(treeMap, function (item) {
  532. list.push(item);
  533. });
  534. return list;
  535. }
  536. $scope.refreshData('expand-right', defaultFilterData);
  537. $scope.try_async_load();
  538. $scope.timer = $interval(function () {
  539. $scope.refreshData2('expand-right', $scope.model);
  540. }, $rootScope.refreshTime);
  541. $scope.$on('$destroy', function () {
  542. $interval.cancel($scope.timer)
  543. })
  544. }]);