faultConsumablesCtrl.js 32 KB

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