(function (app) { app.controller('loginCtrl', ["$scope", 'userService', "data", '$state', 'msg', '$http', function ($scope, userService, data, $state, msg, $http) { $scope.vm = { mobile: '', password:'' }; $scope.login = function () { msg.loading('登录中...'); userService.login($scope.vm.mobile, $scope.vm.password).then(function (result) { msg.hide(); data.setObject('user', result.data.user); data.set('token', result.data.token); $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.token; $state.go('wl.home'); }, function (erro) { msg.hide(); // msg.error(erro.data.message); msg.error(erro.data.message); }); } }]); app.controller('registerCtrl', ["$scope", 'msg', 'util', 'userService', '$timeout', '$state', 'data', '$http', function ($scope, msg, util, userService, $timeout, $state, data, $http) { $scope.vm = { mobile: '', password: '', password1:'', verifyCode:'', waitSeconds: "获取验证码" }; $scope.typeOpt = [ { name: "托运方", value: 1 }, { name: "承运方", value: 2 } ]; $scope.idcard_typeOpt = [ { name: "身份证", value: 1 }, { name: "其它", value: 2 } ]; $scope.save = function () { if (!$scope.vm.type) { msg.text('请选择类型'); return; } if (!$scope.vm.idcard_type) { msg.text('请选择证件类型'); return; } if (!$scope.vm.idcard_no) { msg.text('请输入证件号码'); return; } if (!util.isMobile($scope.vm.mobile)) { msg.text('请输入正确的手机号', true); return; } if (!$scope.vm.verifyCode) { msg.text('请输入短信验证码'); return; } if ($scope.vm.password !== $scope.vm.password1) { msg.text('密码前后输入不一致'); return; } msg.loading('请稍等...'); userService.register({ phone: $scope.vm.mobile, password: $scope.vm.password, verifyCode: $scope.vm.verifyCode, idcard_type: $scope.vm.idcard_type, idcard_no: $scope.vm.idcard_no, type: $scope.vm.type }).then(function (result) { data.setObject('user', { mobile: $scope.vm.mobile, type: $scope.vm.type }); data.set('token', result.data.token); $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.token; msg.hide(); if ($scope.vm.type == 1) {//托运方 $state.go('wl.car'); } if ($scope.vm.type == 2) {//承运方 $state.go('wl.goods'); } }, function (erro) { msg.hide(); msg.error(erro.data.message); }); } $scope.getVerifyCode = function () { if (!util.isMobile($scope.vm.mobile)) { msg.text('请输入正确的手机号',true); return; } $scope.vm.waitSeconds = "正在发送"; userService.getVerifyCode($scope.vm.mobile).then(function (result) { wait(60); }, function (erro) { wait(0); msg.error(erro); }); } var wait = function (seconds) { if (seconds > 0) { $scope.vm.waitSeconds = "" + seconds + "秒"; $scope.vm.enableSend = false; } else { $scope.vm.waitSeconds = "获取验证码"; $scope.vm.enableSend = true; } $timeout(function () { if (seconds >= 1) wait(seconds - 1); }, 1000); }; }]); app.controller('forgetPasswordCtrl', ["$scope", "util", 'userService', '$timeout', '$state', 'msg', function ($scope, util, userService, $timeout, $state, msg) { $scope.vm = { mobile: '', code: '', password: '', password1:'', waitSeconds: "获取验证码" }; $scope.getVerifyCode = function () { if (!util.isMobile($scope.vm.mobile)) { msg.text('请输入正确的手机号', true); return; } $scope.vm.waitSeconds = "正在发送"; userService.getVerifyCode($scope.vm.mobile).then(function (result) { wait(60); }, function (erro) { wait(0); msg.error(erro); }); } $scope.reset = function (vm) { if (vm.password != vm.password1) { msg.text('密码前后输入不一致'); return; } msg.loading('请稍等...'); var model = { phone: vm.mobile, verifyCode: vm.code, password:vm.password }; userService.resetPassword(model).then(function () { msg.hide(); msg.success('密码找回成功'); $state.go('login'); }, function (erro) { msg.hide(); msg.error(erro.message); }); } var wait = function (seconds) { if (seconds > 0) { $scope.vm.waitSeconds = "" + seconds + "秒"; $scope.vm.enableSend = false; } else { $scope.vm.waitSeconds = "获取验证码"; $scope.vm.enableSend = true; } $timeout(function () { if (seconds >= 1) wait(seconds - 1); }, 1000); }; }]); })(angular.module('app.controllers'));