phoneListCtrl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. app.controller('phoneListCtrl', ["$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('phoneUnit', 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. "phoneDirectory": {
  52. "unit": {
  53. "id": id
  54. }
  55. }
  56. };
  57. api_user_data.fetchDataList('phoneDirectory', 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.unit;
  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/company.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.unit;
  103. $scope.ok = function (areaName) {
  104. if (areaName != data.unit) {
  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. "phoneUnit": {
  129. "id": data.id,
  130. "deleteFlag": 0,
  131. "unit": selectedItem
  132. }
  133. }
  134. api_user_data.addData('phoneUnit', fildata).then(function (response) {
  135. if (response) {
  136. if (response.data && response.data.id) {
  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/company.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. "phoneUnit": {
  187. "unit": selectedItem
  188. }
  189. }
  190. api_user_data.addData('phoneUnit', 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('phoneUnit', 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/department.html',
  264. controller: function ($scope, scope, $modalInstance, api_user_data) {
  265. $scope.title = "修改部门";
  266. $scope.check = {
  267. unit: data.unit,
  268. dept: data.dept,
  269. phone: data.phone,
  270. address: data.address
  271. }
  272. $scope.outarea = scope.outarea;
  273. $scope.cancel = function () {
  274. $modalInstance.dismiss('cancel');
  275. };
  276. $scope.ok = function (check) {
  277. if (true) {
  278. if (check.dept && check.phone) {
  279. $modalInstance.close(check);
  280. } else {
  281. SweetAlert.swal({
  282. title: "编辑失败!",
  283. text: "请填写必填项",
  284. type: "error"
  285. })
  286. }
  287. } else {
  288. $modalInstance.dismiss('cancel');
  289. }
  290. }
  291. },
  292. resolve: {
  293. scope: function () {
  294. return $scope;
  295. }
  296. }
  297. });
  298. modalInstance.result.then(function (check) {
  299. if (check) {
  300. var fildata = {
  301. "phoneDirectory": {
  302. "dept": check.dept,
  303. "address": check.address,
  304. "phone": check.phone,
  305. "unit": {
  306. "id": check.unit.id
  307. },
  308. "deleteFlag": 0,
  309. "id": data.id
  310. }
  311. }
  312. api_user_data.addData('phoneDirectory', fildata).then(function (response) {
  313. if (response) {
  314. if (response.data && response.data.id) {
  315. SweetAlert.swal({
  316. title: "修改成功!",
  317. type: "success"
  318. }, function () {
  319. $scope.freshenplace($scope.areaData.id);
  320. })
  321. } else {
  322. SweetAlert.swal({
  323. title: "修改失败!",
  324. text: response.msg || '',
  325. type: "error"
  326. })
  327. }
  328. }
  329. })
  330. }
  331. })
  332. }
  333. // 新增部门
  334. $scope.addplace = function (area) {
  335. var modalInstance = $modal.open({
  336. templateUrl: 'assets/views/system/tpl/department.html',
  337. controller: function ($scope, scope, $modalInstance, api_user_data) {
  338. $scope.title = "新增部门";
  339. if (area !== undefined) {
  340. $scope.check = { unit: area }
  341. } else {
  342. $scope.check = {}
  343. }
  344. $scope.outarea = scope.outarea;
  345. $scope.cancel = function () {
  346. $modalInstance.dismiss('cancel');
  347. };
  348. $scope.ok = function (check) {
  349. if (check && check.unit && check.dept && check.phone) {
  350. console.log(check, 9999)
  351. $modalInstance.close(check);
  352. } else {
  353. SweetAlert.swal({
  354. title: "新增失败!",
  355. text: "请填写必填项",
  356. type: "error"
  357. })
  358. }
  359. }
  360. },
  361. resolve: {
  362. scope: function () {
  363. return $scope;
  364. }
  365. }
  366. });
  367. modalInstance.result.then(function (check) {
  368. if (check) {
  369. var fildata = {
  370. "phoneDirectory": {
  371. "dept": check.dept,
  372. "phone": check.phone,
  373. "address": check.address
  374. }
  375. }
  376. if (check.unit) {
  377. fildata.phoneDirectory.unit = {
  378. "id": check.unit.id
  379. }
  380. }
  381. api_user_data.addData('phoneDirectory', fildata).then(function (response) {
  382. if (response) {
  383. if (response.status == 200) {
  384. SweetAlert.swal({
  385. title: "新增成功!",
  386. type: "success"
  387. }, function () {
  388. $scope.freshenplace($scope.areaData.id);
  389. })
  390. } else {
  391. SweetAlert.swal({
  392. title: "新增失败!",
  393. text: response.msg || '',
  394. type: "error"
  395. })
  396. }
  397. }
  398. })
  399. }
  400. })
  401. }
  402. //删除部门
  403. $scope.closeplace = function (index, data) {
  404. if (!data.id) {
  405. $scope.cancles = true;
  406. $scope.outplace.splice(index, 1);
  407. } else {
  408. var rmvList = data;
  409. var modalInstance = $modal.open({
  410. templateUrl: 'assets/views/delete.html',
  411. controller: function ($scope, $modalInstance) {
  412. $scope.ok = function () {
  413. $modalInstance.close(data);
  414. };
  415. $scope.cancel = function () {
  416. $modalInstance.dismiss('cancel');
  417. };
  418. $scope.title = '部门删除';
  419. $scope.connect = '是否删除该部门'
  420. },
  421. size: 'sm'
  422. });
  423. modalInstance.result.then(function (selectedItem) {
  424. if (selectedItem) {
  425. if (selectedItem.id) {
  426. var fildata = [selectedItem.id];
  427. api_user_data.rmvData('phoneDirectory', fildata).then(function (response) {
  428. if (response) {
  429. if (response.status == 200) {
  430. $scope.outplace.splice(index, 1);
  431. SweetAlert.swal({
  432. title: "删除成功!",
  433. type: "success"
  434. })
  435. } else {
  436. SweetAlert.swal({
  437. title: "删除失败!",
  438. type: "error"
  439. })
  440. }
  441. }
  442. })
  443. }
  444. }
  445. })
  446. }
  447. }
  448. //导入
  449. $scope.importopen = function () { //导入触发事件
  450. var modalInstance = $modal.open({
  451. templateUrl: 'assets/views/import.html',
  452. controller: function ($scope, $modalInstance, FileUploader) {
  453. var importUploader = $scope.importUploader = new FileUploader({
  454. url: api_user_data.importData().getRequestedUrl(),
  455. });
  456. importUploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
  457. console.info('onWhenAddingFileFailed', item, filter, options);
  458. };
  459. importUploader.onAfterAddingFile = function (fileItem) {
  460. console.info('onAfterAddingFile', fileItem);
  461. };
  462. importUploader.onAfterAddingAll = function (addedFileItems) {
  463. console.info('onAfterAddingAll', addedFileItems);
  464. };
  465. importUploader.onProgressItem = function (fileItem, progress) {
  466. console.info('onProgressItem', fileItem, progress);
  467. };
  468. importUploader.onProgressAll = function (progress) {
  469. console.info('onProgressAll', progress);
  470. };
  471. importUploader.onSuccessItem = function (fileItem, response, status, headers) {
  472. if (response.status == 200) {
  473. SweetAlert.swal({
  474. title: "导入成功!",
  475. confirmButtonColor: "#007AFF",
  476. type: "success"
  477. }, function () {
  478. // $scope.ldloading.contract_overlay = false;
  479. $rootScope.isMask = false;
  480. $scope.refreshData('expand-right', defaultFilterData);
  481. });
  482. } else {
  483. // $scope.ldloading.contract_overlay = false;
  484. $rootScope.isMask = false;
  485. SweetAlert.swal({
  486. title: "导入失败!",
  487. text: response.error,
  488. type: "error"
  489. })
  490. }
  491. console.info('onSuccessItem', fileItem, response, status, headers);
  492. };
  493. importUploader.onErrorItem = function (fileItem, response, status, headers) {
  494. console.info('onErrorItem', fileItem, response, status, headers);
  495. SweetAlert.swal({
  496. title: "系统错误!",
  497. text: "系统错误,请稍候重试!",
  498. type: "error"
  499. });
  500. };
  501. importUploader.onCancelItem = function (fileItem, response, status, headers) {
  502. console.info('onCancelItem', fileItem, response, status, headers);
  503. };
  504. importUploader.onCompleteItem = function (fileItem, response, status, headers) {
  505. console.info('onCompleteItem', fileItem, response, status, headers);
  506. };
  507. importUploader.onCompleteAll = function () {
  508. console.info('onCompleteAll');
  509. };
  510. $scope.ldloading = {};
  511. $rootScope.isMask = false;
  512. $scope.import = function (style) {
  513. // $scope.ldloading[style.replace('-', '_')] = true;
  514. $modalInstance.dismiss('cancel');
  515. $rootScope.isMask = true;
  516. importUploader.onBeforeUploadItem = function (item) {
  517. angular.extend(item.headers, $rootScope.getSession());
  518. item.formData.push({
  519. 'filename': item.file.name
  520. });
  521. item.formData.push({
  522. 'type': "areaPlace"
  523. });
  524. console.info('onBeforeUploadItem', item);
  525. };
  526. importUploader.uploadAll();
  527. }
  528. $scope.cancel = function () {
  529. $modalInstance.dismiss('cancel');
  530. };
  531. },
  532. size: 'sm',
  533. resolve: {
  534. importUploader: function () {
  535. return $scope.importUploader;
  536. }
  537. }
  538. });
  539. modalInstance.result.then(function (selectedItem) {
  540. if (selectedItem) { }
  541. })
  542. }
  543. //导出
  544. $scope.openmodel = function () {
  545. // var modalInstance = $modal.open({
  546. // templateUrl: 'assets/views/system/tpl/getdown.html',
  547. // controller: function($scope, $modalInstance) {
  548. // $scope.key = {};
  549. // $scope.onChange = function(key) {
  550. // $scope.key = key;
  551. // }
  552. // // $scope.downmodel = [{ id: 1, name: "EXCEL2003版(xls)" }, { id: 2, name: "EXCEL2007及以上版(xlsx)" }]
  553. // $scope.ok = function() {
  554. // $modalInstance.close($scope.key);
  555. // };
  556. // $scope.cancel = function() {
  557. // $modalInstance.dismiss('cancel');
  558. // };
  559. // },
  560. // size: 'sm',
  561. // });
  562. // modalInstance.result.then(function(selectedItem) {
  563. // if (selectedItem) {
  564. // var selectedItemId = "";
  565. // if (selectedItem.id == 2) {
  566. // selectedItemId = ".xlsx";
  567. // }
  568. // var type = "areaPlace";
  569. // var month = 0;
  570. $http({
  571. url: api_user_data.downDataModel("areaPlace", 0).getRequestedUrl(),
  572. method: 'GET',
  573. headers: {
  574. 'Accept': '*/*'
  575. },
  576. responseType: 'arraybuffer'
  577. }).success(function (data, status, headers, config) {
  578. var file = new Blob([data], {
  579. // type : 'application/octet-stream'
  580. type: 'application/vnd.ms-excel'
  581. });
  582. //trick to download store a file having its URL
  583. var fileURL = URL.createObjectURL(file);
  584. var a = document.createElement('a');
  585. a.href = fileURL;
  586. a.target = '_blank';
  587. a.download = "单位部门.xlsx";
  588. document.body.appendChild(a);
  589. a.click();
  590. }).error(function (data, status, headers, config) {
  591. console.log(data);
  592. });
  593. }
  594. // });
  595. // }
  596. // 2021
  597. //导入模板
  598. $scope.importDataTpl = function () {
  599. var wt_url = api_user_data.importData1('areaPlace').getRequestedUrl();
  600. var form = new FormData();
  601. var file = document.getElementById("importTplIpt").files[0];
  602. form.append('filename', file.name)
  603. form.append('file', file);
  604. console.log(document.getElementById("importTplIpt").files)
  605. $http({
  606. method: 'POST',
  607. url: wt_url,
  608. data: form,
  609. headers: { 'Content-Type': undefined },
  610. transformRequest: angular.identity
  611. }).success(function (data) {
  612. document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
  613. if (data.status == 200) {
  614. SweetAlert.swal({
  615. title: "导入成功",
  616. confirmButtonColor: "#007AFF",
  617. type: "success"
  618. }, function (flag) {
  619. $scope.freshenarea();
  620. $scope.freshenplace();
  621. });
  622. } else {
  623. SweetAlert.swal({
  624. title: "导入失败",
  625. text: data.error,
  626. type: "error"
  627. });
  628. }
  629. }).error(function (data) {
  630. document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
  631. SweetAlert.swal({
  632. title: "导入失败",
  633. text: data.error,
  634. type: "error"
  635. });
  636. })
  637. };
  638. //导出模板
  639. $scope.exportDataTpl = function () {
  640. var wt_url = api_cmdb2.exportData1("downDataModels/operationSystem", {}).getRequestedUrl()
  641. $http({
  642. url: wt_url,
  643. method: 'POST',
  644. headers: {
  645. 'Accept': '*/*'
  646. },
  647. responseType: 'arraybuffer'
  648. }).success(function (data, status, headers, config) {
  649. var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1];
  650. var file = new Blob([data], {
  651. type: 'application/vnd.ms-excel'
  652. });
  653. var fileURL = URL.createObjectURL(file);
  654. var a = document.createElement('a');
  655. a.href = fileURL;
  656. a.target = '_blank';
  657. a.download = decodeURIComponent(fileName);
  658. document.body.appendChild(a);
  659. a.click();
  660. }).error(function (data, status, headers, config) { });
  661. };
  662. }]);