faultConsumablesCtrl.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. showZero: true,
  215. },
  216. };
  217. // 当前所属院区或责任科室
  218. if($rootScope.user.duty){
  219. deptData.consumable.dutyDTO = $rootScope.user.duty;
  220. }else if($rootScope.user.branch){
  221. }
  222. api_user_data
  223. .fetchDataList("consumable", deptData)
  224. .then(function (data) {
  225. var ids = $scope.deptdata.consumableIds.map(v=>v.id);
  226. $scope.consumableList = data.list.filter(v=>!ids.includes(v.id));
  227. });
  228. };
  229. // --------------------
  230. $scope.select_treedata = [];
  231. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  232. if (s) {
  233. var filterKeyword = s.filterKeyword;
  234. }
  235. var postData = {
  236. idx: 0,
  237. sum: 9999,
  238. incidentcategory: {
  239. selectType: "pinyin_qs",
  240. "hierarchyQuery":"two",
  241. "categoryConsumable":1,
  242. }
  243. };
  244. if (filterKeyword) {
  245. postData.incidentcategory.category = filterKeyword;
  246. }
  247. // 当前所属院区或责任科室
  248. if($rootScope.user.duty){
  249. postData.incidentcategory.duty = $rootScope.user.duty.id;
  250. }else if($rootScope.user.branch){
  251. postData.incidentcategory.branch = $rootScope.user.branch.id;
  252. }
  253. $scope.my_data = [];
  254. $scope.doing_async = true;
  255. api_bpm_data
  256. .fetchDataList("incidentcategory", postData)
  257. .then(function (response) {
  258. if (response.status == 200) {
  259. var data = response.list;
  260. if (filterKeyword) {
  261. data.forEach((e) => {
  262. e.isExpanded = true;
  263. });
  264. var li = transform(data).children;
  265. console.log(li);
  266. fn(li);
  267. return;
  268. } else {
  269. var objects = [];
  270. for (var i = 0; i < data.length; i++) {
  271. var object = {};
  272. object.id = data[i].id;
  273. object.parent = data[i].parent;
  274. object.category = data[i].category;
  275. object.isExpanded = true;
  276. objects.push(object);
  277. }
  278. $scope.my_data = convertParentToChildList(objects);
  279. $scope.select_treedata = angular.copy($scope.my_data);
  280. }
  281. if ($scope.my_data.length > 0) {
  282. $scope.doing_async = false;
  283. }
  284. selectItem(selectdata.category,$scope.select_treedata);
  285. $scope.deptdata.category = selectdata.category;
  286. } else {
  287. SweetAlert.swal({
  288. title: "系统错误!",
  289. text: "请刷新重试!",
  290. type: "error",
  291. });
  292. }
  293. });
  294. };
  295. $scope.try_async_load();
  296. // --------------------
  297. $scope.cancel = function () {
  298. $modalInstance.dismiss("cancel");
  299. };
  300. // 保存
  301. $scope.savercode = function (deptdata) {
  302. if (
  303. deptdata &&
  304. deptdata.consumableIds &&
  305. deptdata.category
  306. ) {
  307. var fildata = {
  308. incidentCategoryConsumable: {
  309. id: deptdata.id,
  310. deleteFlag: 0,
  311. consumableIds: deptdata.consumableIds.map(v => v.id).toString(),
  312. category: deptdata.category,
  313. },
  314. };
  315. fildata.incidentCategoryConsumable = Object.assign({}, selectdata, fildata.incidentCategoryConsumable)
  316. api_user_data
  317. .addData("incidentCategoryConsumable", fildata)
  318. .then(function (response) {
  319. if (response) {
  320. if (response.status == 200) {
  321. SweetAlert.swal(
  322. {
  323. title: "修改成功!",
  324. type: "success",
  325. },
  326. function () {
  327. scope.refreshData("expand-right", scope.fileData);
  328. }
  329. );
  330. } else {
  331. SweetAlert.swal(
  332. {
  333. title: "修改失败!",
  334. text: response.msg,
  335. type: "error",
  336. },
  337. function () {
  338. scope.refreshData("expand-right", scope.fileData);
  339. }
  340. );
  341. }
  342. $modalInstance.close();
  343. } else {
  344. SweetAlert.swal(
  345. {
  346. title: "修改失败!",
  347. type: "error",
  348. },
  349. function () {
  350. scope.refreshData("expand-right", scope.fileData);
  351. }
  352. );
  353. }
  354. });
  355. } else {
  356. SweetAlert.swal(
  357. {
  358. title: "修改失败!",
  359. text: "请填写必填项!",
  360. type: "error",
  361. confirmButtonColor: "#DD6B55",
  362. },
  363. function () {}
  364. );
  365. }
  366. };
  367. },
  368. resolve: {
  369. scope: function () {
  370. return $scope;
  371. },
  372. },
  373. });
  374. };
  375. function convertListToTree(data, treeMap) {
  376. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  377. var root = null; //Initially set our loop to null
  378. var parentNode = null;
  379. //loop over data
  380. for (var i = 0; i < data.length; i++) {
  381. var datum = data[i];
  382. //each node will have children, so let's give it a "children" poperty
  383. datum.children = [];
  384. //add an entry for this node to the map so that any future children can
  385. //lookup the parent
  386. idToNodeMap[datum.id] = datum;
  387. //Does this node have a parent?
  388. if (typeof datum.parent === "undefined" || datum.parent == null) {
  389. //Doesn't look like it, so this node is the root of the tree
  390. root = datum;
  391. treeMap[datum.id] = root;
  392. } else {
  393. //This node has a parent, so let's look it up using the id
  394. parentNode = idToNodeMap[datum.parent.id];
  395. //We don't need this property, so let's delete it.
  396. delete datum.parent;
  397. //Let's add the current node as a child of the parent node.
  398. parentNode.children.push(datum);
  399. }
  400. }
  401. return root;
  402. }
  403. function convertParentToChildList(data) {
  404. var treeMap = {};
  405. var list = [];
  406. convertListToTree(data, treeMap);
  407. angular.forEach(treeMap, function (item) {
  408. list.push(item);
  409. });
  410. return list;
  411. }
  412. $scope.addData = function () {
  413. var modalInstance = $modal.open({
  414. templateUrl: "assets/views/system/tpl/faultConsumableschange.html",
  415. controller: function ($rootScope, $scope, scope, $modalInstance, api_user_data,api_bpm_data) {
  416. $scope.deptdata = {
  417. consumableIds: [],
  418. category: "",
  419. };
  420. $scope.title = "故障耗材新增";
  421. // 耗材列表模糊搜索
  422. $scope.searchConsumable = function (key = "") {
  423. var deptData = {
  424. idx: 0,
  425. sum: 10,
  426. consumable: {
  427. keyWord: key,
  428. showZero: true,
  429. },
  430. };
  431. // 当前所属院区或责任科室
  432. if($rootScope.user.duty){
  433. deptData.consumable.dutyDTO = $rootScope.user.duty;
  434. }else if($rootScope.user.branch){
  435. }
  436. api_user_data
  437. .fetchDataList("consumable", deptData)
  438. .then(function (data) {
  439. var ids = $scope.deptdata.consumableIds.map(v=>v.id);
  440. $scope.consumableList = data.list.filter(v=>!ids.includes(v.id));
  441. });
  442. };
  443. // --------------------
  444. $scope.select_treedata = [];
  445. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  446. if (s) {
  447. var filterKeyword = s.filterKeyword;
  448. }
  449. var postData = {
  450. idx: 0,
  451. sum: 9999,
  452. incidentcategory: {
  453. selectType: "pinyin_qs",
  454. "hierarchyQuery":"two",
  455. "categoryConsumable":1,
  456. }
  457. };
  458. if (filterKeyword) {
  459. postData.incidentcategory.category = filterKeyword;
  460. }
  461. // 当前所属院区或责任科室
  462. if($rootScope.user.duty){
  463. postData.incidentcategory.duty = $rootScope.user.duty.id;
  464. }else if($rootScope.user.branch){
  465. postData.incidentcategory.branch = $rootScope.user.branch.id;
  466. }
  467. $scope.my_data = [];
  468. $scope.doing_async = true;
  469. api_bpm_data
  470. .fetchDataList("incidentcategory", postData)
  471. .then(function (response) {
  472. if (response.status == 200) {
  473. var data = response.list;
  474. if (filterKeyword) {
  475. data.forEach((e) => {
  476. e.isExpanded = true;
  477. });
  478. var li = transform(data).children;
  479. console.log(li);
  480. fn(li);
  481. return;
  482. } else {
  483. var objects = [];
  484. for (var i = 0; i < data.length; i++) {
  485. var object = {};
  486. object.id = data[i].id;
  487. object.parent = data[i].parent;
  488. object.category = data[i].category;
  489. object.isExpanded = true;
  490. objects.push(object);
  491. }
  492. $scope.my_data = convertParentToChildList(objects);
  493. $scope.select_treedata = angular.copy($scope.my_data);
  494. }
  495. if ($scope.my_data.length > 0) {
  496. $scope.doing_async = false;
  497. }
  498. } else {
  499. SweetAlert.swal({
  500. title: "系统错误!",
  501. text: "请刷新重试!",
  502. type: "error",
  503. });
  504. }
  505. });
  506. };
  507. $scope.try_async_load();
  508. // --------------------
  509. $scope.cancel = function () {
  510. $modalInstance.dismiss("cancel");
  511. };
  512. // 保存
  513. $scope.savercode = function (deptdata) {
  514. if (
  515. deptdata &&
  516. deptdata.consumableIds &&
  517. deptdata.category
  518. ) {
  519. var selectedItem = deptdata;
  520. if (selectedItem.consumableIds && selectedItem.category) {
  521. var fildata = {
  522. incidentCategoryConsumable: {
  523. consumableIds: selectedItem.consumableIds.map(v => v.id).toString(),
  524. category: selectedItem.category,
  525. },
  526. };
  527. // 当前所属院区或责任科室
  528. if($rootScope.user.duty){
  529. fildata.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  530. }else if($rootScope.user.branch){
  531. fildata.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  532. }
  533. api_user_data
  534. .addData("incidentCategoryConsumable", fildata)
  535. .then(function (response) {
  536. if (response) {
  537. if (response.status == 200) {
  538. $modalInstance.close();
  539. SweetAlert.swal(
  540. {
  541. title: "新增成功!",
  542. type: "success",
  543. },
  544. function () {
  545. scope.refreshData("expand-right", scope.fileData);
  546. }
  547. );
  548. } else {
  549. SweetAlert.swal({
  550. title: "新增失败!",
  551. text: response.msg,
  552. type: "error",
  553. });
  554. }
  555. }
  556. });
  557. } else {
  558. SweetAlert.swal(
  559. {
  560. title: "新增失败!",
  561. text: "请填写必填项!",
  562. type: "error",
  563. confirmButtonColor: "#DD6B55",
  564. },
  565. function () {}
  566. );
  567. }
  568. } else {
  569. SweetAlert.swal(
  570. {
  571. title: "新增失败!",
  572. text: "请填写必填项!",
  573. type: "error",
  574. confirmButtonColor: "#DD6B55",
  575. },
  576. function () {}
  577. );
  578. }
  579. };
  580. },
  581. resolve: {
  582. scope: function(){
  583. return $scope;
  584. }
  585. },
  586. });
  587. };
  588. $scope.removeData = function () {
  589. var modalInstance = $modal.open({
  590. // templateUrl: 'assets/views/delete.html',
  591. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  592. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  593. var rmvList = [];
  594. $scope.title = "故障耗材删除";
  595. $scope.connect = "确定要删除此故障耗材?";
  596. rmvList.push(scope.selected.items);
  597. $scope.ok = function () {
  598. $modalInstance.close(rmvList);
  599. // }
  600. };
  601. $scope.cancel = function () {
  602. $modalInstance.dismiss("cancel");
  603. };
  604. },
  605. size: "sm",
  606. resolve: {
  607. scope: function () {
  608. return $scope;
  609. },
  610. },
  611. });
  612. modalInstance.result.then(function (selectedItem) {
  613. if (selectedItem) {
  614. if (selectedItem.length > 0) {
  615. console.log(selectedItem);
  616. api_user_data
  617. .rmvData("incidentCategoryConsumable", [selectedItem[0].id])
  618. .then(function (response) {
  619. if (response.status == 200) {
  620. SweetAlert.swal(
  621. {
  622. title: "删除成功!",
  623. type: "success",
  624. confirmButtonColor: "#007AFF",
  625. },
  626. function () {
  627. $scope.myData = _.reject($scope.myData, function (o) {
  628. return _.includes(selectedItem, o.id);
  629. });
  630. $scope.selected = {
  631. items: [],
  632. };
  633. $scope.gridOptions.totalItems =
  634. $scope.gridOptions.totalItems - selectedItem.length;
  635. $scope.gridApi.grid.selection.selectedCount = 0;
  636. $scope.refreshData("expand-right", $scope.fileData);
  637. }
  638. );
  639. } else {
  640. SweetAlert.swal({
  641. title: "操作异常!",
  642. text: "系统异常,请稍后重试,或者联系管理员!",
  643. type: "error",
  644. });
  645. }
  646. });
  647. }
  648. }
  649. });
  650. };
  651. $scope.selected = {
  652. items: [],
  653. };
  654. $scope.editted = {
  655. items: [],
  656. };
  657. $scope.gridOptions.onRegisterApi = function (gridApi) {
  658. $scope.gridApi = gridApi;
  659. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  660. // // console.log(rowEntity);
  661. // });
  662. gridApi.pagination.on.paginationChanged(
  663. $scope,
  664. function (newPage, pageSize) {
  665. var filtersData = $scope.memoryfilterData;
  666. filtersData.idx = newPage - 1;
  667. filtersData.sum = pageSize;
  668. $scope.fileData.idx = newPage - 1;
  669. $scope.fileData.sum = pageSize;
  670. defaultFilterData = filtersData;
  671. $scope.refreshData("expand-right", $scope.fileData);
  672. }
  673. );
  674. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  675. scope.grid.appScope.selected.items = scope.entity;
  676. });
  677. };
  678. var defaultFilterData = {
  679. idx: 0,
  680. sum: 10,
  681. incidentCategoryConsumable: {},
  682. };
  683. $scope.memoryfilterData = {
  684. idx: 0,
  685. sum: 10,
  686. incidentCategoryConsumable: {},
  687. };
  688. $scope.fileData = {
  689. idx: 0,
  690. sum: 10,
  691. incidentCategoryConsumable: {},
  692. };
  693. $scope.ldloading = {};
  694. $scope.refreshData = function (style, filterData) {
  695. $scope.selected.items = {};
  696. $scope.ldloading[style.replace("-", "_")] = true;
  697. if (angular.isUndefined(filterData)) {
  698. filterData = defaultFilterData;
  699. }
  700. $scope.myData = [];
  701. $scope.selected = { items: [] };
  702. if ($scope.gridApi) {
  703. $scope.gridApi.grid.selection.selectedCount = 0;
  704. }
  705. // 当前所属院区或责任科室
  706. if($rootScope.user.duty){
  707. filterData.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  708. }else if($rootScope.user.branch){
  709. filterData.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  710. }
  711. api_user_data.fetchDataList("incidentCategoryConsumable", filterData).then(
  712. function (data) {
  713. var myData = Restangular.stripRestangular(data);
  714. $scope.gridOptions.totalItems = myData.totalNum;
  715. $scope.myData = myData.list;
  716. for (var i = 0; i < $scope.myData.length; i++) {
  717. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  718. $scope.myData[i]["consumableDTOSName"] = $scope.myData[i]["consumableDTOS"].map(v => v.name).join(',');
  719. }
  720. $scope.ldloading[style.replace("-", "_")] = false;
  721. },
  722. function () {
  723. $scope.ldloading[style.replace("-", "_")] = false;
  724. }
  725. );
  726. };
  727. $scope.refreshData2 = function (style, filterData) {
  728. $scope.selected.items = {};
  729. $scope.ldloading[style.replace("-", "_")] = true;
  730. if (angular.isUndefined(filterData)) {
  731. filterData = defaultFilterData;
  732. }
  733. $scope.myData = [];
  734. $scope.selected = { items: [] };
  735. if ($scope.gridApi) {
  736. $scope.gridApi.grid.selection.selectedCount = 0;
  737. }
  738. filterData = angular.copy(filterData);
  739. // 当前所属院区或责任科室
  740. if($rootScope.user.duty){
  741. filterData.incidentCategoryConsumable.duty = $rootScope.user.duty.id;
  742. }else if($rootScope.user.branch){
  743. filterData.incidentCategoryConsumable.branch = $rootScope.user.branch.id;
  744. }
  745. api_user_data.fetchDataList("incidentCategoryConsumable", filterData).then(
  746. function (data) {
  747. var myData = Restangular.stripRestangular(data);
  748. $scope.gridOptions.totalItems = myData.totalNum;
  749. $scope.myData = myData.list;
  750. for (var i = 0; i < $scope.myData.length; i++) {
  751. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  752. $scope.myData[i]["consumableDTOSName"] = $scope.myData[i]["consumableDTOS"].map(v => v.name).join(',');
  753. }
  754. $scope.ldloading[style.replace("-", "_")] = false;
  755. },
  756. function () {
  757. $scope.ldloading[style.replace("-", "_")] = false;
  758. }
  759. );
  760. };
  761. // 搜索
  762. $scope.searchData = function () {
  763. $scope.refreshData("expand-right", $scope.fileData);
  764. };
  765. // 清空
  766. $scope.clean = function () {
  767. delete $scope.fileData.incidentCategoryConsumable.consumableIds;
  768. delete $scope.fileData.incidentCategoryConsumable.category;
  769. $scope.getCategoryData();
  770. $scope.refreshData("expand-right", $scope.fileData);
  771. };
  772. // 获取院区下拉
  773. $scope.model = {};
  774. // --------------------
  775. $scope.select_treedata = [];
  776. $rootScope.bala1 = $scope.try_async_load = function (s, fn) {
  777. if (s) {
  778. var filterKeyword = s.filterKeyword;
  779. }
  780. var postData = {
  781. idx: 0,
  782. sum: 9999,
  783. incidentcategory: {
  784. selectType: "pinyin_qs",
  785. "hierarchyQuery":"two",
  786. "categoryConsumable":1,
  787. }
  788. };
  789. if (filterKeyword) {
  790. postData.incidentcategory.category = filterKeyword;
  791. }
  792. // 当前所属院区或责任科室
  793. if($rootScope.user.duty){
  794. postData.incidentcategory.duty = $rootScope.user.duty.id;
  795. }else if($rootScope.user.branch){
  796. postData.incidentcategory.branch = $rootScope.user.branch.id;
  797. }
  798. $scope.my_data = [];
  799. $scope.doing_async = true;
  800. api_bpm_data
  801. .fetchDataList("incidentcategory", postData)
  802. .then(function (response) {
  803. if (response.status == 200) {
  804. var data = response.list;
  805. if (filterKeyword) {
  806. data.forEach((e) => {
  807. e.isExpanded = true;
  808. });
  809. var li = transform(data).children;
  810. console.log(li);
  811. fn(li);
  812. return;
  813. } else {
  814. var objects = [];
  815. for (var i = 0; i < data.length; i++) {
  816. var object = {};
  817. object.id = data[i].id;
  818. object.parent = data[i].parent;
  819. object.category = data[i].category;
  820. object.isExpanded = true;
  821. objects.push(object);
  822. }
  823. $scope.my_data = convertParentToChildList(objects);
  824. $scope.select_treedata = angular.copy($scope.my_data);
  825. }
  826. if ($scope.my_data.length > 0) {
  827. $scope.doing_async = false;
  828. }
  829. } else {
  830. SweetAlert.swal({
  831. title: "系统错误!",
  832. text: "请刷新重试!",
  833. type: "error",
  834. });
  835. }
  836. });
  837. };
  838. // $scope.try_async_load();
  839. // --------------------
  840. $scope.refreshData("expand-right", $scope.fileData);
  841. $scope.timer = $interval(function () {
  842. $scope.refreshData2("expand-right", $scope.fileData);
  843. }, $rootScope.refreshTime);
  844. $scope.$on("$destroy", function () {
  845. $interval.cancel($scope.timer);
  846. });
  847. },
  848. ]);