angular.module('push') .controller('psMoneyConsumeCtrl', function ($scope, $stateParams, $ionicModal, UserService, UtilService, $ionicPopup, CommentService) { $scope.keyPsMoney = ""; $scope.totalcurrency = $stateParams.totalcurrency; var item = 0;//服务对应item //获取兑换服务列表 var getServices = function () { $scope.showLoadingToast(); CommentService.getServices().then(function (response) { // console.log(response); $scope.servicelist = response; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) }; getServices(); $ionicModal.fromTemplateUrl('my-payBoard.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.modal = modal; }); //打开支付弹窗 $scope.openPasModal = function (tempitem, tempitemvalue) { item = tempitem; if (UserService.ishaspaypassword == 0) { $ionicPopup.show({ title: '提示', template: '您的支付密码还未设置', buttons: [ { text: '去设置', type: "button-positive", onTap: function (e) { $scope.go("payPsMoneyPassword"); } } ] }); return; } if ($scope.totalcurrency < tempitemvalue) { notPsEnough(); return; } $scope.modal.show(); }; //关闭支付弹窗 $scope.closePasModal = function () { $scope.keyPsMoney = ""; $scope.modal.hide(); }; //输入密码 $scope.pressKey = function (num) { $(".gradeBgWrap_Div").removeClass("gradeBgWrap_Div_delete"); if ($scope.keyPsMoney.length >= 6) { return; } $scope.keyPsMoney += num; if ($scope.keyPsMoney.length == 6) { checkPas(); } }; /*回退密码*/ $scope.keyBoardDelete = function () { if ($scope.keyPsMoney.length <= 0) { return; } $scope.keyPsMoney = $scope.keyPsMoney.substring(0, $scope.keyPsMoney.length - 1); }; //检测密码并兑换服务 var checkPas = function () { CommentService.checkPaymentPassword($scope.keyPsMoney).then(function (response) { if (response == 1) { CommentService.exchangeService(item).then(function (response) { //0 支付密码错误 1 兑换成功 2 普适币不足 3 支付密码成功,兑换失败 // console.log(response); if (response == 1) { UtilService.showMess("兑换成功"); } else if (response == 2) { notPsEnough(); } else { UtilService.showMess("兑换失败,请重试"); } $scope.keyPsMoney = ""; $scope.hideLoadingToast(); }, function () { $scope.keyPsMoney = ""; $scope.hideLoadingToast(); }) } else { UtilService.showMess("支付密码错误,请重试"); $scope.hideLoadingToast(); } $scope.closePasModal(); }, function () { $scope.closePasModal(); $scope.hideLoadingToast(); }); }; //账户余额不足 var notPsEnough = function () { $ionicPopup.show({ template: "您的账号余额不足,无法兑换服务!", title: "普适币账号余额不足", scope: $scope, buttons: [ { text: "取消" }, { text: '确认', type: "button-positive", onTap: function (e) { } } ] }) }; });