editDataCtrl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. angular.module('push')
  2. .controller('EditDataCtrl', function ($scope, $ionicPopup, $ionicActionSheet, $stateParams, AccountService, UtilService, UserService, AreaService, ConfigService, $ionicHistory) {
  3. //TODO
  4. if($scope.app){
  5. $scope.setStatusBar(0);
  6. }
  7. $scope.userInfo = UserService.user.user;
  8. if ($scope.userInfo.orgType == 1) {
  9. $scope.orgname = '企业';
  10. }
  11. if ($scope.userInfo.orgType == 2) {
  12. $scope.orgname = '学校';
  13. }
  14. // 编辑头像
  15. $scope.show_header = function () {
  16. // 弹出头像选择框
  17. $ionicActionSheet.show({
  18. cancelOnStateChange: true,
  19. cssClass: 'action_s',
  20. cancelText: '取消',
  21. buttons: [
  22. {text: "拍照"},
  23. {text: "从相册上传"}
  24. ],
  25. buttonClicked: function (index) {
  26. if (index == 0) {
  27. openCamera(1);
  28. } else {
  29. openCamera(0);
  30. }
  31. return true;
  32. },
  33. destructiveButtonClicked: function () {
  34. return true;
  35. }
  36. });
  37. };
  38. var openCamera = function (srcType) {
  39. var options = {
  40. // Some common settings are 20, 50, and 100
  41. quality: 50,
  42. destinationType: Camera.DestinationType.FILE_URI,
  43. // In this app, dynamically set the picture source, Camera or photo gallery
  44. sourceType: srcType,
  45. encodingType: Camera.EncodingType.JPEG,
  46. mediaType: Camera.MediaType.PICTURE,
  47. allowEdit: false,
  48. correctOrientation: true //Corrects Android orientation quirks
  49. };
  50. navigator.camera.getPicture(function (imageData) {
  51. $scope.imgurl = imageData;
  52. $scope.showLoadingToast();
  53. UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) {
  54. AccountService.setuserName(response[0].userPhoto, 3).then(function (res) {
  55. $scope.userInfo.photo = res.photo;
  56. UserService.user.user.photo = res.photo;
  57. }, function () {
  58. });
  59. $scope.hideLoadingToast();
  60. }, function () {
  61. $scope.hideLoadingToast();
  62. });
  63. }, function (message) {
  64. }, options);
  65. };
  66. $scope.user = {
  67. oldpwd: "",
  68. newpwd: "",
  69. twopwd: ""
  70. };
  71. //修改密码
  72. $scope.updatepwd = function () {
  73. if ($scope.user.oldpwd == "") {
  74. UtilService.showMess("旧密码不能为空!");
  75. } else if ($scope.user.newpwd == "") {
  76. UtilService.showMess("新密码不能为空!");
  77. } else if ($scope.user.newpwd.length < 6 || $scope.user.newpwd.length > 20) {
  78. UtilService.showMess("请输入6-20位英文数字组合的新密码!");
  79. } else if ($scope.user.twopwd == "") {
  80. UtilService.showMess("重复密码不能为空!");
  81. } else if ($scope.user.twopwd.length < 6 || $scope.user.twopwd.length > 20) {
  82. UtilService.showMess("请输入6-20位英文数字组合的重复密码!");
  83. } else {
  84. if ($scope.user.newpwd != $scope.user.twopwd) {
  85. UtilService.showMess("两次密码不同!");
  86. } else {
  87. $scope.showLoadingToast();
  88. AccountService.setuserPwd($scope.user.oldpwd, $scope.user.newpwd, 2).then(function (response) {
  89. if (response.status) {
  90. UtilService.showMess("恭喜,修改密码成功!");
  91. logout();
  92. } else {
  93. UtilService.showMess("旧密码输入错误!");
  94. }
  95. $scope.hideLoadingToast();
  96. }, function (response) {
  97. $scope.hideLoadingToast();
  98. });
  99. }
  100. }
  101. };
  102. //退出登录
  103. var logout = function () {
  104. ConfigService.islogin = false;
  105. UserService.user = {};
  106. UserService.id = "0";
  107. ConfigService.comefrom = "320412000";
  108. $ionicHistory.clearCache();
  109. $scope.go('tab.account');
  110. };
  111. // 编辑用户名
  112. $scope.showPopup = function () {
  113. $scope.data = {
  114. name: $scope.userInfo.userName
  115. };
  116. // 调用$ionicPopup弹出编辑用户名
  117. var myShow = $ionicPopup.show({
  118. template: "<div style='height:74px;'>" +
  119. "<input type='text' maxlength='15' ng-model='data.name' style='border-radius:4px;border:1px solid #e9e9ea;text-indent: 11px;'>" +
  120. "<span class='pop_subtitle'>2-15个字,支持中英文、数字</span>" +
  121. "</div>",
  122. title: "编辑用户名",
  123. scope: $scope,
  124. buttons: [
  125. {
  126. text: "取消"
  127. },
  128. {
  129. text: '<span class="pop_right_button">确认</span>',
  130. type: "button-positive",
  131. onTap: function (e) {
  132. if (!UtilService.isDefined($scope.data.name)) {
  133. UtilService.showMess("用户名不能为空");
  134. return $scope.data.name;
  135. }
  136. AccountService.setuserName($scope.data.name, 1);
  137. $scope.userInfo.userName = $scope.data.name;
  138. return $scope.data.name;
  139. }
  140. }
  141. ]
  142. })
  143. .then(function (res) {
  144. $scope.organizationName = [res].join(" ");
  145. });
  146. };
  147. // 编辑个性签名
  148. $scope.showSignature = function () {
  149. $scope.data = {
  150. intro: $scope.userInfo.intro
  151. };
  152. // 调用$ionicPopup弹出编辑个性签名
  153. $ionicPopup.show({
  154. template: "<div style='height:115px;'>" +
  155. "<textarea maxlength='126' rows='4' ng-model='data.intro' style='border-radius:5px;border:1px solid #e9e9ea;text-indent:11px;padding: 9px 4px 4px;'></textarea>" +
  156. "<span class='pop_subtitle'>126个字以内</span>" +
  157. "</div>",
  158. title: "编辑个性签名",
  159. scope: $scope,
  160. buttons: [
  161. {
  162. text: "取消"
  163. },
  164. {
  165. text: '<span class="pop_right_button">确认</span>',
  166. type: "button-positive",
  167. onTap: function (e) {
  168. if (!UtilService.isDefined($scope.data.intro)) {
  169. UtilService.showMess("个性签名不能为空");
  170. return $scope.data.intro;
  171. }
  172. AccountService.setuserName($scope.data.intro, 4);
  173. $scope.userInfo.intro = $scope.data.intro;
  174. return $scope.data.intro;
  175. }
  176. }
  177. ]
  178. })
  179. .then(function (res) {
  180. $scope.organizationBrief = [res].join(" ");
  181. });
  182. };
  183. // 编辑机构名
  184. $scope.show_org = function () {
  185. $scope.data = {
  186. orgName: $scope.userInfo.orgName
  187. };
  188. // 调用$ionicPopup弹出编辑机构名
  189. $ionicPopup.show({
  190. template: "<div style='height:90px;'>" +
  191. "<input type='text' maxlength='13' ng-model='data.orgName' style='border-radius:4px;border:1px solid #e9e9ea;text-indent:11px;'>" +
  192. "<span class='pop_subtitle'>13个字以内</span>" +
  193. "</div>",
  194. title: "编辑机构名",
  195. scope: $scope,
  196. buttons: [
  197. {
  198. text: "取消"
  199. },
  200. {
  201. text: '<span class="pop_right_button">确认</span>',
  202. type: "button-positive",
  203. onTap: function (e) {
  204. AccountService.setuserName($scope.data.orgName, 5);
  205. $scope.userInfo.orgName = $scope.data.orgName;
  206. return $scope.data.orgName;
  207. }
  208. }
  209. ]
  210. })
  211. .then(function (res) {
  212. $scope.organizationBrief = [res].join(" ");
  213. });
  214. };
  215. // 编辑机构类型
  216. $scope.show_style = function () {
  217. $scope.data = {
  218. orgType: $scope.userInfo.orgType
  219. };
  220. // 调用$ionicPopup弹出编辑机构类型
  221. $ionicPopup.show({
  222. template: "<div>" +
  223. " <label class='style_p'>" +
  224. "<input type='radio' ng-model='data.orgType' value='1'/>" +
  225. "企业" +
  226. "</label> " +
  227. "<label class='style_p'>" +
  228. "<input type='radio' ng-model='data.orgType' value='2' />" +
  229. "学校" +
  230. "</label>" +
  231. "</div>",
  232. title: "编辑机构类型",
  233. scope: $scope,
  234. buttons: [
  235. {
  236. text: "取消"
  237. },
  238. {
  239. text: '<span class="pop_right_button">确认</span>',
  240. type: "button-positive",
  241. onTap: function (e) {
  242. AccountService.setuserName($scope.data.orgType, 6);
  243. $scope.userInfo.orgType = $scope.data.orgType;
  244. if ($scope.userInfo.orgType == 1) {
  245. $scope.orgname = '企业';
  246. }
  247. if ($scope.userInfo.orgType == 2) {
  248. $scope.orgname = '学校';
  249. }
  250. return $scope.data.orgType;
  251. }
  252. }
  253. ]
  254. })
  255. .then(function (res) {
  256. $scope.organizationBrief = [res].join(" ");
  257. });
  258. };
  259. // 编辑联系人
  260. $scope.show_link = function () {
  261. $scope.data = {
  262. linkman: $scope.userInfo.linkman
  263. };
  264. // 调用$ionicPopup弹出编辑联系人
  265. $ionicPopup.show({
  266. template: "<div style='height:90px;'>" +
  267. "<input type='text' maxlength='5' ng-model='data.linkman' style='border-radius:4px;border:1px solid #e9e9ea;text-indent:11px;'>" +
  268. "<span class='pop_subtitle'>5个字以内</span>" +
  269. "</div>",
  270. title: "编辑联系人",
  271. scope: $scope,
  272. buttons: [
  273. {
  274. text: "取消"
  275. },
  276. {
  277. text: '<span class="pop_right_button">确认</span>',
  278. type: "button-positive",
  279. onTap: function (e) {
  280. AccountService.setuserName($scope.data.linkman, 8);
  281. $scope.userInfo.linkman = $scope.data.linkman;
  282. return $scope.data.linkman;
  283. }
  284. }
  285. ]
  286. })
  287. .then(function (res) {
  288. $scope.organizationBrief = [res].join(" ");
  289. });
  290. };
  291. // 编辑联系电话
  292. $scope.show_tel = function () {
  293. $scope.data = {
  294. contactNumber: $scope.userInfo.contactNumber
  295. };
  296. // 调用$ionicPopup弹出编辑联系电话
  297. $ionicPopup.show({
  298. template: "<div style='height:75px;'>" +
  299. "<input type='number' maxlength='13' ng-model='data.contactNumber' style='border-radius:4px;border:1px solid #e9e9ea;text-indent:11px;'>" +
  300. "<span class='pop_subtitle'>请输入正确手机号或固定电话,固定电话请加区号</span>" +
  301. "</div>",
  302. title: "编辑联系电话",
  303. scope: $scope,
  304. buttons: [
  305. {
  306. text: "取消"
  307. },
  308. {
  309. text: '<span class="pop_right_button">确认</span>',
  310. type: "button-positive",
  311. onTap: function (e) {
  312. AccountService.setuserName($scope.data.contactNumber, 9);
  313. $scope.userInfo.contactNumber = $scope.data.contactNumber;
  314. return $scope.data.contactNumber;
  315. }
  316. }
  317. ]
  318. })
  319. .then(function (res) {
  320. $scope.organizationBrief = [res].join(" ");
  321. });
  322. };
  323. // 编辑联系邮箱
  324. $scope.show_email = function () {
  325. $scope.data = {
  326. contactEmail: $scope.userInfo.contactEmail
  327. };
  328. // 调用$ionicPopup弹出编辑联系邮箱
  329. $ionicPopup.show({
  330. template: "<div style='height:75px;'>" +
  331. "<input type='email' maxlength='26' ng-model='data.contactEmail' style='border-radius:4px;border:1px solid #e9e9ea;text-indent:11px;'>" +
  332. "<span class='pop_subtitle'>请输入正确邮箱,包含@.元素</span>" +
  333. "</div>",
  334. title: "编辑联系邮箱",
  335. scope: $scope,
  336. buttons: [
  337. {
  338. text: "取消"
  339. },
  340. {
  341. text: '<span class="pop_right_button">确认</span>',
  342. type: "button-positive",
  343. onTap: function (e) {
  344. AccountService.setuserName($scope.data.contactEmail, 9);
  345. $scope.userInfo.contactEmail = $scope.data.contactEmail;
  346. return $scope.data.contactEmail;
  347. }
  348. }
  349. ]
  350. })
  351. .then(function (res) {
  352. $scope.organizationBrief = [res].join(" ");
  353. });
  354. };
  355. //修改简介
  356. $scope.editIntro = function () {
  357. AccountService.setuserName($scope.intro, 10).then(function (response) {
  358. }, function () {
  359. });
  360. };
  361. if (angular.isDefined(AreaService.cityid) && AreaService.cityid.length > 0) {
  362. AccountService.setuserName(AreaService.cityid, 7).then(function (response) {
  363. $scope.userInfo.region = AreaService.cityname;
  364. AreaService.cityid = "";
  365. AreaService.cityname = "";
  366. }, function () {
  367. });
  368. }
  369. if (angular.isDefined(AreaService.infobook) && AreaService.infobook.length > 0) {
  370. AccountService.setuserName(AreaService.infobook, 10).then(function (response) {
  371. $scope.userInfo.data = AreaService.infobook;
  372. AreaService.infobook = "";
  373. }, function () {
  374. });
  375. }
  376. $scope.goProvince = function () {
  377. ConfigService.cityflg = 2;
  378. $scope.go('chooseProvince');
  379. };
  380. //显示二维码
  381. $scope.showMyMessage = function () {
  382. $(".fixedTwo").css("display", "block");
  383. };
  384. //隐藏二维码
  385. $scope.hiddenTwoCode = function () {
  386. $(".fixedTwo").css("display", "none");
  387. };
  388. });