placeCtrl.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. app.controller('placeCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_cmdb2", function ($rootScope, $scope, $http, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_cmdb2) {
  2. $scope.langs = i18nService.getAllLangs();
  3. $scope.lang = 'zh-cn';
  4. $scope.cancles = true;
  5. var loginUser = $rootScope.user;
  6. $scope.xinzeng = false;
  7. $scope.shanchu = false;
  8. $scope.bianji = false;
  9. for (var i = 0; i < loginUser.menu.length; i++) {
  10. if (loginUser.menu[i].link == "quyudidianguanli_xinzeng") {
  11. $scope.xinzeng = true
  12. }
  13. if (loginUser.menu[i].link == "quyudidianguanli_shanchu") {
  14. $scope.shanchu = true
  15. }
  16. if (loginUser.menu[i].link == "quyudidianguanli_bianji") {
  17. $scope.bianji = true
  18. }
  19. }
  20. var fildata = {
  21. "idx": 0,
  22. "sum": 1000
  23. };
  24. $scope.choice = false;
  25. $scope.backcolor = [];
  26. $scope.outhospital = [];
  27. $scope.outarea = [];
  28. $scope.outplace = [];
  29. $scope.pla = {};
  30. $scope.areaid = {};
  31. $scope.areaname = "";
  32. $scope.area = {};
  33. $scope.areaplace = true;
  34. $scope.freshenHospital = function () {
  35. api_user_data.fetchDataList('branch', fildata).then(function (response) {
  36. if (response) {
  37. if (response.status = 200) {
  38. $scope.outhospital = response.list;
  39. }
  40. }
  41. })
  42. }
  43. $scope.freshenHospital();
  44. $scope.freshenarea = function () {
  45. api_user_data.fetchDataList('area', fildata).then(function (response) {
  46. if (response) {
  47. if (response.status = 200) {
  48. if (!$scope.outarea.length&&response.list.length) {
  49. $scope.ckickrow(response.list[0]);
  50. }
  51. $scope.outarea = response.list;
  52. }
  53. }
  54. })
  55. }
  56. $scope.freshenarea();
  57. $scope.freshenplace = function (id) {
  58. if (id) {
  59. var fildata = {
  60. "idx": 0,
  61. "sum": 1000,
  62. "place": {
  63. "area": {
  64. "id": id
  65. }
  66. }
  67. };
  68. api_user_data.fetchDataList('place', fildata).then(function (response) {
  69. if (response) {
  70. if (response.status = 200) {
  71. $scope.outplace = response.list;
  72. }
  73. }
  74. })
  75. }
  76. }
  77. $scope.ckickrow = function (data) {
  78. $scope.choice = false;
  79. $scope.areaid = data.id;
  80. $scope.areaname = data.area;
  81. $scope.areaplace = true;
  82. $scope.areaData = data;
  83. if (data.id) {
  84. $scope.freshenplace(data.id);
  85. // var fildata={"idx":0,"sum":1000,"place":{areaId:data.id}};
  86. // api_user_data.fetchDataList('place',fildata).then(function(response){
  87. // if(response){
  88. // if(response.status=200){
  89. // $scope.outplace= response.list;
  90. // }
  91. // }
  92. // })
  93. } else { }
  94. }
  95. // 置空区域下的地点
  96. $scope.clear = function () {
  97. $scope.areaname = ''
  98. $scope.outplace = []
  99. }
  100. $scope.clickplace = function (pla) {
  101. $scope.areaplace = false;
  102. $scope.pla = pla
  103. }
  104. // 编辑区域
  105. $scope.editArea = function (data) {
  106. var modalInstance = $modal.open({
  107. templateUrl: 'assets/views/system/tpl/area.html',
  108. controller: function ($scope, scope, $modalInstance, api_user_data) {
  109. $scope.title = "修改区域";
  110. $scope.cancel = function () {
  111. $modalInstance.dismiss('cancel');
  112. };
  113. $scope.check = {
  114. areaName: data.area,
  115. areaAlias: data.alias ? data.alias.split(',') : []
  116. }
  117. $scope.outhospital = scope.outhospital;
  118. $scope.search = {hospital:{id:data.branch,hosName:data.branchName}};
  119. $scope.ok = function (check) {
  120. // if (areaName != data.area) {
  121. if ($scope.check.areaName && $scope.search.hospital.id) {
  122. $modalInstance.close({areaName:check.areaName,hospital:$scope.search.hospital,areaAlias:check.areaAlias});
  123. } else {
  124. SweetAlert.swal({
  125. title: "修改失败!",
  126. text: "名称不能为空",
  127. type: "error"
  128. })
  129. }
  130. // } else {
  131. // $modalInstance.dismiss('cancel');
  132. // }
  133. }
  134. },
  135. resolve: {
  136. scope: function () {
  137. return $scope;
  138. }
  139. }
  140. });
  141. modalInstance.result.then(function (selectedItem) {
  142. if (selectedItem) {
  143. var fildata = {
  144. "area": {
  145. "id": data.id,
  146. "deleteFlag": 0,
  147. "area": selectedItem.areaName,
  148. branch: selectedItem.hospital.id,
  149. branchName: selectedItem.hospital.hosName,
  150. alias: String(selectedItem.areaAlias)
  151. }
  152. }
  153. api_user_data.updData('area', fildata).then(function (response) {
  154. if (response) {
  155. if (response.status == 200) {
  156. SweetAlert.swal({
  157. title: "修改成功!",
  158. type: "success"
  159. }, function () {
  160. $scope.freshenarea()
  161. })
  162. } else {
  163. SweetAlert.swal({
  164. title: "修改失败!",
  165. text: response.msg || '',
  166. type: "error"
  167. })
  168. }
  169. }
  170. })
  171. }
  172. })
  173. }
  174. // 新增区域
  175. $scope.addArea = function (state) {
  176. var modalInstance = $modal.open({
  177. templateUrl: 'assets/views/system/tpl/area.html',
  178. controller: function ($scope, scope, $modalInstance, api_user_data) {
  179. $scope.title = "新增区域";
  180. $scope.check = {
  181. areaName: "",
  182. areaAlias: []
  183. }
  184. $scope.search = {hospital:{}};
  185. $scope.outhospital = scope.outhospital;
  186. $scope.cancel = function () {
  187. $modalInstance.dismiss('cancel');
  188. };
  189. $scope.ok = function (check) {
  190. if ($scope.check.areaName&&$scope.search.hospital.id) {
  191. $modalInstance.close({areaName:check.areaName,hospital:$scope.search.hospital,areaAlias:check.areaAlias});
  192. } else {
  193. SweetAlert.swal({
  194. title: "新增失败!",
  195. text: "名称不能为空",
  196. type: "error"
  197. })
  198. }
  199. }
  200. },
  201. resolve: {
  202. scope: function () {
  203. return $scope;
  204. }
  205. }
  206. });
  207. modalInstance.result.then(function (selectedItem) {
  208. if (selectedItem) {
  209. var fildata = {
  210. "area": {
  211. "area": selectedItem.areaName,
  212. branch: selectedItem.hospital.id,
  213. branchName: selectedItem.hospital.hosName,
  214. alias: String(selectedItem.areaAlias)
  215. }
  216. }
  217. api_user_data.addData('area', fildata).then(function (response) {
  218. if (response) {
  219. if (response.status == 200) {
  220. SweetAlert.swal({
  221. title: "新增成功!",
  222. type: "success"
  223. }, function () {
  224. $scope.freshenarea()
  225. })
  226. } else {
  227. SweetAlert.swal({
  228. title: "新增失败!",
  229. text: response.msg || '',
  230. type: "error"
  231. })
  232. }
  233. }
  234. })
  235. }
  236. })
  237. }
  238. //删除区域
  239. $scope.closearea = function (index, data) {
  240. if (!data.id) {
  241. $scope.cancles = true;
  242. $scope.outarea.splice(index, 1);
  243. } else {
  244. var rmvList = data;
  245. var modalInstance = $modal.open({
  246. templateUrl: 'assets/views/delete.html',
  247. controller: function ($scope, $modalInstance) {
  248. $scope.ok = function () {
  249. $modalInstance.close(data);
  250. };
  251. $scope.cancel = function () {
  252. $modalInstance.dismiss('cancel');
  253. };
  254. $scope.title = '区域删除';
  255. $scope.connect = '是否删除该区域'
  256. },
  257. size: 'sm'
  258. });
  259. modalInstance.result.then(function (selectedItem) {
  260. if (selectedItem) {
  261. if (selectedItem.id) {
  262. var fildata = [selectedItem.id];
  263. api_user_data.rmvData('area', fildata).then(function (response) {
  264. if (response) {
  265. if (response.status == 200) {
  266. $scope.outplace = [];
  267. $scope.areaname = "";
  268. $scope.outarea.splice(index, 1);
  269. SweetAlert.swal({
  270. title: "删除成功!",
  271. type: "success"
  272. })
  273. } else {
  274. SweetAlert.swal({
  275. title: "删除失败!",
  276. text: response.msg || '',
  277. type: "error"
  278. })
  279. }
  280. }
  281. })
  282. }
  283. }
  284. })
  285. }
  286. }
  287. // 编辑地点
  288. $scope.editPlace = function (data) {
  289. var modalInstance = $modal.open({
  290. templateUrl: 'assets/views/system/tpl/place.html',
  291. controller: function ($scope, scope, $modalInstance, api_user_data) {
  292. $scope.title = "修改地点";
  293. $scope.check = {
  294. area: data.area,
  295. place: data.place,
  296. placeAlias: data.alias ? data.alias.split(',') : [],
  297. }
  298. $scope.outarea = scope.outarea;
  299. $scope.cancel = function () {
  300. $modalInstance.dismiss('cancel');
  301. };
  302. $scope.ok = function (check) {
  303. // if (check.place != data.place) {
  304. if (check.place) {
  305. $modalInstance.close(check);
  306. } else {
  307. SweetAlert.swal({
  308. title: "编辑失败!",
  309. text: "地点不能为空",
  310. type: "error"
  311. })
  312. }
  313. // } else {
  314. // $modalInstance.dismiss('cancel');
  315. // }
  316. }
  317. },
  318. resolve: {
  319. scope: function () {
  320. return $scope;
  321. }
  322. }
  323. });
  324. modalInstance.result.then(function (check) {
  325. if (check) {
  326. var fildata = {
  327. "place": {
  328. "place": check.place,
  329. alias: String(check.placeAlias),
  330. "area": {
  331. "id": check.area.id
  332. },
  333. "deleteFlag": 0,
  334. "id": data.id
  335. }
  336. }
  337. api_user_data.updData('place', fildata).then(function (response) {
  338. if (response) {
  339. if (response.status == 200) {
  340. SweetAlert.swal({
  341. title: "修改成功!",
  342. type: "success"
  343. }, function () {
  344. $scope.freshenplace($scope.areaData.id);
  345. })
  346. } else {
  347. SweetAlert.swal({
  348. title: "修改失败!",
  349. text: response.msg || '',
  350. type: "error"
  351. })
  352. }
  353. }
  354. })
  355. }
  356. })
  357. }
  358. // 新增地点
  359. $scope.addplace = function (area) {
  360. var modalInstance = $modal.open({
  361. templateUrl: 'assets/views/system/tpl/place.html',
  362. controller: function ($scope, scope, $modalInstance, api_user_data) {
  363. $scope.title = "新增地点";
  364. if (area !== undefined) {
  365. $scope.check = { area: area, placeAlias: [] }
  366. } else {
  367. $scope.check = {placeAlias: []}
  368. }
  369. $scope.outarea = scope.outarea;
  370. $scope.cancel = function () {
  371. $modalInstance.dismiss('cancel');
  372. };
  373. $scope.ok = function (check) {
  374. if (check && check.area && check.place) {
  375. console.log(check, 9999)
  376. $modalInstance.close(check);
  377. } else {
  378. SweetAlert.swal({
  379. title: "新增失败!",
  380. text: "请填写必填项",
  381. type: "error"
  382. })
  383. }
  384. }
  385. },
  386. resolve: {
  387. scope: function () {
  388. return $scope;
  389. }
  390. }
  391. });
  392. modalInstance.result.then(function (check) {
  393. if (check) {
  394. var fildata = {
  395. "place": {
  396. "place": check.place,
  397. "alias": String(check.placeAlias),
  398. }
  399. }
  400. if (check.area) {
  401. fildata.place.area = {
  402. "id": check.area.id
  403. }
  404. }
  405. api_user_data.addData('place', fildata).then(function (response) {
  406. if (response) {
  407. if (response.status == 200) {
  408. SweetAlert.swal({
  409. title: "新增成功!",
  410. type: "success"
  411. }, function () {
  412. $scope.freshenplace($scope.areaData.id);
  413. })
  414. } else {
  415. SweetAlert.swal({
  416. title: "新增失败!",
  417. text: response.msg || '',
  418. type: "error"
  419. })
  420. }
  421. }
  422. })
  423. }
  424. })
  425. }
  426. //删除地点
  427. $scope.closeplace = function (index, data) {
  428. if (!data.id) {
  429. $scope.cancles = true;
  430. $scope.outplace.splice(index, 1);
  431. } else {
  432. var rmvList = data;
  433. var modalInstance = $modal.open({
  434. templateUrl: 'assets/views/delete.html',
  435. controller: function ($scope, $modalInstance) {
  436. $scope.ok = function () {
  437. $modalInstance.close(data);
  438. };
  439. $scope.cancel = function () {
  440. $modalInstance.dismiss('cancel');
  441. };
  442. $scope.title = '地点删除';
  443. $scope.connect = '是否删除该地点'
  444. },
  445. size: 'sm'
  446. });
  447. modalInstance.result.then(function (selectedItem) {
  448. if (selectedItem) {
  449. if (selectedItem.id) {
  450. var fildata = [selectedItem.id];
  451. api_user_data.rmvData('place', fildata).then(function (response) {
  452. if (response) {
  453. if (response.status == 200) {
  454. $scope.outplace.splice(index, 1);
  455. SweetAlert.swal({
  456. title: "删除成功!",
  457. type: "success"
  458. })
  459. } else {
  460. SweetAlert.swal({
  461. title: "删除失败!",
  462. type: "error"
  463. })
  464. }
  465. }
  466. })
  467. }
  468. }
  469. })
  470. }
  471. }
  472. //导入
  473. $scope.importopen = function () { //导入触发事件
  474. var modalInstance = $modal.open({
  475. templateUrl: 'assets/views/import.html',
  476. controller: function ($scope, $modalInstance, FileUploader) {
  477. var importUploader = $scope.importUploader = new FileUploader({
  478. url: api_user_data.importData().getRequestedUrl(),
  479. });
  480. importUploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
  481. console.info('onWhenAddingFileFailed', item, filter, options);
  482. };
  483. importUploader.onAfterAddingFile = function (fileItem) {
  484. console.info('onAfterAddingFile', fileItem);
  485. };
  486. importUploader.onAfterAddingAll = function (addedFileItems) {
  487. console.info('onAfterAddingAll', addedFileItems);
  488. };
  489. importUploader.onProgressItem = function (fileItem, progress) {
  490. console.info('onProgressItem', fileItem, progress);
  491. };
  492. importUploader.onProgressAll = function (progress) {
  493. console.info('onProgressAll', progress);
  494. };
  495. importUploader.onSuccessItem = function (fileItem, response, status, headers) {
  496. if (response.status == 200) {
  497. SweetAlert.swal({
  498. title: "导入成功!",
  499. confirmButtonColor: "#007AFF",
  500. type: "success"
  501. }, function () {
  502. // $scope.ldloading.contract_overlay = false;
  503. $rootScope.isMask = false;
  504. $scope.refreshData('expand-right', defaultFilterData);
  505. });
  506. } else {
  507. // $scope.ldloading.contract_overlay = false;
  508. $rootScope.isMask = false;
  509. SweetAlert.swal({
  510. title: "导入失败!",
  511. text: response.error,
  512. type: "error"
  513. })
  514. }
  515. console.info('onSuccessItem', fileItem, response, status, headers);
  516. };
  517. importUploader.onErrorItem = function (fileItem, response, status, headers) {
  518. console.info('onErrorItem', fileItem, response, status, headers);
  519. SweetAlert.swal({
  520. title: "系统错误!",
  521. text: "系统错误,请稍候重试!",
  522. type: "error"
  523. });
  524. };
  525. importUploader.onCancelItem = function (fileItem, response, status, headers) {
  526. console.info('onCancelItem', fileItem, response, status, headers);
  527. };
  528. importUploader.onCompleteItem = function (fileItem, response, status, headers) {
  529. console.info('onCompleteItem', fileItem, response, status, headers);
  530. };
  531. importUploader.onCompleteAll = function () {
  532. console.info('onCompleteAll');
  533. };
  534. $scope.ldloading = {};
  535. $rootScope.isMask = false;
  536. $scope.import = function (style) {
  537. // $scope.ldloading[style.replace('-', '_')] = true;
  538. $modalInstance.dismiss('cancel');
  539. $rootScope.isMask = true;
  540. importUploader.onBeforeUploadItem = function (item) {
  541. angular.extend(item.headers, $rootScope.getSession());
  542. item.formData.push({
  543. 'filename': item.file.name
  544. });
  545. item.formData.push({
  546. 'type': "areaPlace"
  547. });
  548. console.info('onBeforeUploadItem', item);
  549. };
  550. importUploader.uploadAll();
  551. }
  552. $scope.cancel = function () {
  553. $modalInstance.dismiss('cancel');
  554. };
  555. },
  556. size: 'sm',
  557. resolve: {
  558. importUploader: function () {
  559. return $scope.importUploader;
  560. }
  561. }
  562. });
  563. modalInstance.result.then(function (selectedItem) {
  564. if (selectedItem) { }
  565. })
  566. }
  567. //导出
  568. $scope.openmodel = function () {
  569. // var modalInstance = $modal.open({
  570. // templateUrl: 'assets/views/system/tpl/getdown.html',
  571. // controller: function($scope, $modalInstance) {
  572. // $scope.key = {};
  573. // $scope.onChange = function(key) {
  574. // $scope.key = key;
  575. // }
  576. // // $scope.downmodel = [{ id: 1, name: "EXCEL2003版(xls)" }, { id: 2, name: "EXCEL2007及以上版(xlsx)" }]
  577. // $scope.ok = function() {
  578. // $modalInstance.close($scope.key);
  579. // };
  580. // $scope.cancel = function() {
  581. // $modalInstance.dismiss('cancel');
  582. // };
  583. // },
  584. // size: 'sm',
  585. // });
  586. // modalInstance.result.then(function(selectedItem) {
  587. // if (selectedItem) {
  588. // var selectedItemId = "";
  589. // if (selectedItem.id == 2) {
  590. // selectedItemId = ".xlsx";
  591. // }
  592. // var type = "areaPlace";
  593. // var month = 0;
  594. $http({
  595. url: api_user_data.downDataModel("areaPlace", 0).getRequestedUrl(),
  596. method: 'GET',
  597. headers: {
  598. 'Accept': '*/*'
  599. },
  600. responseType: 'arraybuffer'
  601. }).success(function (data, status, headers, config) {
  602. var file = new Blob([data], {
  603. // type : 'application/octet-stream'
  604. type: 'application/vnd.ms-excel'
  605. });
  606. //trick to download store a file having its URL
  607. var fileURL = URL.createObjectURL(file);
  608. var a = document.createElement('a');
  609. a.href = fileURL;
  610. a.target = '_blank';
  611. a.download = "区域地点.xlsx";
  612. document.body.appendChild(a);
  613. a.click();
  614. }).error(function (data, status, headers, config) {
  615. console.log(data);
  616. });
  617. }
  618. // });
  619. // }
  620. // 2021
  621. //导入模板
  622. $scope.importDataTpl = function () {
  623. var wt_url = api_user_data.importData1('areaPlace').getRequestedUrl();
  624. var form = new FormData();
  625. var file = document.getElementById("importTplIpt").files[0];
  626. form.append('filename', file.name)
  627. form.append('file', file);
  628. console.log(document.getElementById("importTplIpt").files)
  629. $http({
  630. method: 'POST',
  631. url: wt_url,
  632. data: form,
  633. headers: { 'Content-Type': undefined },
  634. transformRequest: angular.identity
  635. }).success(function (data) {
  636. document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
  637. if (data.status == 200) {
  638. SweetAlert.swal({
  639. title: "导入成功",
  640. confirmButtonColor: "#007AFF",
  641. type: "success"
  642. }, function (flag) {
  643. $scope.freshenarea();
  644. $scope.freshenplace();
  645. });
  646. } else {
  647. SweetAlert.swal({
  648. title: "导入失败",
  649. text: data.error,
  650. type: "error"
  651. });
  652. }
  653. }).error(function (data) {
  654. document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
  655. SweetAlert.swal({
  656. title: "导入失败",
  657. text: data.error,
  658. type: "error"
  659. });
  660. })
  661. };
  662. //导出模板
  663. $scope.exportDataTpl = function () {
  664. var wt_url = api_cmdb2.exportData1("downDataModels/operationSystem", {}).getRequestedUrl()
  665. $http({
  666. url: wt_url,
  667. method: 'POST',
  668. headers: {
  669. 'Accept': '*/*'
  670. },
  671. responseType: 'arraybuffer'
  672. }).success(function (data, status, headers, config) {
  673. var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1];
  674. var file = new Blob([data], {
  675. type: 'application/vnd.ms-excel'
  676. });
  677. var fileURL = URL.createObjectURL(file);
  678. var a = document.createElement('a');
  679. a.href = fileURL;
  680. a.target = '_blank';
  681. a.download = decodeURIComponent(fileName);
  682. document.body.appendChild(a);
  683. a.click();
  684. }).error(function (data, status, headers, config) { });
  685. };
  686. }]);