hospitalCtrl.js 16 KB

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