placeCtrl.js 28 KB

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