hospitalCtrl.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("hospitalCtrl", [
  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. function (
  19. $rootScope,
  20. $scope,
  21. $state,
  22. $timeout,
  23. $interval,
  24. $modal,
  25. SweetAlert,
  26. i18nService,
  27. uiGridConstants,
  28. uiGridGroupingConstants,
  29. Restangular,
  30. api_user_data
  31. ) {
  32. $scope.langs = i18nService.getAllLangs();
  33. $scope.lang = "zh-cn";
  34. i18nService.setCurrentLang($scope.lang);
  35. var loginUser = $rootScope.user;
  36. $scope.xinzeng = false;
  37. $scope.shanchu = false;
  38. $scope.bianji = false;
  39. for (var i = 0; i < loginUser.menu.length; i++) {
  40. if (loginUser.menu[i].link == "hospital_add") {
  41. $scope.xinzeng = true;
  42. }
  43. if (loginUser.menu[i].link == "hospital_del") {
  44. $scope.shanchu = true;
  45. }
  46. if (loginUser.menu[i].link == "hospital_edit") {
  47. $scope.bianji = true;
  48. }
  49. }
  50. $scope.gridOptions = {};
  51. $scope.gridOptions.data = "myData";
  52. $scope.gridOptions.enableColumnResizing = true;
  53. $scope.gridOptions.enableFiltering = true;
  54. $scope.gridOptions.enableGridMenu = true;
  55. $scope.gridOptions.enableRowSelection = true;
  56. $scope.gridOptions.showGridFooter = true;
  57. $scope.gridOptions.showColumnFooter = false;
  58. $scope.gridOptions.fastWatch = true;
  59. $scope.gridOptions.useExternalFiltering = true;
  60. $scope.gridOptions.useExternalPagination = true;
  61. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  62. $scope.gridOptions.paginationPageSize = 10;
  63. $scope.gridOptions.multiSelect = false;
  64. // $scope.gridOptions.rowTemplate =
  65. // '<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>';
  66. $scope.gridOptions.rowIdentity = function (row) {
  67. return row.id;
  68. };
  69. $scope.gridOptions.getRowIdentity = function (row) {
  70. return row.id;
  71. };
  72. $scope.gridOptions.columnDefs = [
  73. {
  74. name: "item",
  75. displayName: "序号",
  76. width: 50,
  77. enableFiltering: false,
  78. },
  79. {
  80. name: "parent.hosName",
  81. displayName: "父级院区",
  82. width: "25%",
  83. enableFiltering: false,
  84. },
  85. {
  86. name: "hosName",
  87. displayName: "院区名称",
  88. width: "25%",
  89. enableFiltering: false,
  90. },
  91. {
  92. name: "hosNo",
  93. displayName: "院区编码",
  94. width: "25%",
  95. enableFiltering: false,
  96. },
  97. {
  98. name: "操作",
  99. cellTemplate:
  100. '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  101. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  102. '<a ng-click="grid.appScope.removeData(row.entity)" ng-show="grid.appScope.shanchu" class="bianjifont">删除</a>' +
  103. "</div></div>",
  104. enableFiltering: false,
  105. },
  106. ];
  107. $scope.transferDept = function (data) {
  108. if (data) {
  109. return data;
  110. } else {
  111. return "无";
  112. }
  113. };
  114. // // 区域
  115. // $scope.getArea = function () {
  116. // var fildata = {
  117. // "idx": 0,
  118. // "sum": 1000
  119. // };
  120. // api_user_data.fetchDataList('area', fildata).then(function (res) {
  121. // $scope.areaData=res.list;
  122. // })
  123. // }
  124. // $scope.getArea();
  125. // // 选择区域带出地点
  126. // $scope.changeArea=function(item){
  127. // $scope.getPlace(item.id)
  128. // }
  129. // // 地点
  130. // $scope.getPlace = function (areaId) {
  131. // var fildata = {
  132. // "idx": 0,
  133. // "sum": 1000,
  134. // place: {area: {id: areaId}},
  135. // };
  136. // api_user_data.fetchDataList('place', fildata).then(function (res) {
  137. // $scope.placeData=res.list;
  138. // })
  139. // }
  140. // 编辑
  141. $scope.saveData = function (selectdata) {
  142. console.log(selectdata);
  143. var modalInstance = $modal.open({
  144. templateUrl: "assets/views/system/tpl/hospitalchange.html",
  145. controller: function ($scope, scope, $modalInstance, api_user_data) {
  146. $scope.hospital = selectdata;
  147. $scope.title = "院区编辑";
  148. $scope.hospitalList = [];
  149. api_user_data.fetchDataList("branch", { "idx":0,"sum":10 })
  150. .then(function (data) {
  151. $scope.hospitalList = Restangular.stripRestangular(data).list.filter(v=>(v.id != selectdata.id && (v.children.length > 0||(v.children.length === 0 && Restangular.stripRestangular(data).list.length === 1))));
  152. });
  153. $scope.cancel = function () {
  154. $modalInstance.dismiss("cancel");
  155. };
  156. $scope.savercode = function (hospital) {
  157. if (hospital && hospital.hosName && hospital.hosNo) {
  158. var fildata = {
  159. branch: {
  160. uuid:hospital.uuid,
  161. parent:hospital.parent,
  162. id: hospital.id,
  163. hosName: hospital.hosName,
  164. hosNo: hospital.hosNo,
  165. deleteFlag: 0,
  166. },
  167. };
  168. api_user_data
  169. .updData("branch", fildata)
  170. .then(function (response) {
  171. if (response) {
  172. if (response.status == 200) {
  173. SweetAlert.swal(
  174. {
  175. title: "修改成功!",
  176. type: "success",
  177. },
  178. function () {
  179. scope.refreshData("expand-right", scope.fileData);
  180. }
  181. );
  182. } else if (response.status == 500) {
  183. SweetAlert.swal(
  184. {
  185. title: "修改失败!",
  186. text: "该院区已存在",
  187. type: "error",
  188. },
  189. function () {
  190. scope.refreshData("expand-right", scope.fileData);
  191. }
  192. );
  193. } else {
  194. SweetAlert.swal(
  195. {
  196. title: "修改失败!",
  197. type: "error",
  198. },
  199. function () {
  200. scope.refreshData("expand-right", scope.fileData);
  201. }
  202. );
  203. }
  204. $modalInstance.close();
  205. } else {
  206. SweetAlert.swal(
  207. {
  208. title: "修改失败!",
  209. type: "error",
  210. },
  211. function () {
  212. scope.refreshData("expand-right", scope.fileData);
  213. }
  214. );
  215. }
  216. });
  217. } else {
  218. SweetAlert.swal(
  219. {
  220. title: "修改失败!",
  221. text: "请填写必填项!",
  222. type: "error",
  223. confirmButtonColor: "#DD6B55",
  224. },
  225. function () {}
  226. );
  227. }
  228. };
  229. },
  230. resolve: {
  231. scope: function () {
  232. return $scope;
  233. },
  234. },
  235. });
  236. };
  237. // 新增
  238. $scope.addData = function () {
  239. var modalInstance = $modal.open({
  240. templateUrl: "assets/views/system/tpl/hospitalchange.html",
  241. controller: function ($scope, $modalInstance, api_user_data) {
  242. $scope.title = "院区新增";
  243. $scope.cancel = function () {
  244. $modalInstance.dismiss("cancel");
  245. };
  246. $scope.hospital = { hosName: "", hosNo: "", parent:undefined };
  247. $scope.hospitalList = [];
  248. api_user_data.fetchDataList("branch", { "idx":0,"sum":10 })
  249. .then(function (data) {
  250. $scope.hospitalList = Restangular.stripRestangular(data).list.filter(v=>(v.children.length > 0||(v.children.length === 0 && Restangular.stripRestangular(data).list.length === 1)));
  251. if($scope.hospitalList.length){
  252. $scope.hospital.parent = $scope.hospitalList[0];
  253. }
  254. });
  255. $scope.savercode = function (hospital) {
  256. if (hospital && hospital.hosName && hospital.hosNo) {
  257. $modalInstance.close(hospital);
  258. } else {
  259. SweetAlert.swal(
  260. {
  261. title: "新增失败!",
  262. text: "请填写必填项!",
  263. type: "error",
  264. confirmButtonColor: "#DD6B55",
  265. },
  266. function () {}
  267. );
  268. }
  269. };
  270. },
  271. });
  272. modalInstance.result.then(function (selectedItem) {
  273. if (selectedItem.hosName && selectedItem.hosNo) {
  274. var fildata = {
  275. branch: {
  276. parent:selectedItem.parent,
  277. hosName: selectedItem.hosName,
  278. hosNo: selectedItem.hosNo,
  279. deleteFlag: 0,
  280. },
  281. };
  282. api_user_data.addData("branch", fildata).then(function (response) {
  283. if (response) {
  284. if (response.status == 200) {
  285. SweetAlert.swal(
  286. {
  287. title: "新增成功!",
  288. type: "success",
  289. },
  290. function () {
  291. $scope.refreshData("expand-right", $scope.fileData);
  292. }
  293. );
  294. } else {
  295. SweetAlert.swal({
  296. title: "新增失败!",
  297. text: response.msg,
  298. type: "error",
  299. });
  300. }
  301. }
  302. });
  303. } else {
  304. SweetAlert.swal(
  305. {
  306. title: "新增失败!",
  307. text: "请填写必填项!",
  308. type: "error",
  309. confirmButtonColor: "#DD6B55",
  310. },
  311. function () {}
  312. );
  313. }
  314. });
  315. };
  316. // 删除
  317. $scope.removeData = function (rmData) {
  318. var modalInstance = $modal.open({
  319. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  320. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  321. var rmvList = [];
  322. $scope.title = "院区删除";
  323. $scope.connect = "确定要删除此院区?";
  324. rmvList.push(rmData);
  325. $scope.ok = function () {
  326. $modalInstance.close(rmvList);
  327. };
  328. $scope.cancel = function () {
  329. $modalInstance.dismiss("cancel");
  330. };
  331. },
  332. size: "sm",
  333. resolve: {
  334. scope: function () {
  335. return $scope;
  336. },
  337. },
  338. });
  339. modalInstance.result.then(function (selectedItem) {
  340. if (selectedItem) {
  341. if (selectedItem.length > 0) {
  342. console.log(selectedItem);
  343. api_user_data
  344. .rmvData("branch", [selectedItem[0].id])
  345. .then(function (response) {
  346. if (response.status == 200) {
  347. SweetAlert.swal(
  348. {
  349. title: "删除成功!",
  350. type: "success",
  351. confirmButtonColor: "#007AFF",
  352. },
  353. function () {
  354. $scope.myData = _.reject($scope.myData, function (o) {
  355. return _.includes(selectedItem, o.id);
  356. });
  357. $scope.selected = {
  358. items: [],
  359. };
  360. $scope.gridOptions.totalItems =
  361. $scope.gridOptions.totalItems - selectedItem.length;
  362. $scope.gridApi.grid.selection.selectedCount = 0;
  363. $scope.refreshData("expand-right", $scope.fileData);
  364. }
  365. );
  366. } else {
  367. SweetAlert.swal({
  368. title: "操作异常!",
  369. text: "系统异常,请稍后重试,或者联系管理员!",
  370. type: "error",
  371. });
  372. }
  373. });
  374. }
  375. }
  376. });
  377. };
  378. $scope.selected = {
  379. items: [],
  380. };
  381. $scope.editted = {
  382. items: [],
  383. };
  384. $scope.gridOptions.onRegisterApi = function (gridApi) {
  385. $scope.gridApi = gridApi;
  386. gridApi.pagination.on.paginationChanged(
  387. $scope,
  388. function (newPage, pageSize) {
  389. var filtersData = $scope.memoryfilterData;
  390. filtersData.idx = newPage - 1;
  391. filtersData.sum = pageSize;
  392. $scope.fileData.idx = newPage - 1;
  393. $scope.fileData.sum = pageSize;
  394. defaultFilterData = filtersData;
  395. $scope.refreshData("expand-right", $scope.fileData);
  396. }
  397. );
  398. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  399. scope.grid.appScope.selected.items = scope.entity;
  400. });
  401. };
  402. var defaultFilterData = {
  403. idx: 0,
  404. sum: 10,
  405. };
  406. $scope.memoryfilterData = {
  407. idx: 0,
  408. sum: 10,
  409. };
  410. $scope.fileData = {
  411. idx: 0,
  412. sum: 10,
  413. branch: {},
  414. };
  415. $scope.ldloading = {};
  416. $scope.refreshData = function (style, filterData) {
  417. $scope.selected.items = {};
  418. $scope.ldloading[style.replace("-", "_")] = true;
  419. if (angular.isUndefined(filterData)) {
  420. filterData = defaultFilterData;
  421. }
  422. $scope.myData = [];
  423. $scope.selected = { items: [] };
  424. if ($scope.gridApi) {
  425. $scope.gridApi.grid.selection.selectedCount = 0;
  426. }
  427. api_user_data.fetchDataList("branch", filterData).then(
  428. function (data) {
  429. var myData = Restangular.stripRestangular(data);
  430. $scope.gridOptions.totalItems = myData.totalNum;
  431. $scope.myData = myData.list;
  432. for (var i = 0; i < $scope.myData.length; i++) {
  433. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  434. }
  435. $scope.ldloading[style.replace("-", "_")] = false;
  436. },
  437. function () {
  438. $scope.ldloading[style.replace("-", "_")] = false;
  439. }
  440. );
  441. };
  442. $scope.refreshData2 = function (style, filterData) {
  443. $scope.selected.items = {};
  444. $scope.ldloading[style.replace("-", "_")] = true;
  445. if (angular.isUndefined(filterData)) {
  446. filterData = defaultFilterData;
  447. }
  448. // $scope.myData = [];
  449. $scope.selected = { items: [] };
  450. if ($scope.gridApi) {
  451. $scope.gridApi.grid.selection.selectedCount = 0;
  452. }
  453. api_user_data.fetchDataList("branch", filterData).then(
  454. function (data) {
  455. var myData = Restangular.stripRestangular(data);
  456. $scope.gridOptions.totalItems = myData.totalNum;
  457. $scope.myData = myData.list;
  458. for (var i = 0; i < $scope.myData.length; i++) {
  459. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  460. }
  461. $scope.ldloading[style.replace("-", "_")] = false;
  462. },
  463. function () {
  464. $scope.ldloading[style.replace("-", "_")] = false;
  465. }
  466. );
  467. };
  468. // 搜索
  469. $scope.searchData = function () {
  470. $scope.refreshData("expand-right", $scope.fileData);
  471. };
  472. // 清空
  473. $scope.clean = function () {
  474. delete $scope.fileData.branch.dept;
  475. delete $scope.fileData.branch.address;
  476. delete $scope.fileData.branch.phone;
  477. delete $scope.fileData.branch.parent;
  478. delete $scope.fileData.branch.area;
  479. delete $scope.fileData.branch.place;
  480. $scope.refreshData("expand-right", $scope.fileData);
  481. };
  482. // 获取单位下拉
  483. $scope.model = {};
  484. $scope.deptData = {};
  485. // $scope.getDeptData=function(){
  486. // var data={
  487. // "idx":0,
  488. // "sum":1000
  489. // }
  490. // api_user_data.fetchDataList('branch',data).then(function(res){
  491. // $scope.deptData=res.list;
  492. // // console.log($scope.deptData)
  493. // })
  494. // }
  495. // $scope.getDeptData();
  496. $scope.refreshData("expand-right", $scope.fileData);
  497. $scope.timer = $interval(function () {
  498. $scope.refreshData2("expand-right", $scope.fileData);
  499. }, $rootScope.refreshTime);
  500. $scope.$on("$destroy", function () {
  501. $interval.cancel($scope.timer);
  502. });
  503. },
  504. ]);