creditCardAdminCtrl.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. $scope.active = 'personal';
  6. var getMethod = function() {
  7. var method = null;
  8. switch($scope.active) {
  9. case 'personal':
  10. method = 'getBuyPersonalBank'; break;
  11. case 'enterprise':
  12. method = 'getBuyEnterpriseBank'; break;
  13. default: method = 'getBuyPersonalBank';
  14. }
  15. return method;
  16. }
  17. $scope.setActive = function(status) {
  18. $scope.active = status;
  19. loadAccount();
  20. }
  21. var hideBankFilter = $filter("hideBankFilter");
  22. var loadAccount = function() {
  23. bankInfoService[getMethod()].call(null, {}, function(data) {
  24. $scope.accounts = data;
  25. angular.forEach($scope.accounts, function(account) {
  26. account.filterAccount = hideBankFilter(account.number);
  27. })
  28. }, function(response) {
  29. toaster.pop('error', '获取账户信息失败 ', response.data);
  30. })
  31. }
  32. loadAccount();
  33. $scope.setDefaultAccount = function(id) {
  34. bankInfoService.setDefaultAccount({id : id}, function() {
  35. toaster.pop('success', '设置成功');
  36. loadAccount();
  37. }, function(response) {
  38. toaster.pop('error', '设置默认账户失败');
  39. })
  40. }
  41. //删除账户
  42. $scope.deleteAccount = function(buyAccount) {
  43. var isSure = confirm('确认删除本银行账户?删除后无法恢复,请谨慎操作');
  44. if(isSure){
  45. bankInfoService.deleteBank({id: buyAccount.id}, function(data) {
  46. toaster.pop('success', '删除成功');
  47. loadAccount();
  48. }, function(response) {
  49. toaster.pop('error', '删除失败');
  50. })
  51. }
  52. }
  53. //编辑账户
  54. $scope.editAccount = function(data) {
  55. switch($scope.active) {
  56. case 'personal':
  57. $scope.kind = 1; break;
  58. case 'enterprise':
  59. $scope.kind = 0; break;
  60. default: $scope.kind = 1;
  61. }
  62. var modalInstance = $modal.open({
  63. templateUrl : 'static/view/common/bankInfoModal.html',
  64. controller : 'BankInfoCtrl',
  65. resolve : {
  66. kind : function() {
  67. //深拷贝一份
  68. return angular.copy($scope.kind);
  69. },
  70. account : function() {
  71. //深拷贝一份
  72. return angular.copy(data);
  73. }
  74. }
  75. });
  76. modalInstance.result.then(function(account) {
  77. if(account.kind) {
  78. bankInfoService.saveBuyPersonalBank({}, account, function(data) {
  79. toaster.pop('success', '成功','信息已更新');
  80. $scope.kind = account.kind;
  81. loadAccount(); //这个方法不能提取到外面,因为存在异步。
  82. }, function(res) {
  83. toaster.pop('error', '错误', res.data);
  84. });
  85. }else {
  86. //企业账户
  87. bankInfoService.saveBuyEnterpriseBank({}, account, function(data) {
  88. toaster.pop('success', '保存成功','信息已更新');
  89. $scope.kind = account.kind;
  90. loadAccount();
  91. }, function(res) {
  92. toaster.pop('error', '错误', res.data);
  93. });
  94. }
  95. }, function() {
  96. });
  97. };
  98. }]);
  99. app.register.controller('BankInfoCtrl', ['$scope', '$modalInstance', 'account', 'kind', function($scope, $modalInstance, account, kind){
  100. $scope.account = account;
  101. if($scope.account) {
  102. $scope.eidt = true;
  103. } else {
  104. delete $scope.eidt;
  105. }
  106. $scope.kind = kind;
  107. if($scope.account) {
  108. $scope.title = "修改账户";
  109. }else {
  110. $scope.title = "新增账户";
  111. $scope.account = {};
  112. }
  113. $scope.set = function(kind) {
  114. $scope.kind = kind;
  115. }
  116. $scope.confirm = function() {
  117. $scope.account.kind = $scope.kind;
  118. $modalInstance.close($scope.account);
  119. }
  120. $scope.cancel = function() {
  121. $modalInstance.dismiss();
  122. }
  123. }]);
  124. })