faultConsumablesCtrl.js 34 KB

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