placeCtrl.js 25 KB

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