placeCtrl.js 26 KB

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