123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- (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'));
|