faultConsumablesCtrl.js 33 KB

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