placeCtrl.js 27 KB

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