phoneListCtrl.js 26 KB

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