psMoneyConsumeCtrl.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. angular.module('push')
  2. .controller('psMoneyConsumeCtrl', function ($scope, $stateParams, $ionicModal, UserService, UtilService, $ionicPopup, CommentService) {
  3. $scope.keyPsMoney = "";
  4. $scope.totalcurrency = $stateParams.totalcurrency;
  5. var item = 0;//服务对应item
  6. //获取兑换服务列表
  7. var getServices = function () {
  8. $scope.showLoadingToast();
  9. CommentService.getServices().then(function (response) {
  10. // console.log(response);
  11. $scope.servicelist = response;
  12. $scope.hideLoadingToast();
  13. }, function () {
  14. $scope.hideLoadingToast();
  15. })
  16. };
  17. getServices();
  18. $ionicModal.fromTemplateUrl('my-payBoard.html', {
  19. scope: $scope,
  20. animation: 'slide-in-up'
  21. }).then(function (modal) {
  22. $scope.modal = modal;
  23. });
  24. //打开支付弹窗
  25. $scope.openPasModal = function (tempitem, tempitemvalue) {
  26. item = tempitem;
  27. if (UserService.ishaspaypassword == 0) {
  28. $ionicPopup.show({
  29. title: '提示',
  30. template: '<span style="width: 100%;display: block;text-align: center;">您的支付密码还未设置</span>',
  31. buttons: [
  32. {
  33. text: '<span class="ionicAction_span">去设置</span>',
  34. type: "button-positive",
  35. onTap: function (e) {
  36. $scope.go("payPsMoneyPassword");
  37. }
  38. }
  39. ]
  40. });
  41. return;
  42. }
  43. if ($scope.totalcurrency < tempitemvalue) {
  44. notPsEnough();
  45. return;
  46. }
  47. $scope.modal.show();
  48. };
  49. //关闭支付弹窗
  50. $scope.closePasModal = function () {
  51. $scope.keyPsMoney = "";
  52. $scope.modal.hide();
  53. };
  54. //输入密码
  55. $scope.pressKey = function (num) {
  56. $(".gradeBgWrap_Div").removeClass("gradeBgWrap_Div_delete");
  57. if ($scope.keyPsMoney.length >= 6) {
  58. return;
  59. }
  60. $scope.keyPsMoney += num;
  61. if ($scope.keyPsMoney.length == 6) {
  62. checkPas();
  63. }
  64. };
  65. /*回退密码*/
  66. $scope.keyBoardDelete = function () {
  67. if ($scope.keyPsMoney.length <= 0) {
  68. return;
  69. }
  70. $scope.keyPsMoney = $scope.keyPsMoney.substring(0, $scope.keyPsMoney.length - 1);
  71. };
  72. //检测密码并兑换服务
  73. var checkPas = function () {
  74. CommentService.checkPaymentPassword($scope.keyPsMoney).then(function (response) {
  75. if (response == 1) {
  76. CommentService.exchangeService(item).then(function (response) {
  77. //0 支付密码错误 1 兑换成功 2 普适币不足 3 支付密码成功,兑换失败
  78. // console.log(response);
  79. if (response == 1) {
  80. UtilService.showMess("兑换成功");
  81. } else if (response == 2) {
  82. notPsEnough();
  83. } else {
  84. UtilService.showMess("兑换失败,请重试");
  85. }
  86. $scope.keyPsMoney = "";
  87. $scope.hideLoadingToast();
  88. }, function () {
  89. $scope.keyPsMoney = "";
  90. $scope.hideLoadingToast();
  91. })
  92. } else {
  93. UtilService.showMess("支付密码错误,请重试");
  94. $scope.hideLoadingToast();
  95. }
  96. $scope.closePasModal();
  97. }, function () {
  98. $scope.closePasModal();
  99. $scope.hideLoadingToast();
  100. });
  101. };
  102. //账户余额不足
  103. var notPsEnough = function () {
  104. $ionicPopup.show({
  105. template: "<span style='display: block;width:90%;margin: 0 auto 10px;height: 55px;'>您的账号余额不足,无法兑换服务!</span>",
  106. title: "普适币账号余额不足",
  107. scope: $scope,
  108. buttons: [
  109. {
  110. text: "取消"
  111. },
  112. {
  113. text: '<span class="pop_right_button">确认</span>',
  114. type: "button-positive",
  115. onTap: function (e) {
  116. }
  117. }
  118. ]
  119. })
  120. };
  121. });