angular.module('push') .controller('bindPhoneCtrl', function ($scope, $stateParams, LoginService, UtilService, ConfigService, SqliteStorageService, UserService, $ionicHistory, $state, CommonService, AccountService) { if ($scope.app) { $scope.setStatusBar(0); } $scope.titleLogo = 'img/wel_push.png'; if ($scope.isLiyangApp) { $scope.titleLogo = 'img/wel_liyang.png'; } var tokeninfo = angular.fromJson($stateParams.tokeninfo); var type = $scope.type = $stateParams.type; // console.log(tokeninfo); $scope.user = { name: '', password: '' }; //公用第三方登录返回处理 var thirdCommonLogin = function (response) { var tempuser = angular.fromJson(response.gsonInfo); var tempwechat = {}; if (type == 2) { tempwechat = angular.fromJson(response.weChat); } else { tempwechat = response.qq; } $scope.hideLoadingToast(); if (tempuser.dataType == "21005") { //该用户名已被禁用 UtilService.showMess("用户名已被禁用"); } else if (tempuser.dataType == "21004") { //用户名或密码错误! UtilService.showMess("手机号密码错误"); } else if (tempuser.dataType == "21007") { UtilService.showMess("手机号已被绑定"); } else { UtilService.showMess("绑定成功"); localStorage.isUserBindWx = 1; localStorage.isUserFocusXW = 1; ConfigService.islogin = true; //存储用户信息--自动登录 /*var tempdate = UtilService.formatDate(); SqliteStorageService.deleteData("delete from userinfo"); var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : ""; var tempobj = { id: tempuser.user.userid, mobile: $scope.user.name, password: $scope.user.password, updatetime: tempdate.formattime2, access_token: tempwechat.access_token, refresh_token: refresh, openid: tempwechat.openid, type: type }; SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) { }, function (err) { });*/ ConfigService.isedit = 1; //保存用户信息 UserService.user = tempuser.user; UserService.id = tempuser.user.userid; //UserService.node = tempuser.user.comefrom; UserService.role = tempuser.user.userRoleList; $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // UserService.viplevel = tempuser.member.memberid; // ConfigService.mychannellist = tempuser.channelList; ConfigService.comefrom = tempuser.user.comefrom; $ionicHistory.clearCache(); // $scope.go("tab.activityIndex"); // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) $state.reload(); if ($scope.app) { $ionicHistory.goBack(-2); } else { $scope.goback(); } //$scope.go("tab.account"); } }; $scope.readCommit = false; $scope.readCommition = function () { $scope.readCommit = !$scope.readCommit; }; //微信请求后台登录 $scope.wechatReqLogin = function () { $scope.showLoadingToast(); if ($stateParams.comfrom == 'maincontroller') { var params = JSON.parse($stateParams.params); params.mobile = $scope.user.name; params.password = $scope.user.password; // var url=window.location.href.split('#/')[1]; // console.log(url); LoginService.wechatUserAdd(params).then(function (res) { if (res.code == 3350) { ConfigService.islogin = true; $scope.islogin = true; localStorage.setItem("mobile", params.mobile); //存储密码用作自动登录 localStorage.setItem("password", params.password); UserService.id = res.data; AccountService.getUserInfo().then(function (response) { UserService.user = response.data; UserService.role = response.data.userRoleList; // var url = $stateParams.url.replace('/', '.'); // $scope.hideLoadingToast(); // $scope.go(url); $state.reload(); if ($scope.app) { $ionicHistory.goBack(-2); } else { $scope.goback(); } }); } else { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess(res.message); } else { CommonService.showMessage(res.message, $scope); } } }) } else { if (type == 2) { LoginService.wxLogin(tokeninfo, $scope.user.name, $scope.user.password).then(function (response) { thirdCommonLogin(response.data); }, function () { $scope.hideLoadingToast(); }); } else { LoginService.QQLogin(tokeninfo, $scope.user.name, $scope.user.password).then(function (response) { thirdCommonLogin(response); }, function () { $scope.hideLoadingToast(); }) } } }; $scope.hideModel = function () { $scope.goback() } });