creditCardAdminCtrl.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. define(['app/app'], function(app) {
  2. 'use strict';
  3. app.register.controller('creditCardAdminCtrl', ['$scope', 'toaster', 'BaseService', 'bankInfoService', '$filter', '$modal', function($scope, toaster, BaseService, bankInfoService, $filter, $modal) {
  4. BaseService.scrollBackToTop();
  5. var hideBankFilter = $filter("hideBankFilter");
  6. $scope.active = "personal";
  7. var getState = function() {
  8. var method = "getAdminEnterAccount";
  9. switch($scope.active) {
  10. case "personal" :
  11. method = "getAdminPersAccount"; break;
  12. case "enterprise":
  13. method = "getAdminEnterAccount"; break;
  14. default :
  15. method = "getAdminEnterAccount";
  16. }
  17. return method;
  18. }
  19. var getSaveMethod = function(kind) {
  20. var method = null;
  21. switch(kind) {
  22. case "personal":
  23. method = "saveAdminPerAccount"; break;
  24. case "enterprise":
  25. method = "saveAdminEnteAccount"; break;
  26. }
  27. return method;
  28. }
  29. $scope.setActive = function(status) {
  30. $scope.active = status;
  31. loadAccount();
  32. }
  33. $scope.kind = 0;
  34. var loadAccount = function() {
  35. bankInfoService[getState()]({}, function(data) {
  36. $scope.accounts = data;
  37. angular.forEach($scope.accounts, function(account) {
  38. account.filterAccount = hideBankFilter(account.number);
  39. })
  40. }, function(response) {
  41. toaster.pop('error', '获取账户信息失败 '+ response.data);
  42. })
  43. }
  44. loadAccount();
  45. $scope.setDefaultAccount = function(id) {
  46. bankInfoService.setDefaultAccount({id : id}, function() {
  47. toaster.pop('success', '设置成功');
  48. loadAccount();
  49. }, function(response) {
  50. toaster.pop('error', '设置默认账户失败');
  51. })
  52. }
  53. //删除账户
  54. $scope.deleteAccount = function(buyAccount) {
  55. var isSure = confirm('确认删除本银行账户?删除后无法恢复,请谨慎操作');
  56. if(isSure){
  57. bankInfoService.deleteBank({id: buyAccount.id}, function(data) {
  58. toaster.pop('success', '删除成功');
  59. loadAccount();
  60. }, function(response) {
  61. toaster.pop('error', '删除失败');
  62. })
  63. }
  64. }
  65. //编辑账户
  66. $scope.editAccount = function(data) {
  67. var modalInstance = $modal.open({
  68. templateUrl : 'static/view/admin/modal/creditCard_modal.html',
  69. controller : 'BankInfoCtrl',
  70. resolve : {
  71. account : function() {
  72. //深拷贝一份
  73. return angular.copy(data);
  74. },
  75. kind : function() {
  76. return $scope.active;
  77. }
  78. }
  79. });
  80. modalInstance.result.then(function(account) {
  81. var method = getSaveMethod(account.kind);
  82. if(method == null) {
  83. toaster.pop("info", "没有设置对应的账户类型,不能保存");
  84. return ;
  85. }
  86. bankInfoService[method].call(null, account, function(data) {
  87. toaster.pop('success', '保存成功','信息已更新');
  88. $scope.kind = account.kind;
  89. loadAccount();
  90. }, function(res) {
  91. toaster.pop('error', '错误', res.data);
  92. });
  93. });
  94. };
  95. }]);
  96. app.register.controller('BankInfoCtrl', ['$scope', '$modalInstance', 'account', 'kind', function($scope, $modalInstance, account, kind){
  97. $scope.creditCard = account || {};
  98. $scope.creditCard.kind = kind;
  99. if(account) {
  100. $scope.eidt = true;
  101. } else {
  102. delete $scope.eidt;
  103. }
  104. $scope.confirm = function() {
  105. $modalInstance.close($scope.creditCard);
  106. }
  107. $scope.cancel = function() {
  108. $modalInstance.dismiss();
  109. }
  110. }]);
  111. });