inspectListCtrl.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("inspectListCtrl", [
  6. "$rootScope",
  7. "$scope",
  8. "$state",
  9. "$timeout",
  10. "$interval",
  11. "$modal",
  12. "SweetAlert",
  13. "i18nService",
  14. "uiGridConstants",
  15. "uiGridGroupingConstants",
  16. "Restangular",
  17. "api_bpm_schedule",
  18. "api_bpm_data",
  19. "api_configure_data",
  20. "api_bpm",
  21. "api_user_data",
  22. function (
  23. $rootScope,
  24. $scope,
  25. $state,
  26. $timeout,
  27. $interval,
  28. $modal,
  29. SweetAlert,
  30. i18nService,
  31. uiGridConstants,
  32. uiGridGroupingConstants,
  33. Restangular,
  34. api_bpm_schedule,
  35. api_bpm_data,
  36. api_configure_data,
  37. api_bpm,
  38. api_user_data
  39. ) {
  40. $scope.langs = i18nService.getAllLangs();
  41. $scope.lang = "zh-cn";
  42. i18nService.setCurrentLang($scope.lang);
  43. var loginUser = $rootScope.user;
  44. $scope.chuli = false;
  45. $scope.assign = false;
  46. for (var i = 0; i < loginUser.menu.length; i++) {
  47. if (loginUser.menu[i].link == "xunjianliebiao_chuli") {
  48. $scope.chuli = true;
  49. }
  50. if (loginUser.menu[i].link == "xunjianliebiao_assign") {
  51. $scope.assign = true;
  52. }
  53. }
  54. var defaultFilterData = {
  55. assignee: loginUser.id,
  56. // "assignee": "1",
  57. idx: 0,
  58. sum: 10,
  59. status: "",
  60. searchType: "todo",
  61. };
  62. var inspectListParameter = {
  63. assignee: loginUser.id,
  64. // "assignee": "1",
  65. idx: 0,
  66. sum: 10,
  67. status: "",
  68. };
  69. // $scope.memoryfilterData = {
  70. // "idx": 0,
  71. // "sum": 10
  72. // }
  73. //本地存储
  74. sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
  75. //ui-grid设置
  76. $scope.gridOptions = {};
  77. $scope.gridOptions.data = "myData";
  78. $scope.gridOptions.enableColumnResizing = true;
  79. $scope.gridOptions.enableFiltering = true;
  80. $scope.gridOptions.enableGridMenu = true;
  81. $scope.gridOptions.enableRowSelection = true;
  82. $scope.gridOptions.showGridFooter = true;
  83. $scope.gridOptions.showColumnFooter = false;
  84. $scope.gridOptions.fastWatch = true;
  85. $scope.gridOptions.useExternalFiltering = true;
  86. $scope.gridOptions.useExternalPagination = true;
  87. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  88. $scope.gridOptions.paginationPageSize = 10;
  89. $scope.gridOptions.multiSelect = true;
  90. // $scope.gridOptions.rowTemplate = '<div style="background: red"><a>123</a></div';
  91. // $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>";
  92. $scope.gridOptions.rowIdentity = function (row) {
  93. return row.id;
  94. };
  95. $scope.gridOptions.getRowIdentity = function (row) {
  96. return row.id;
  97. };
  98. //执行中的巡检才能批量派单
  99. $scope.gridOptions.isRowSelectable = function (row,i) {
  100. // console.log(row,row.uid,document);
  101. if (row.entity.state == 0) {
  102. return true;
  103. } else {
  104. return false;
  105. }
  106. };
  107. $scope.transferColor = function (item) {
  108. var color = "icon iconfont icon-zhengchang greenfont";
  109. if (item && item.colourInfo) {
  110. if (item.colourInfo.id == 1) {
  111. color = "icon iconfont icon-yiyuqi redfont";
  112. } else if (item.colourInfo.id == 2) {
  113. color = "iconfont icon-yuqixinxiu yellofont";
  114. }
  115. } else {
  116. // color = "white";
  117. }
  118. return color;
  119. };
  120. $scope.transfertip = function (item) {
  121. var tip = "正常";
  122. if (item && item.colourInfo) {
  123. if (item.colourInfo.id == 1) {
  124. tip = "逾期";
  125. } else if (item.colourInfo.id == 2) {
  126. tip = "即将逾期";
  127. }
  128. } else {
  129. // color = "white";
  130. }
  131. return tip;
  132. };
  133. $scope.gridOptions.columnDefs = [
  134. {
  135. name: "id",
  136. displayName: "",
  137. width: 40,
  138. enableFiltering: false,
  139. cellTemplate:
  140. "<div>" +
  141. '<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>',
  142. },
  143. {
  144. name: "inspection.title",
  145. displayName: "计划主题",
  146. width: "12%",
  147. minWidth: 120,
  148. enableFiltering: false,
  149. },
  150. {
  151. name: "sign",
  152. displayName: "单号",
  153. width: "12%",
  154. minWidth: 120,
  155. enableFiltering: false,
  156. },
  157. {
  158. name: "online",
  159. displayName: "巡检分类",
  160. width: "23%",
  161. minWidth: 200,
  162. enableFiltering: false,
  163. cellTemplate:
  164. "<div>" +
  165. '<div class="ui-grid-cell-contents">{{row.entity.online?"线上巡检-":(row.entity.online===false?"线下巡检-":"")}}{{row.entity.inspectionType.type}}</div>' +
  166. "</div>",
  167. },
  168. // {
  169. // name: "inspection.createUser.name",
  170. // displayName: "创建人",
  171. // width: "8%",
  172. // minWidth: 80,
  173. // enableFiltering: false,
  174. // },
  175. {
  176. name: "stateName",
  177. displayName: "状态",
  178. width: "8%",
  179. minWidth: 80,
  180. enableFiltering: false,
  181. },
  182. {
  183. name: "processUser.name",
  184. displayName: "处理人/组",
  185. width: "8%",
  186. minWidth: 80,
  187. enableFiltering: false,
  188. cellTemplate: '<div>' +
  189. '<div class="ui-grid-cell-contents" ng-if="row.entity.processUser">{{row.entity.processUser.name}}</div>' +
  190. '<div class="ui-grid-cell-contents" ng-if="row.entity.group">{{row.entity.group.groupName}}</div>' +
  191. '</div>'
  192. },
  193. {
  194. name: "startDate",
  195. displayName: "开始时间",
  196. width: "15%",
  197. minWidth: 160,
  198. enableFiltering: false,
  199. cellTemplate:
  200. "<div>" +
  201. '<div class="ui-grid-cell-contents">{{row.entity.startDate?grid.appScope.transferTime(row.entity.startDate):""}}</div>' +
  202. "</div>",
  203. },
  204. {
  205. name: "endTime",
  206. displayName: "结束时间",
  207. width: "15%",
  208. width: 160,
  209. enableFiltering: false,
  210. cellTemplate:
  211. "<div>" +
  212. '<div class="ui-grid-cell-contents">{{row.entity.endTime?grid.appScope.transferTime(row.entity.endTime):""}}</div>' +
  213. "</div>",
  214. },
  215. {
  216. name: "操作",
  217. minWidth: "150",
  218. enableFiltering: false,
  219. cellTemplate:
  220. '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  221. '<a ng-click="grid.appScope.lookFunction(row.entity)" tooltip="查看" tooltip-placement="right" class="bianjifont">查看</a>' +
  222. '<a ng-show="{{grid.appScope.showChuli(row.entity)&&grid.appScope.chuli}}" ng-click="grid.appScope.selectRowFunction(row.entity)" class="bianjifont">处理</a>' +
  223. // '<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>' +
  224. "</div>",
  225. },
  226. ];
  227. // $scope.addData = function() {
  228. // $state.go('app.inspection.inspectList.editor', {
  229. // formKey: 'inspectionform',
  230. // service: 'api_bpm_data'
  231. // });
  232. // }
  233. $scope.transferTime = function (time) {
  234. return moment(time).format("YYYY-MM-DD HH:mm");
  235. };
  236. $scope.showChuli = function (data) {
  237. if(data.inspection.dictionary.value == 1){
  238. // 按巡检人员
  239. if (data.processUser.id == loginUser.id && data.stateName == "执行中") {
  240. return true;
  241. } else {
  242. return false;
  243. }
  244. }else if(data.inspection.dictionary.value == 3){
  245. // 按工作组
  246. var hasGroup = loginUser.group.some(v=>v.id == data.group.id);
  247. if (hasGroup && data.stateName == "执行中") {
  248. return true;
  249. } else {
  250. return false;
  251. }
  252. }
  253. };
  254. $scope.selectRowFunction = function (data) {
  255. var filedata = {
  256. model: {
  257. inspectionProcessActual: data,
  258. },
  259. };
  260. $state.go("app.inspection.inspectListEditor", {
  261. taskId: data.taskId,
  262. dataId: data.id,
  263. processInstanceId: data.processInstanceId,
  264. pdKey: data.processKey,
  265. formUiEdit: data.inspectionType.formUiEdit,
  266. // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  267. model: JSON.stringify(filedata),
  268. });
  269. };
  270. $scope.lookFunction = function (data) {
  271. var filedata = {
  272. model: {
  273. inspectionProcessActual: data,
  274. },
  275. // model:data
  276. };
  277. $state.go("app.inspection.inspectListdetail", {
  278. formKey: data.inspectionType.formUiName,
  279. dataId: data.id,
  280. taskId: data.taskId,
  281. processInstanceId: data.processInstanceId,
  282. pdKey: data.processKey,
  283. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  284. formUiName: data.inspectionType.formUiName,
  285. model: JSON.stringify(filedata),
  286. });
  287. };
  288. $scope.model = {
  289. assignee: JSON.parse(sessionStorage.inspectListParameter).assignee,
  290. idx: 0,
  291. sum: 10,
  292. searchType: "todo",
  293. inspectionProcessActual: {
  294. inspection: {},
  295. },
  296. };
  297. // $scope.removeData = function() {
  298. // // var rmvList = [$scope.selected.items.id]
  299. // var rmvList = [];
  300. // angular.forEach($scope.selected.items, function(item) {
  301. // rmvList.push(item.id);
  302. // });
  303. // if (rmvList.length > 0) {
  304. // api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
  305. // if (response.status == 200) {
  306. // SweetAlert.swal({
  307. // title: "删除成功!",
  308. // type: "success",
  309. // confirmButtonColor: "#007AFF"
  310. // }, function() {
  311. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  312. // $scope.selected = {
  313. // items: []
  314. // };
  315. // });
  316. // } else {
  317. // SweetAlert.swal({
  318. // title: "操作异常!",
  319. // text: "系统异常,请稍后重试,或者联系管理员!",
  320. // type: "error"
  321. // });
  322. // }
  323. // })
  324. // }
  325. // }
  326. //批量派单
  327. $scope.toAssign = function() {
  328. var _$scope = $scope;
  329. console.log($scope.selected.items);
  330. var sendList = [];
  331. angular.forEach($scope.selected.items, function(item) {
  332. sendList.push(item.id);
  333. });
  334. // --------------------------------------------------------
  335. var modalInstance = $modal.open({
  336. templateUrl: 'assets/views/incident/tpl/toAssign.tpl.html',
  337. controller: function ($scope, $modalInstance, api_bpm_domain, modelData, currentUserId, Alert, api_user_data) {
  338. console.log(_$scope.selected.items,loginUser);
  339. //获取组下面的用户
  340. $scope.getUsers = function(groupId){
  341. $scope.user = [];
  342. var postData = {};
  343. if(groupId){
  344. postData = {
  345. "idx": 0,
  346. "sum": 100,
  347. user: {
  348. groupdata:{id:groupId},
  349. roledata: { rolecode: "inspectman" },
  350. selectType: "1",
  351. selectDetails:1
  352. }
  353. }
  354. }else{
  355. postData = {
  356. "idx": 0,
  357. "sum": 100,
  358. user: {
  359. roledata: { rolecode: "inspectman" },
  360. selectType: "1",
  361. selectDetails:1
  362. }
  363. }
  364. }
  365. api_user_data.fetchDataList('user', postData).then(function (data) {
  366. $scope.user = data.list;
  367. })
  368. }
  369. $scope.assignUser = null;
  370. $scope.user = [];
  371. $scope.group = [];
  372. $scope.getUsers();
  373. api_user_data.fetchDataList('group', {
  374. "idx": 0,
  375. "sum": 100,
  376. group: {'selectType':'nouser'}
  377. }).then(function (data) {
  378. $scope.group = data.list;
  379. })
  380. $scope.onChangeRotateUser = function(item){
  381. $scope.assignUser = item.id;
  382. }
  383. $scope.onChangeRotateGroup = function(item){
  384. $scope.assignGroup = item.id;
  385. $scope.getUsers(item.id)
  386. }
  387. $scope.ok = function () {
  388. if (!$scope.assignUser){
  389. Alert.swal({
  390. title: "操作失败",
  391. text: "请选择转派对象信息!",
  392. type: "error"
  393. });
  394. return;
  395. }
  396. api_bpm.assign({ids:sendList.join(),userId:$scope.assignUser}).then(function (response) {
  397. console.log(response)
  398. if (response.status == 200) {
  399. Alert.swal({
  400. title: "操作成功!",
  401. confirmButtonColor: "#007AFF",
  402. type: "success"
  403. });
  404. $modalInstance.close('success');
  405. _$scope.gridApi.selection.clearSelectedRows();
  406. } else {
  407. Alert.swal({
  408. title: "操作失败",
  409. text: "操作失败, 请稍后再试!",
  410. type: "error"
  411. });
  412. }
  413. });
  414. }
  415. $scope.cancel = function () {
  416. $modalInstance.dismiss('cancel');
  417. }
  418. },
  419. size: 'sm',
  420. resolve: {
  421. api_bpm: function () {
  422. return api_bpm;
  423. },
  424. modelData: function () {
  425. return _$scope.selected.items;
  426. },
  427. currentUserId: function () {
  428. return loginUser.id;
  429. },
  430. Alert: function () {
  431. return SweetAlert;
  432. },
  433. api_user_data: function () {
  434. return api_user_data;
  435. }
  436. }
  437. });
  438. modalInstance.result.then(function (selectedItem) {
  439. if (selectedItem == 'success') {
  440. defaultFilterData.assignee = loginUser.id;
  441. $scope.refreshData('expand-right', defaultFilterData);
  442. }
  443. });
  444. return;
  445. // --------------------------------------------------------
  446. }
  447. $scope.selected = {
  448. items: [],
  449. };
  450. $scope.editted = {
  451. items: [],
  452. };
  453. $scope.jry_idx = 0;
  454. $scope.jry_sum = 10;
  455. //分页控制
  456. $scope.gridOptions.onRegisterApi = function (gridApi) {
  457. $scope.gridApi = gridApi;
  458. gridApi.pagination.on.paginationChanged(
  459. $scope,
  460. function (newPage, pageSize) {
  461. console.log("ok");
  462. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  463. filterData.idx = newPage - 1;
  464. filterData.sum = pageSize;
  465. $scope.jry_idx = newPage - 1;
  466. $scope.jry_sum = pageSize;
  467. $scope.model.idx = newPage - 1;
  468. $scope.model.sum = pageSize;
  469. $scope.refreshData("expand-right", $scope.model);
  470. }
  471. );
  472. // 单选
  473. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  474. console.log(scope)
  475. if (scope.isSelected) {
  476. scope.grid.appScope.selected.items.push(scope.entity)
  477. } else {
  478. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  479. if (scope.grid.appScope.selected.items[i].id == scope.entity.id) {
  480. scope.grid.appScope.selected.items.splice(i, 1);
  481. break;
  482. }
  483. }
  484. }
  485. console.log(scope.grid.appScope.selected.items)
  486. });
  487. // 全选/全不选
  488. gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows) {
  489. console.log(rows)
  490. var selectitem = [];
  491. selectitem = angular.copy($scope.selected.items);
  492. for (var j = 0; j < rows.length; j++) {
  493. if (rows[j].isSelected == true) {
  494. selectitem.push(rows[j].entity);
  495. } else {
  496. delete selectitem[j];
  497. }
  498. }
  499. $scope.selected.items = [];
  500. for (var i = 0; i < selectitem.length; i++) {
  501. if (selectitem[i]) {
  502. $scope.selected.items.push(selectitem[i]);
  503. }
  504. }
  505. console.log($scope.selected.items)
  506. });
  507. };
  508. // var data = JSON.parse(sessionStorage.inspectListParameter);
  509. // sessionStorage.inspectListParameter = JSON.stringify(data);
  510. $scope.ldloading = {};
  511. $scope.statusData = {};
  512. $scope.tData = { title: "", batchNo: "" };
  513. //搜索事件
  514. $scope.searchinspectlist = function (item) {
  515. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  516. // console.log(filterData);
  517. // if (item.type) {
  518. // filterData.inspection = { 'inspectionTypeDTO': { 'id':item.type.id}};
  519. // }
  520. // if (item.title) {
  521. // filterData.inspection = { 'title': item.title};
  522. // }
  523. $scope.model.idx = $scope.jry_idx;
  524. $scope.model.sum = $scope.jry_sum;
  525. if ($scope.model.inspectionProcessActual.inspectionType) {
  526. $scope.model.inspectionProcessActual.inspectionTypeId =
  527. $scope.model.inspectionProcessActual.inspectionType.id;
  528. delete $scope.model.inspectionProcessActual.inspectionType;
  529. }
  530. if ($scope.statusData.state) {
  531. $scope.model.inspectionProcessActual.state =
  532. $scope.statusData.state.state;
  533. }
  534. if ($scope.tData.title) {
  535. if ($scope.model.inspectionProcessActual.inspection) {
  536. $scope.model.inspectionProcessActual.inspection.title =
  537. $scope.tData.title.title;
  538. } else {
  539. $scope.model.inspectionProcessActual.inspection = {
  540. title: $scope.tData.title.title,
  541. };
  542. }
  543. }
  544. if ($scope.tData.batchNo) {
  545. $scope.model.inspectionProcessActual.batchNo = $scope.tData.batchNo.batchNo;
  546. }
  547. // filterData.status = item;
  548. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  549. $scope.refreshData("expand-right", $scope.model);
  550. };
  551. $scope.clean = function () {
  552. $scope.tData = { title: "", batchNo: "" };
  553. delete $scope.model.inspectionProcessActual.batchNo;
  554. delete $scope.model.inspectionProcessActual.inspection.title;
  555. delete $scope.model.inspectionProcessActual.inspectionType;
  556. delete $scope.model.inspectionProcessActual.inspectionTypeId;
  557. delete $scope.model.inspectionProcessActual.inspection.executeUser;
  558. delete $scope.model.inspectionProcessActual.inspection.createUser;
  559. delete $scope.model.inspectionProcessActual.state;
  560. $scope.statusData = {};
  561. $scope.try_async_load();
  562. $scope.refreshData("expand-right", $scope.model);
  563. };
  564. //树形控件点击事件
  565. $scope.my_tree_handler = function (branch) {
  566. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  567. filterData.status = branch.id;
  568. // if (filterData.inspectionProcessActual) {
  569. // filterData.inspectionProcessActual.inspectionTypeId = branch.id;
  570. // } else {
  571. // filterData = angular.extend(filterData, {
  572. // "inspectionProcessActual": {
  573. // "inspectionTypeId": branch.id
  574. // }
  575. // })
  576. // }
  577. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  578. $scope.refreshData("expand-right", filterData);
  579. };
  580. //搜索栏点击事件
  581. $scope.searchstate = "todo";
  582. $scope.onChange = function (searchType) {
  583. console.log($scope.gridApi)
  584. $scope.gridApi.selection.clearSelectedRows();
  585. $scope.searchstate = searchType;
  586. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  587. filterData.searchType = searchType;
  588. $scope.model.searchType = searchType;
  589. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  590. $scope.refreshData("expand-right", $scope.model);
  591. };
  592. $scope.reload = function () {
  593. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  594. $scope.refreshData("expand-right", filterData);
  595. };
  596. $scope.refreshData = function (style, filterData) {
  597. $scope.ldloading[style.replace("-", "_")] = true;
  598. if (angular.isUndefined(filterData)) {
  599. filterData = defaultFilterData;
  600. }
  601. $scope.myData = [];
  602. $scope.memoryfilterData = filterData;
  603. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(
  604. function (data) {
  605. var myData = Restangular.stripRestangular(data);
  606. $scope.gridOptions.totalItems = myData.resultCount;
  607. if (angular.isArray(myData.data)) {
  608. $scope.myData = myData.data;
  609. for (var i = 0; i < $scope.myData.length; i++) {
  610. //添加序号
  611. $scope.myData[i]["itemId"] =
  612. i + 1 + filterData.idx * filterData.sum;
  613. }
  614. $scope.ldloading[style.replace("-", "_")] = false;
  615. } else {
  616. $scope.ldloading[style.replace("-", "_")] = false;
  617. SweetAlert.swal({
  618. title: "数据为空",
  619. text: myData.data,
  620. type: "warning",
  621. });
  622. }
  623. },
  624. function () {
  625. $scope.ldloading[style.replace("-", "_")] = false;
  626. }
  627. );
  628. };
  629. $scope.refreshData2 = function (style, filterData) {
  630. $scope.ldloading[style.replace("-", "_")] = true;
  631. if (angular.isUndefined(filterData)) {
  632. filterData = defaultFilterData;
  633. }
  634. // $scope.myData = [];
  635. $scope.memoryfilterData = filterData;
  636. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(
  637. function (data) {
  638. var myData = Restangular.stripRestangular(data);
  639. $scope.gridOptions.totalItems = myData.resultCount;
  640. if (angular.isArray(myData.data)) {
  641. $scope.myData = myData.data;
  642. for (var i = 0; i < $scope.myData.length; i++) {
  643. //添加序号
  644. $scope.myData[i]["itemId"] =
  645. i + 1 + filterData.idx * filterData.sum;
  646. }
  647. $scope.ldloading[style.replace("-", "_")] = false;
  648. } else {
  649. $scope.ldloading[style.replace("-", "_")] = false;
  650. SweetAlert.swal({
  651. title: "数据为空",
  652. text: myData.data,
  653. type: "warning",
  654. });
  655. }
  656. },
  657. function () {
  658. $scope.ldloading[style.replace("-", "_")] = false;
  659. }
  660. );
  661. };
  662. $scope.inspecttype = {};
  663. // 获取处理人
  664. $scope.getExecuteUser = function () {
  665. api_configure_data
  666. .fetchDataList("user", {
  667. idx: 0,
  668. sum: 1000,
  669. user: {
  670. roledata: {
  671. rolecode: "inspectman",
  672. },
  673. simple: true,
  674. },
  675. })
  676. .then(function (res) {
  677. $scope.executeUserData = res.list;
  678. });
  679. };
  680. $scope.getExecuteUser();
  681. $scope.statusData = [
  682. {
  683. name: "执行中",
  684. state: 0,
  685. },
  686. {
  687. name: "已完成",
  688. state: 1,
  689. },
  690. ];
  691. $scope.titleData = []; //计划主题列表
  692. $scope.batchNoData = []; //批次号列表
  693. // 获取计划主题列表
  694. $scope.getTitleData = function () {
  695. var postData = {
  696. assignee: $rootScope.user.id,
  697. idx: 0,
  698. sum: 9999,
  699. searchType: "all",
  700. inspectionProcessActual: {},
  701. };
  702. api_bpm_data
  703. .fetchDataList("inspection", postData)
  704. .then(function (result) {
  705. if (result.status == 200) {
  706. $scope.titleData = result.list;
  707. }
  708. });
  709. };
  710. $scope.getTitleData();
  711. //修改计划主题
  712. $scope.changeTitle = function(){
  713. $scope.tData.batchNo = "";
  714. $scope.batchNoData = $scope.tData.title.batchNos.map(v=>({id:v,batchNo:v}));
  715. }
  716. // 获取创建人
  717. $scope.getCreateUser = function () {
  718. api_configure_data
  719. .fetchDataList("user", {
  720. idx: 0,
  721. sum: 1000,
  722. user: {
  723. simple: true,
  724. },
  725. })
  726. .then(function (res) {
  727. $scope.createUserData = res.list;
  728. });
  729. };
  730. $scope.getCreateUser();
  731. $scope.open = function ($event) {
  732. $event.preventDefault();
  733. $event.stopPropagation();
  734. $scope.opened = !$scope.opened;
  735. };
  736. $scope.endOpen = function ($event) {
  737. $event.preventDefault();
  738. $event.stopPropagation();
  739. $scope.startOpened = false;
  740. $scope.endOpened = !$scope.endOpened;
  741. };
  742. $scope.startOpen = function ($event) {
  743. $event.preventDefault();
  744. $event.stopPropagation();
  745. $scope.endOpened = false;
  746. $scope.startOpened = !$scope.startOpened;
  747. };
  748. //树形控件加载
  749. $scope.my_tree = {};
  750. $scope.try_async_load = function () {
  751. $scope.my_data = [];
  752. $scope.doing_async = true;
  753. api_bpm_data
  754. .fetchDataList("inspectionType", {
  755. idx: 0,
  756. sum: 1000,
  757. })
  758. .then(function (response) {
  759. if (response.status == 200) {
  760. var data = response.list;
  761. var objects = [];
  762. for (var i = 0; i < data.length; i++) {
  763. var object = {};
  764. object.id = data[i].id;
  765. if (data[i].parent && data[i].parent.id != 0) {
  766. object.parent = data[i].parent.id;
  767. }
  768. object.label = data[i].type;
  769. objects.push(object);
  770. }
  771. $scope.my_data = convertParentToChildList(objects);
  772. $scope.tree_data = angular.copy($scope.my_data);
  773. if ($scope.my_data.length > 0) {
  774. $scope.doing_async = false;
  775. }
  776. // return $scope.my_tree.expand_all()
  777. } else {
  778. SweetAlert.swal({
  779. title: "系统错误!",
  780. text: "请刷新重试!",
  781. type: "error",
  782. });
  783. }
  784. });
  785. };
  786. function convertListToTree(data, treeMap) {
  787. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  788. var root = null; //Initially set our loop to null
  789. var parentNode = null;
  790. //loop over data
  791. for (var i = 0; i < data.length; i++) {
  792. var datum = data[i];
  793. //each node will have children, so let's give it a "children" poperty
  794. datum.children = [];
  795. //add an entry for this node to the map so that any future children can
  796. //lookup the parent
  797. idToNodeMap[datum.id] = datum;
  798. //Does this node have a parent?
  799. if (typeof datum.parent === "undefined" || datum.parent == null) {
  800. //Doesn't look like it, so this node is the root of the tree
  801. root = datum;
  802. treeMap[datum.id] = root;
  803. } else {
  804. //This node has a parent, so let's look it up using the id
  805. parentNode = idToNodeMap[datum.parent];
  806. //We don't need this property, so let's delete it.
  807. delete datum.parent;
  808. //Let's add the current node as a child of the parent node.
  809. parentNode.children.push(datum);
  810. }
  811. }
  812. return root;
  813. }
  814. function convertParentToChildList(data) {
  815. var treeMap = {};
  816. var list = [];
  817. convertListToTree(data, treeMap);
  818. angular.forEach(treeMap, function (item) {
  819. list.push(item);
  820. });
  821. return list;
  822. }
  823. $scope.refreshData("expand-right", defaultFilterData);
  824. $scope.try_async_load();
  825. $scope.timer = $interval(function () {
  826. $scope.refreshData2("expand-right", $scope.model);
  827. }, $rootScope.refreshTime);
  828. $scope.$on("$destroy", function () {
  829. $interval.cancel($scope.timer);
  830. });
  831. },
  832. ]);