angular.module('push') //设置用户名 .controller('SetNameCtrl', function ($scope, AccountService, UtilService, $timeout, $ionicActionSheet, ConstantService,CommonService, UserService, $stateParams, $ionicHistory, ConfigService, LoginService, SqliteStorageService,$state) { $scope.user = {userName: ''}; $scope.greeting = "用户名2-15个字以内"; $scope.Username = "用户名是必须的"; $scope.useravater = "img/Set_head.png"; $scope.inputuser = { userid: $stateParams.userid, username: $scope.user.userName, photo: "", comefrom: localStorage.node }; //先储存用户名,再跳转到个人中心 $scope.setName = function () { $scope.showLoadingToast(); // 需再取一次设置的用户名 $scope.inputuser.username = $scope.user.userName; console.log($scope.inputuser); AccountService.setuserName($scope.inputuser).then(function (response) { if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { if($scope.app){ UtilService.showMess("设置昵称成功!"); }else{ CommonService.showMessage('设置昵称成功',$scope); } $timeout(function () { login(); }, 100); } $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if($scope.app){ UtilService.showMess("网络不给力,请重试!"); }else{ CommonService.showMessage('网络不给力,请重试!',$scope); } }); }; //登录 var login = function () { LoginService.login($stateParams.username, $stateParams.userpwd).then(function (response) { $scope.hideLoadingToast(); if (response.code == ConstantService.STATUS_TYPE_21002) { //未注册 if($scope.app){ UtilService.showMess(response.message); }else{ CommonService.showMessage(response.message,$scope); } } else if (response.code == ConstantService.STATUS_TYPE_21004) { //用户名或密码错误! if($scope.app){ UtilService.showMess(response.message); }else{ CommonService.showMessage(response.message,$scope); } } else if (response.code == ConstantService.STATUS_TYPE_21005) { //该用户名已被禁用 if($scope.app){ UtilService.showMess(response.message); }else{ CommonService.showMessage(response.message,$scope); } } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { // if($scope.app){ // UtilService.showMess(ConstantService.MESSAGE_TYPE_21000); // }else{ // CommonService.showMessage(response.message,$scope); // } ConfigService.islogin = true; //$scope.selCom.hide(); //存储用户信息--自动登录 /*var tempdate = UtilService.formatDate(); var del_sql = "delete from userinfo"; SqliteStorageService.deleteData(del_sql); SqliteStorageService.insertSingleData("userinfo", { id: response.data.userid, mobile: $scope.user.name, password: $scope.user.password, updatetime: tempdate.formattime2, type: 1 });*/ //保存用户信息 UserService.user = response.data; UserService.id = response.data.userid; UserService.node = response.data.comefrom; UserService.role = response.data.userRoleList;//角色 if($scope.app){ $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 }//获取用户cliendif、订阅主题信息 // UserService.viplevel = response.member.memberid; // ConfigService.mychannellist = response.channelList; ConfigService.comefrom = response.data.comefrom; $ionicHistory.clearCache(); // $scope.go("tab.activityIndex"); // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) $ionicHistory.goBack(-3); //$scope.go("tab.account"); // $scope.go("chooseNodeIndex",{comefrom:'tab.account'}); } }, function () { if($scope.app){ UtilService.showMess("网络不给力,请重试"); }else{ CommonService.showMessage('网络不给力,请重试!',$scope); } }); }; // 编辑头像 $scope.show_header = function () { var buttons=[]; if($scope.app){ buttons=[ {text: "拍照"}, {text: "从相册上传"} ] }else{ buttons=[ {text: "从相册上传"} ] } // 弹出头像选择框 $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', buttons: buttons, buttonClicked: function (index) { if($scope.app){ if (index == 0) { openCamera(1,1); } else { openCamera(0,1); } }else { if (index == 0) { var files = document.getElementById('file'); files.click(); $(files).unbind().on('change', function (e) { var data = new FormData(); data.append('file', e.target.files[0]); // $scope.fatherdata.detailList[$scope.imgIndex].imagelist.push(); CommonService.webUploadImage(data).then(function (res) { $scope.useravater = $scope.imgUrl + $scope.avaterPath + res.photoName; $scope.inputuser.photo = res.photoName; }) }) } } return true; }, destructiveText: "取消", destructiveButtonClicked: function () { return true; } }); }; var openCamera = function (srcType) { var options = { // Some common settings are 20, 50, and 100 quality: 50, destinationType: Camera.DestinationType.FILE_URI, // In this app, dynamically set the picture source, Camera or photo gallery sourceType: srcType, encodingType: Camera.EncodingType.JPEG, mediaType: Camera.MediaType.PICTURE, allowEdit: false, correctOrientation: true, //Corrects Android orientation quirks saveToPhotoAlbum: true }; navigator.camera.getPicture(function (imageData) { $scope.imgurl = imageData; $scope.showLoadingToast(); UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) { $scope.useravater = $scope.imgUrl + $scope.avaterPath + response[0].photoName; $scope.inputuser.photo = response[0].photoName; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if($scope.app){ UtilService.showMess("网络不给力,请重试!"); }else{ CommonService.showMessage('网络不给力,请重试!',$scope); } }); }, function (message) { }, options); }; });