faultConsumablesCtrl.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("faultConsumablesCtrl", [
  6. "$rootScope",
  7. "$scope",
  8. "$state",
  9. "$timeout",
  10. "$interval",
  11. "$modal",
  12. "SweetAlert",
  13. "i18nService",
  14. "uiGridConstants",
  15. "uiGridGroupingConstants",
  16. "Restangular",
  17. "api_user_data",
  18. 'api_bpm_data',
  19. function (
  20. $rootScope,
  21. $scope,
  22. $state,
  23. $timeout,
  24. $interval,
  25. $modal,
  26. SweetAlert,
  27. i18nService,
  28. uiGridConstants,
  29. uiGridGroupingConstants,
  30. Restangular,
  31. api_user_data,
  32. api_bpm_data
  33. ) {
  34. $scope.langs = i18nService.getAllLangs();
  35. $scope.lang = "zh-cn";
  36. i18nService.setCurrentLang($scope.lang);
  37. var loginUser = $rootScope.user;
  38. $scope.xinzeng = false;
  39. $scope.shanchu = false;
  40. $scope.bianji = false;
  41. for (var i = 0; i < loginUser.menu.length; i++) {
  42. if (loginUser.menu[i].link == "responsibilityDept_add") {
  43. $scope.xinzeng = true;
  44. }
  45. if (loginUser.menu[i].link == "responsibilityDept_del") {
  46. $scope.shanchu = true;
  47. }
  48. if (loginUser.menu[i].link == "responsibilityDept_edit") {
  49. $scope.bianji = true;
  50. }
  51. }
  52. $scope.gridOptions = {};
  53. $scope.gridOptions.data = "myData";
  54. $scope.gridOptions.enableColumnResizing = true;
  55. $scope.gridOptions.enableFiltering = true;
  56. $scope.gridOptions.enableGridMenu = true;
  57. $scope.gridOptions.enableRowSelection = true;
  58. $scope.gridOptions.showGridFooter = true;
  59. $scope.gridOptions.showColumnFooter = false;
  60. $scope.gridOptions.fastWatch = true;
  61. $scope.gridOptions.useExternalFiltering = true;
  62. $scope.gridOptions.useExternalPagination = true;
  63. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  64. $scope.gridOptions.paginationPageSize = 10;
  65. $scope.gridOptions.multiSelect = false;
  66. $scope.gridOptions.rowTemplate =
  67. '<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>';
  68. $scope.gridOptions.rowIdentity = function (row) {
  69. return row.id;
  70. };
  71. $scope.gridOptions.getRowIdentity = function (row) {
  72. return row.id;
  73. };
  74. $scope.gridOptions.columnDefs = [
  75. {
  76. name: "item",
  77. displayName: "序号",
  78. width: 50,
  79. enableFiltering: false,
  80. },
  81. {
  82. name: "category.mutiCategory",
  83. displayName: "故障现象",
  84. width: "20%",
  85. enableFiltering: false,
  86. },
  87. {
  88. name: "consumableDTOSName",
  89. displayName: "耗材信息",
  90. width: "40%",
  91. enableFiltering: false,
  92. },
  93. {
  94. name: "操作",
  95. cellTemplate:
  96. '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  97. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  98. // '<i class="fa fa-pencil-square-o"></i></a>'+
  99. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  100. "</div></div>",
  101. enableFiltering: false,
  102. },
  103. ];
  104. $scope.transferDept = function (data) {
  105. if (data) {
  106. return data;
  107. } else {
  108. return "无";
  109. }
  110. };
  111. //树形图
  112. // 将故障现象搜索结果返回的数据整理成children模式
  113. function transform(nodes) {
  114. var treeConverter = {
  115. result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的
  116. attributeName: 'id', //节点唯一标识符
  117. needFind: true, //是否查询节点在result中已经存在,为了优化效率
  118. transform: function (node) { //转化递归函数,参数:一个待插入节点
  119. if (node.parent != null) { //该节点有父节点
  120. var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制
  121. if (this.needFind) {
  122. for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在
  123. if (newNode.children[i][this.attributeName] === node[this.attributeName]) {
  124. return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  125. }
  126. }
  127. }
  128. this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断
  129. // delete node.parent; //删除该节点的parent属性,如果有的话
  130. node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性
  131. newNode.children.push(node); //将该node节点push进newNode的子节点数组中
  132. return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中
  133. } else if (node.parent == null) { //该叶节点没有父节点,即为根节点
  134. // delete node.parent; //删除该节点的parent属性,如果有的话
  135. if (this.result == null) { //根节点不存在
  136. node.children = []; //给该节点增加children:[]属性
  137. return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  138. } else {
  139. node.children = [];
  140. // 顶级去重
  141. for (var i = 0; i < this.result.children.length; i++) {
  142. if (this.result.children[i][this.attributeName] === node[this.attributeName]) {
  143. return this.result.children[i];
  144. }
  145. }
  146. this.result.children.push(node)
  147. return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  148. }
  149. }
  150. },
  151. getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果
  152. var _node = {};
  153. _node.children = [];
  154. this.result = _node; //重置根节点
  155. this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id”
  156. nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据
  157. nodes.forEach(item => { //循环调用转化方法
  158. this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点
  159. this.transform(item);
  160. })
  161. return this.result; //返回根节点
  162. }
  163. }
  164. var result = treeConverter.getWhole(nodes); //调用
  165. return result;
  166. }
  167. function selectItem(pmodel, childrens) {
  168. if (angular.isArray(pmodel)) {
  169. angular.forEach(pmodel, function (index) {
  170. if (index && index.id) {
  171. angular.forEach(childrens, function (item) {
  172. if (item.id == index.id) {
  173. item.selected = true;
  174. }
  175. if (item && item.children) {
  176. selectItem(pmodel, item.children);
  177. }
  178. });
  179. }
  180. });
  181. } else {
  182. if (pmodel && pmodel.id) {
  183. angular.forEach(childrens, function (item, index) {
  184. if (item.id == pmodel.id) {
  185. item.selected = true;
  186. }
  187. if (item && item.children) {
  188. selectItem(pmodel, item.children);
  189. }
  190. });
  191. }
  192. }
  193. }
  194. $scope.saveData = function (selectdata) {
  195. console.log(selectdata);
  196. var modalInstance = $modal.open({
  197. templateUrl: "assets/views/system/tpl/faultConsumableschange.html",
  198. controller: function ($rootScope, $scope, scope, $modalInstance, api_user_data,api_bpm_data) {
  199. selectdata.category.selected = true;
  200. $scope.deptdata = {
  201. id: selectdata.id,
  202. consumableIds: selectdata.consumableDTOS || [],
  203. category: selectdata.category
  204. };
  205. $scope.categoryList = [];
  206. $scope.title = "故障耗材修改";
  207. // 耗材列表模糊搜索
  208. $scope.searchConsumable = function (key = "") {
  209. var deptData = {
  210. idx: 0,
  211. sum: 10,
  212. consumable: {
  213. keyWord: key,
  214. },
  215. };
  216. api_user_data
  217. .fetchDataList("consumable", deptData)
  218. .then(function (data) {
  219. var ids = $scope.deptdata.consumableIds.map(v=>v.id);
  220. $scope.consumableList = data.list.filter(v=>!ids.includes(v.id));
  221. });
  222. };
  223. // --------------------
  224. $scope.select_treedata = [];
  225. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  226. if (s) {
  227. var filterKeyword = s.filterKeyword;
  228. }
  229. var postData = {
  230. idx: 0,
  231. sum: 9999,
  232. incidentcategory: {
  233. selectType: "pinyin_qs",
  234. "hierarchyQuery":"two",
  235. "categoryConsumable":1,
  236. }
  237. };
  238. if (filterKeyword) {
  239. postData.incidentcategory.category = filterKeyword;
  240. }
  241. // 当前所属院区或责任科室
  242. if($rootScope.user.duty){
  243. postData.incidentcategory.duty = $rootScope.user.duty.id;
  244. }else if($rootScope.user.branch){
  245. postData.incidentcategory.branch = $rootScope.user.branch.id;
  246. }
  247. $scope.my_data = [];
  248. $scope.doing_async = true;
  249. api_bpm_data
  250. .fetchDataList("incidentcategory", postData)
  251. .then(function (response) {
  252. if (response.status == 200) {
  253. var data = response.list;
  254. if (filterKeyword) {
  255. data.forEach((e) => {
  256. e.isExpanded = true;
  257. });
  258. var li = transform(data).children;
  259. console.log(li);
  260. fn(li);
  261. return;
  262. } else {
  263. var objects = [];
  264. for (var i = 0; i < data.length; i++) {
  265. var object = {};
  266. object.id = data[i].id;
  267. object.parent = data[i].parent;
  268. object.category = data[i].category;
  269. object.isExpanded = true;
  270. objects.push(object);
  271. }
  272. $scope.my_data = convertParentToChildList(objects);
  273. $scope.select_treedata = angular.copy($scope.my_data);
  274. }
  275. if ($scope.my_data.length > 0) {
  276. $scope.doing_async = false;
  277. }
  278. selectItem(selectdata.category,$scope.select_treedata);
  279. $scope.deptdata.category = selectdata.category;
  280. } else {
  281. SweetAlert.swal({
  282. title: "系统错误!",
  283. text: "请刷新重试!",
  284. type: "error",
  285. });
  286. }
  287. });
  288. };
  289. $scope.try_async_load();
  290. // --------------------
  291. $scope.cancel = function () {
  292. $modalInstance.dismiss("cancel");
  293. };
  294. // 保存
  295. $scope.savercode = function (deptdata) {
  296. if (
  297. deptdata &&
  298. deptdata.consumableIds &&
  299. deptdata.category
  300. ) {
  301. var fildata = {
  302. incidentCategoryConsumable: {
  303. id: deptdata.id,
  304. deleteFlag: 0,
  305. consumableIds: deptdata.consumableIds.map(v => v.id).toString(),
  306. category: deptdata.category,
  307. },
  308. };
  309. fildata.incidentCategoryConsumable = Object.assign({}, selectdata, fildata.incidentCategoryConsumable)
  310. api_user_data
  311. .addData("incidentCategoryConsumable", fildata)
  312. .then(function (response) {
  313. if (response) {
  314. if (response.status == 200) {
  315. SweetAlert.swal(
  316. {
  317. title: "修改成功!",
  318. type: "success",
  319. },
  320. function () {
  321. scope.refreshData("expand-right", scope.fileData);
  322. }
  323. );
  324. } else {
  325. SweetAlert.swal(
  326. {
  327. title: "修改失败!",
  328. text: response.msg,
  329. type: "error",
  330. },
  331. function () {
  332. scope.refreshData("expand-right", scope.fileData);
  333. }
  334. );
  335. }
  336. $modalInstance.close();
  337. } else {
  338. SweetAlert.swal(
  339. {
  340. title: "修改失败!",
  341. type: "error",
  342. },
  343. function () {
  344. scope.refreshData("expand-right", scope.fileData);
  345. }
  346. );
  347. }
  348. });
  349. } else {
  350. SweetAlert.swal(
  351. {
  352. title: "修改失败!",
  353. text: "请填写必填项!",
  354. type: "error",
  355. confirmButtonColor: "#DD6B55",
  356. },
  357. function () {}
  358. );
  359. }
  360. };
  361. },
  362. resolve: {
  363. scope: function () {
  364. return $scope;
  365. },
  366. },
  367. });
  368. };
  369. function convertListToTree(data, treeMap) {
  370. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  371. var root = null; //Initially set our loop to null
  372. var parentNode = null;
  373. //loop over data
  374. for (var i = 0; i < data.length; i++) {
  375. var datum = data[i];
  376. //each node will have children, so let's give it a "children" poperty
  377. datum.children = [];
  378. //add an entry for this node to the map so that any future children can
  379. //lookup the parent
  380. idToNodeMap[datum.id] = datum;
  381. //Does this node have a parent?
  382. if (typeof datum.parent === "undefined" || datum.parent == null) {
  383. //Doesn't look like it, so this node is the root of the tree
  384. root = datum;
  385. treeMap[datum.id] = root;
  386. } else {
  387. //This node has a parent, so let's look it up using the id
  388. parentNode = idToNodeMap[datum.parent.id];
  389. //We don't need this property, so let's delete it.
  390. delete datum.parent;
  391. //Let's add the current node as a child of the parent node.
  392. parentNode.children.push(datum);
  393. }
  394. }
  395. return root;
  396. }
  397. function convertParentToChildList(data) {
  398. var treeMap = {};
  399. var list = [];
  400. convertListToTree(data, treeMap);
  401. angular.forEach(treeMap, function (item) {
  402. list.push(item);
  403. });
  404. return list;
  405. }
  406. $scope.addData = function () {
  407. var modalInstance = $modal.open({
  408. templateUrl: "assets/views/system/tpl/faultConsumableschange.html",
  409. controller: function ($rootScope, $scope, scope, $modalInstance, api_user_data,api_bpm_data) {
  410. $scope.deptdata = {
  411. consumableIds: [],
  412. category: "",
  413. };
  414. $scope.title = "故障耗材新增";
  415. // 耗材列表模糊搜索
  416. $scope.searchConsumable = function (key = "") {
  417. var deptData = {
  418. idx: 0,
  419. sum: 10,
  420. consumable: {
  421. keyWord: key,
  422. },
  423. };
  424. api_user_data
  425. .fetchDataList("consumable", deptData)
  426. .then(function (data) {
  427. var ids = $scope.deptdata.consumableIds.map(v=>v.id);
  428. $scope.consumableList = data.list.filter(v=>!ids.includes(v.id));
  429. });
  430. };
  431. // --------------------
  432. $scope.select_treedata = [];
  433. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  434. if (s) {
  435. var filterKeyword = s.filterKeyword;
  436. }
  437. var postData = {
  438. idx: 0,
  439. sum: 9999,
  440. incidentcategory: {
  441. selectType: "pinyin_qs",
  442. "hierarchyQuery":"two",
  443. "categoryConsumable":1,
  444. }
  445. };
  446. if (filterKeyword) {
  447. postData.incidentcategory.category = filterKeyword;
  448. }
  449. // 当前所属院区或责任科室
  450. if($rootScope.user.duty){
  451. postData.incidentcategory.duty = $rootScope.user.duty.id;
  452. }else if($rootScope.user.branch){
  453. postData.incidentcategory.branch = $rootScope.user.branch.id;
  454. }
  455. $scope.my_data = [];
  456. $scope.doing_async = true;
  457. api_bpm_data
  458. .fetchDataList("incidentcategory", postData)
  459. .then(function (response) {
  460. if (response.status == 200) {
  461. var data = response.list;
  462. if (filterKeyword) {
  463. data.forEach((e) => {
  464. e.isExpanded = true;
  465. });
  466. var li = transform(data).children;
  467. console.log(li);
  468. fn(li);
  469. return;
  470. } else {
  471. var objects = [];
  472. for (var i = 0; i < data.length; i++) {
  473. var object = {};
  474. object.id = data[i].id;
  475. object.parent = data[i].parent;
  476. object.category = data[i].category;
  477. object.isExpanded = true;
  478. objects.push(object);
  479. }
  480. $scope.my_data = convertParentToChildList(objects);
  481. $scope.select_treedata = angular.copy($scope.my_data);
  482. }
  483. if ($scope.my_data.length > 0) {
  484. $scope.doing_async = false;
  485. }
  486. } else {
  487. SweetAlert.swal({
  488. title: "系统错误!",
  489. text: "请刷新重试!",
  490. type: "error",
  491. });
  492. }
  493. });
  494. };
  495. $scope.try_async_load();
  496. // --------------------
  497. $scope.cancel = function () {
  498. $modalInstance.dismiss("cancel");
  499. };
  500. // 保存
  501. $scope.savercode = function (deptdata) {
  502. if (
  503. deptdata &&
  504. deptdata.consumableIds &&
  505. deptdata.category
  506. ) {
  507. var selectedItem = deptdata;
  508. if (selectedItem.consumableIds && selectedItem.category) {
  509. var fildata = {
  510. incidentCategoryConsumable: {
  511. consumableIds: selectedItem.consumableIds.map(v => v.id).toString(),
  512. category: selectedItem.category,
  513. },
  514. };
  515. // 当前所属院区或责任科室
  516. if($rootScope.user.duty){
  517. fildata.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  518. }else if($rootScope.user.branch){
  519. fildata.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  520. }
  521. api_user_data
  522. .addData("incidentCategoryConsumable", fildata)
  523. .then(function (response) {
  524. if (response) {
  525. if (response.status == 200) {
  526. $modalInstance.close();
  527. SweetAlert.swal(
  528. {
  529. title: "新增成功!",
  530. type: "success",
  531. },
  532. function () {
  533. scope.refreshData("expand-right", scope.fileData);
  534. }
  535. );
  536. } else {
  537. SweetAlert.swal({
  538. title: "新增失败!",
  539. text: response.msg,
  540. type: "error",
  541. });
  542. }
  543. }
  544. });
  545. } else {
  546. SweetAlert.swal(
  547. {
  548. title: "新增失败!",
  549. text: "请填写必填项!",
  550. type: "error",
  551. confirmButtonColor: "#DD6B55",
  552. },
  553. function () {}
  554. );
  555. }
  556. } else {
  557. SweetAlert.swal(
  558. {
  559. title: "新增失败!",
  560. text: "请填写必填项!",
  561. type: "error",
  562. confirmButtonColor: "#DD6B55",
  563. },
  564. function () {}
  565. );
  566. }
  567. };
  568. },
  569. resolve: {
  570. scope: function(){
  571. return $scope;
  572. }
  573. },
  574. });
  575. };
  576. $scope.removeData = function () {
  577. var modalInstance = $modal.open({
  578. // templateUrl: 'assets/views/delete.html',
  579. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  580. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  581. var rmvList = [];
  582. $scope.title = "故障耗材删除";
  583. $scope.connect = "确定要删除此故障耗材?";
  584. rmvList.push(scope.selected.items);
  585. $scope.ok = function () {
  586. $modalInstance.close(rmvList);
  587. // }
  588. };
  589. $scope.cancel = function () {
  590. $modalInstance.dismiss("cancel");
  591. };
  592. },
  593. size: "sm",
  594. resolve: {
  595. scope: function () {
  596. return $scope;
  597. },
  598. },
  599. });
  600. modalInstance.result.then(function (selectedItem) {
  601. if (selectedItem) {
  602. if (selectedItem.length > 0) {
  603. console.log(selectedItem);
  604. api_user_data
  605. .rmvData("incidentCategoryConsumable", [selectedItem[0].id])
  606. .then(function (response) {
  607. if (response.status == 200) {
  608. SweetAlert.swal(
  609. {
  610. title: "删除成功!",
  611. type: "success",
  612. confirmButtonColor: "#007AFF",
  613. },
  614. function () {
  615. $scope.myData = _.reject($scope.myData, function (o) {
  616. return _.includes(selectedItem, o.id);
  617. });
  618. $scope.selected = {
  619. items: [],
  620. };
  621. $scope.gridOptions.totalItems =
  622. $scope.gridOptions.totalItems - selectedItem.length;
  623. $scope.gridApi.grid.selection.selectedCount = 0;
  624. $scope.refreshData("expand-right", $scope.fileData);
  625. }
  626. );
  627. } else {
  628. SweetAlert.swal({
  629. title: "操作异常!",
  630. text: "系统异常,请稍后重试,或者联系管理员!",
  631. type: "error",
  632. });
  633. }
  634. });
  635. }
  636. }
  637. });
  638. };
  639. $scope.selected = {
  640. items: [],
  641. };
  642. $scope.editted = {
  643. items: [],
  644. };
  645. $scope.gridOptions.onRegisterApi = function (gridApi) {
  646. $scope.gridApi = gridApi;
  647. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  648. // // console.log(rowEntity);
  649. // });
  650. gridApi.pagination.on.paginationChanged(
  651. $scope,
  652. function (newPage, pageSize) {
  653. var filtersData = $scope.memoryfilterData;
  654. filtersData.idx = newPage - 1;
  655. filtersData.sum = pageSize;
  656. $scope.fileData.idx = newPage - 1;
  657. $scope.fileData.sum = pageSize;
  658. defaultFilterData = filtersData;
  659. $scope.refreshData("expand-right", $scope.fileData);
  660. }
  661. );
  662. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  663. scope.grid.appScope.selected.items = scope.entity;
  664. });
  665. };
  666. var defaultFilterData = {
  667. idx: 0,
  668. sum: 10,
  669. incidentCategoryConsumable: {},
  670. };
  671. $scope.memoryfilterData = {
  672. idx: 0,
  673. sum: 10,
  674. incidentCategoryConsumable: {},
  675. };
  676. $scope.fileData = {
  677. idx: 0,
  678. sum: 10,
  679. incidentCategoryConsumable: {},
  680. };
  681. $scope.ldloading = {};
  682. $scope.refreshData = function (style, filterData) {
  683. $scope.selected.items = {};
  684. $scope.ldloading[style.replace("-", "_")] = true;
  685. if (angular.isUndefined(filterData)) {
  686. filterData = defaultFilterData;
  687. }
  688. $scope.myData = [];
  689. $scope.selected = { items: [] };
  690. if ($scope.gridApi) {
  691. $scope.gridApi.grid.selection.selectedCount = 0;
  692. }
  693. // 当前所属院区或责任科室
  694. if($rootScope.user.duty){
  695. filterData.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  696. }else if($rootScope.user.branch){
  697. filterData.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  698. }
  699. api_user_data.fetchDataList("incidentCategoryConsumable", filterData).then(
  700. function (data) {
  701. var myData = Restangular.stripRestangular(data);
  702. $scope.gridOptions.totalItems = myData.totalNum;
  703. $scope.myData = myData.list;
  704. for (var i = 0; i < $scope.myData.length; i++) {
  705. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  706. $scope.myData[i]["consumableDTOSName"] = $scope.myData[i]["consumableDTOS"].map(v => v.name).join(',');
  707. }
  708. $scope.ldloading[style.replace("-", "_")] = false;
  709. },
  710. function () {
  711. $scope.ldloading[style.replace("-", "_")] = false;
  712. }
  713. );
  714. };
  715. $scope.refreshData2 = function (style, filterData) {
  716. $scope.selected.items = {};
  717. $scope.ldloading[style.replace("-", "_")] = true;
  718. if (angular.isUndefined(filterData)) {
  719. filterData = defaultFilterData;
  720. }
  721. $scope.myData = [];
  722. $scope.selected = { items: [] };
  723. if ($scope.gridApi) {
  724. $scope.gridApi.grid.selection.selectedCount = 0;
  725. }
  726. filterData = angular.copy(filterData);
  727. // 当前所属院区或责任科室
  728. if($rootScope.user.duty){
  729. filterData.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  730. }else if($rootScope.user.branch){
  731. filterData.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  732. }
  733. api_user_data.fetchDataList("incidentCategoryConsumable", filterData).then(
  734. function (data) {
  735. var myData = Restangular.stripRestangular(data);
  736. $scope.gridOptions.totalItems = myData.totalNum;
  737. $scope.myData = myData.list;
  738. for (var i = 0; i < $scope.myData.length; i++) {
  739. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  740. $scope.myData[i]["consumableDTOSName"] = $scope.myData[i]["consumableDTOS"].map(v => v.name).join(',');
  741. }
  742. $scope.ldloading[style.replace("-", "_")] = false;
  743. },
  744. function () {
  745. $scope.ldloading[style.replace("-", "_")] = false;
  746. }
  747. );
  748. };
  749. // 搜索
  750. $scope.searchData = function () {
  751. $scope.refreshData("expand-right", $scope.fileData);
  752. };
  753. // 清空
  754. $scope.clean = function () {
  755. delete $scope.fileData.incidentCategoryConsumable.consumableIds;
  756. delete $scope.fileData.incidentCategoryConsumable.category;
  757. $scope.getCategoryData();
  758. $scope.refreshData("expand-right", $scope.fileData);
  759. };
  760. // 获取院区下拉
  761. $scope.model = {};
  762. // --------------------
  763. $scope.select_treedata = [];
  764. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  765. if (s) {
  766. var filterKeyword = s.filterKeyword;
  767. }
  768. var postData = {
  769. idx: 0,
  770. sum: 9999,
  771. incidentcategory: {
  772. selectType: "pinyin_qs",
  773. "hierarchyQuery":"two",
  774. "categoryConsumable":1,
  775. }
  776. };
  777. if (filterKeyword) {
  778. postData.incidentcategory.category = filterKeyword;
  779. }
  780. // 当前所属院区或责任科室
  781. if($rootScope.user.duty){
  782. postData.incidentcategory.duty = $rootScope.user.duty.id;
  783. }else if($rootScope.user.branch){
  784. postData.incidentcategory.branch = $rootScope.user.branch.id;
  785. }
  786. $scope.my_data = [];
  787. $scope.doing_async = true;
  788. api_bpm_data
  789. .fetchDataList("incidentcategory", postData)
  790. .then(function (response) {
  791. if (response.status == 200) {
  792. var data = response.list;
  793. if (filterKeyword) {
  794. data.forEach((e) => {
  795. e.isExpanded = true;
  796. });
  797. var li = transform(data).children;
  798. console.log(li);
  799. fn(li);
  800. return;
  801. } else {
  802. var objects = [];
  803. for (var i = 0; i < data.length; i++) {
  804. var object = {};
  805. object.id = data[i].id;
  806. object.parent = data[i].parent;
  807. object.category = data[i].category;
  808. object.isExpanded = true;
  809. objects.push(object);
  810. }
  811. $scope.my_data = convertParentToChildList(objects);
  812. $scope.select_treedata = angular.copy($scope.my_data);
  813. }
  814. if ($scope.my_data.length > 0) {
  815. $scope.doing_async = false;
  816. }
  817. } else {
  818. SweetAlert.swal({
  819. title: "系统错误!",
  820. text: "请刷新重试!",
  821. type: "error",
  822. });
  823. }
  824. });
  825. };
  826. // $scope.try_async_load();
  827. // --------------------
  828. $scope.refreshData("expand-right", $scope.fileData);
  829. $scope.timer = $interval(function () {
  830. $scope.refreshData2("expand-right", $scope.fileData);
  831. }, $rootScope.refreshTime);
  832. $scope.$on("$destroy", function () {
  833. $interval.cancel($scope.timer);
  834. });
  835. },
  836. ]);