setNameCtrl.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. angular.module('push')
  2. //设置用户名
  3. .controller('SetNameCtrl', function ($scope, AccountService, UtilService, $timeout, $ionicActionSheet, ConstantService,CommonService,
  4. UserService, $stateParams, $ionicHistory, ConfigService, LoginService, SqliteStorageService,$state) {
  5. $scope.user = {userName: ''};
  6. $scope.greeting = "用户名2-15个字以内";
  7. $scope.Username = "用户名是必须的";
  8. $scope.useravater = "img/Set_head.png";
  9. $scope.inputuser = {
  10. userid: $stateParams.userid,
  11. username: $scope.user.userName,
  12. photo: "",
  13. comefrom: localStorage.node
  14. };
  15. //先储存用户名,再跳转到个人中心
  16. $scope.setName = function () {
  17. $scope.showLoadingToast();
  18. // 需再取一次设置的用户名
  19. $scope.inputuser.username = $scope.user.userName;
  20. console.log($scope.inputuser);
  21. AccountService.setuserName($scope.inputuser).then(function (response) {
  22. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  23. if($scope.app){
  24. UtilService.showMess("设置昵称成功!");
  25. }else{
  26. CommonService.showMessage('设置昵称成功',$scope);
  27. }
  28. $timeout(function () {
  29. login();
  30. }, 100);
  31. }
  32. $scope.hideLoadingToast();
  33. }, function () {
  34. $scope.hideLoadingToast();
  35. if($scope.app){
  36. UtilService.showMess("网络不给力,请重试!");
  37. }else{
  38. CommonService.showMessage('网络不给力,请重试!',$scope);
  39. }
  40. });
  41. };
  42. //登录
  43. var login = function () {
  44. LoginService.login($stateParams.username, $stateParams.userpwd).then(function (response) {
  45. $scope.hideLoadingToast();
  46. if (response.code == ConstantService.STATUS_TYPE_21002) {
  47. //未注册
  48. if($scope.app){
  49. UtilService.showMess(response.message);
  50. }else{
  51. CommonService.showMessage(response.message,$scope);
  52. }
  53. } else if (response.code == ConstantService.STATUS_TYPE_21004) {
  54. //用户名或密码错误!
  55. if($scope.app){
  56. UtilService.showMess(response.message);
  57. }else{
  58. CommonService.showMessage(response.message,$scope);
  59. }
  60. } else if (response.code == ConstantService.STATUS_TYPE_21005) {
  61. //该用户名已被禁用
  62. if($scope.app){
  63. UtilService.showMess(response.message);
  64. }else{
  65. CommonService.showMessage(response.message,$scope);
  66. }
  67. } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  68. // if($scope.app){
  69. // UtilService.showMess(ConstantService.MESSAGE_TYPE_21000);
  70. // }else{
  71. // CommonService.showMessage(response.message,$scope);
  72. // }
  73. ConfigService.islogin = true;
  74. //$scope.selCom.hide();
  75. //存储用户信息--自动登录
  76. /*var tempdate = UtilService.formatDate();
  77. var del_sql = "delete from userinfo";
  78. SqliteStorageService.deleteData(del_sql);
  79. SqliteStorageService.insertSingleData("userinfo", {
  80. id: response.data.userid,
  81. mobile: $scope.user.name,
  82. password: $scope.user.password,
  83. updatetime: tempdate.formattime2,
  84. type: 1
  85. });*/
  86. //保存用户信息
  87. UserService.user = response.data;
  88. UserService.id = response.data.userid;
  89. UserService.node = response.data.comefrom;
  90. UserService.role = response.data.userRoleList;//角色
  91. if($scope.app){
  92. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  93. }//获取用户cliendif、订阅主题信息
  94. // UserService.viplevel = response.member.memberid;
  95. // ConfigService.mychannellist = response.channelList;
  96. ConfigService.comefrom = response.data.comefrom;
  97. $ionicHistory.clearCache();
  98. // $scope.go("tab.activityIndex");
  99. // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  100. // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  101. $ionicHistory.goBack(-3);
  102. //$scope.go("tab.account");
  103. // $scope.go("chooseNodeIndex",{comefrom:'tab.account'});
  104. }
  105. }, function () {
  106. if($scope.app){
  107. UtilService.showMess("网络不给力,请重试");
  108. }else{
  109. CommonService.showMessage('网络不给力,请重试!',$scope);
  110. }
  111. });
  112. };
  113. // 编辑头像
  114. $scope.show_header = function () {
  115. var buttons=[];
  116. if($scope.app){
  117. buttons=[
  118. {text: "拍照"},
  119. {text: "从相册上传"}
  120. ]
  121. }else{
  122. buttons=[
  123. {text: "从相册上传"}
  124. ]
  125. }
  126. // 弹出头像选择框
  127. $ionicActionSheet.show({
  128. cancelOnStateChange: true,
  129. cssClass: 'action_s',
  130. buttons: buttons,
  131. buttonClicked: function (index) {
  132. if($scope.app){
  133. if (index == 0) {
  134. openCamera(1,1);
  135. } else {
  136. openCamera(0,1);
  137. }
  138. }else {
  139. if (index == 0) {
  140. var files = document.getElementById('file');
  141. files.click();
  142. $(files).unbind().on('change', function (e) {
  143. var data = new FormData();
  144. data.append('file', e.target.files[0]);
  145. // $scope.fatherdata.detailList[$scope.imgIndex].imagelist.push();
  146. CommonService.webUploadImage(data).then(function (res) {
  147. $scope.useravater = $scope.imgUrl + $scope.avaterPath + res.photoName;
  148. $scope.inputuser.photo = res.photoName;
  149. })
  150. })
  151. }
  152. }
  153. return true;
  154. },
  155. destructiveText: "取消",
  156. destructiveButtonClicked: function () {
  157. return true;
  158. }
  159. });
  160. };
  161. var openCamera = function (srcType) {
  162. var options = {
  163. // Some common settings are 20, 50, and 100
  164. quality: 50,
  165. destinationType: Camera.DestinationType.FILE_URI,
  166. // In this app, dynamically set the picture source, Camera or photo gallery
  167. sourceType: srcType,
  168. encodingType: Camera.EncodingType.JPEG,
  169. mediaType: Camera.MediaType.PICTURE,
  170. allowEdit: false,
  171. correctOrientation: true, //Corrects Android orientation quirks
  172. saveToPhotoAlbum: true
  173. };
  174. navigator.camera.getPicture(function (imageData) {
  175. $scope.imgurl = imageData;
  176. $scope.showLoadingToast();
  177. UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) {
  178. $scope.useravater = $scope.imgUrl + $scope.avaterPath + response[0].photoName;
  179. $scope.inputuser.photo = response[0].photoName;
  180. $scope.hideLoadingToast();
  181. }, function () {
  182. $scope.hideLoadingToast();
  183. if($scope.app){
  184. UtilService.showMess("网络不给力,请重试!");
  185. }else{
  186. CommonService.showMessage('网络不给力,请重试!',$scope);
  187. }
  188. });
  189. }, function (message) {
  190. }, options);
  191. };
  192. });