phoneListCtrl.js 27 KB

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