PersonalVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. //
  2. // PersonalVC.m
  3. // JSJPCoach
  4. //
  5. // Created by apple on 2017/3/20.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "PersonalVC.h"
  9. #import "LoginVC.h"
  10. #import "MyMsgVC.h"
  11. #import "commentVC.h"
  12. #import "Tools.h"
  13. #import "BindVC.h"
  14. @interface PersonalVC ()<InputViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIAlertViewDelegate>
  15. {
  16. UILabel *nameLabel, *carTypeLabel, *schoollabel, *cardNumLabel;
  17. UIImageView *imgHead;
  18. UIButton *btnTel, *btnAddr, *loginBtn;
  19. InputView *inputVi;
  20. UITextField *psw1;
  21. UITextField *psw2;
  22. UITextField *RegistField;
  23. NSString *password;
  24. CGFloat _scrHeight;
  25. }
  26. @end
  27. @implementation PersonalVC
  28. -(instancetype)initWithScrFrame:(CGRect)frame{
  29. if (self = [super init]) {
  30. _scrHeight = frame.size.height;
  31. self.view.frame = frame;
  32. }
  33. return self;
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. [self myInit];
  38. }
  39. -(void)viewWillAppear:(BOOL)animated
  40. {
  41. [super viewWillAppear:animated];
  42. [self refreshUI];
  43. };
  44. -(void)myInit
  45. {
  46. NSString *str;
  47. CGFloat x,y,w,h,bd;
  48. NSInteger tag = 1;
  49. bd = 15;
  50. x = y = 0;
  51. w = kSize.width;
  52. h = _scrHeight;
  53. UIScrollView *sv = [[UIScrollView alloc] setxywh];
  54. [sv setShowsVerticalScrollIndicator:YES];
  55. [self.view addSubview:sv];
  56. h = bd*2 + 80 + 30+30;
  57. UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  58. [sv addSubview:vi];
  59. UIImageView* iv;
  60. y += bd;
  61. w = h = 70;
  62. x += bd;
  63. iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  64. iv.layer.cornerRadius = iv.height*.5;
  65. iv.layer.masksToBounds = YES;
  66. [iv setContentMode:UIViewContentModeScaleAspectFill];
  67. str = defUser.userDict[@"photo"];
  68. if (!str || [str isEqualToString:@""]) {
  69. [iv setImage:[[UIImage imageNamed:@"noHeadImg.png"] tint:[UIColor whiteColor]]];
  70. }else{
  71. if (![str hasPrefix:@"http"]){
  72. str = [imgPreFix stringByAppendingString:str];
  73. }
  74. [iv sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]];
  75. }
  76. [sv addSubview:iv];
  77. imgHead = iv;
  78. x += w + bd;
  79. w = kSize.width - w;
  80. UILabel* label;
  81. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  82. [label setText:defUser.userDict[@"name"] Font:Font21 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  83. [sv addSubview:label];
  84. nameLabel = label;
  85. x = 0;
  86. w = kSize.width;
  87. UIButton* btn;
  88. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y - bd, w, h + bd)];
  89. [btn target:self Tag:tag++];
  90. [sv addSubview:btn];
  91. y += h + bd;
  92. h = 30;
  93. w = kSize.width/3.0;
  94. NSArray* arr = @[@"准教车型",@"所属驾校",@"职业资格证号"];
  95. for (int i=0; i < arr.count; i++) {
  96. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  97. [label setText:arr[i] Font:Font14 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  98. [sv addSubview:label];
  99. x += w;
  100. }
  101. NSString *teachCarType = defUser.userDict[@"teachCarType"];
  102. if (!teachCarType) {
  103. teachCarType = @"";
  104. }
  105. NSString *schoolName = defUser.userDict[@"schoolName"];
  106. if (!schoolName) {
  107. schoolName = @"";
  108. }
  109. NSString *occupationNO = defUser.userDict[@"occupationNO"];
  110. if (!occupationNO) {
  111. occupationNO = @"";
  112. }
  113. x = 0;
  114. y += h;
  115. w = kSize.width/3.0;
  116. h = 44;
  117. NSMutableArray *labelArray = [NSMutableArray arrayWithCapacity:3];
  118. arr = @[teachCarType,schoolName,occupationNO];
  119. for (int i=0; i < arr.count; i++) {
  120. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  121. [label setText:arr[i] Font:Font14 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  122. [label setNumberOfLines:0];
  123. [sv addSubview:label];
  124. x += w;
  125. [labelArray addObject:label];
  126. // label.height = [label.text heightForWid:w Font:Font14];
  127. }
  128. carTypeLabel = (UILabel *)labelArray[0];
  129. schoollabel = (UILabel *)labelArray[1];
  130. cardNumLabel = (UILabel *)labelArray[2];
  131. [label addViewWithRect:CGRectMake(w - 1, y - 25, 1, h + 25) Color:newBackGroundColor];
  132. [label addViewWithRect:CGRectMake(2*w, y - 25, 1, h + 25) Color:newBackGroundColor];
  133. UIColor *customLineColor = newBackGroundColor;
  134. x = bd;
  135. y += h+10;
  136. w = kSize.width-bd*2-45;
  137. h = 50;
  138. btn = [[UIButton alloc] setxywh];
  139. [btn setPersonalImage:[UIImage imageNamed:@"phone.png"] Tit:defUser.userDict[@"mobile"] Font:Font16 State:UIControlStateNormal];
  140. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  141. [btn target:self Tag:tag++];//2
  142. btnTel= btn;
  143. [sv addSubview:btn];
  144. [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  145. y +=h + 2;
  146. btn = [[UIButton alloc] setxywh];
  147. [btn setPersonalImage:[UIImage imageNamed:@"address_icon.png"] Tit:defUser.userDict[@"address"] Font:Font16 State:UIControlStateNormal];
  148. [btn.titleLabel setNumberOfLines:0];
  149. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  150. [btn target:self Tag:tag++];//3
  151. [btn setEnabled:NO];
  152. [sv addSubview:btn];
  153. btnAddr = btn;
  154. [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  155. //我的消息 先放在主页显示
  156. y += h + 2;
  157. btn = [[UIButton alloc] setxywh];
  158. [btn setPersonalImage:[UIImage imageNamed:@"myNews.png"] Tit:@"我的消息" Font:Font16 State:UIControlStateNormal];
  159. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  160. [btn target:self Tag:10];
  161. [sv addSubview:btn];
  162. [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  163. y += h + 2;
  164. btn = [[UIButton alloc] setxywh];
  165. [btn setPersonalImage:[UIImage imageNamed:@"fixKey.png"] Tit:@"修改密码" Font:Font16 State:UIControlStateNormal];
  166. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  167. [btn target:self Tag:12];
  168. [sv addSubview:btn];
  169. [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  170. //我的评论
  171. y += h + 2;
  172. btn = [[UIButton alloc] setxywh];
  173. [btn setPersonalImage:[[UIImage imageNamed:@"myComment.png"] tint:[UIColor cyanColor]] Tit:@"学员评论" Font:Font16 State:UIControlStateNormal];
  174. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  175. [btn target:self Tag:11];
  176. [sv addSubview:btn];
  177. [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  178. // y += h;
  179. // btn = [[UIButton alloc] setxywh];
  180. // [btn setPersonalImage:[UIImage imageNamed:@"terminalRegist.png"] Tit:@"终端注册" Font:Font16 State:UIControlStateNormal];
  181. // [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  182. // [btn target:self Tag:13];
  183. // [sv addSubview:btn];
  184. // [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  185. //
  186. // y += h;
  187. // btn = [[UIButton alloc] setxywh];
  188. // [btn setPersonalImage:[UIImage imageNamed:@"terminalCancel.png"] Tit:@"终端注销" Font:Font16 State:UIControlStateNormal];
  189. // [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  190. // [btn target:self Tag:14];
  191. // [sv addSubview:btn];
  192. // [btn addViewWithRect:CGRectMake(x+45, y+h, w, 1) Color:customLineColor];
  193. y += h + 20;
  194. x = bd;
  195. w = kSize.width - bd*2;
  196. h = 50;
  197. btn = [[UIButton alloc] setxywh];
  198. [btn setTitle:@"退出登录" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  199. [btn setBackgroundColor:defGreen];
  200. [btn corner:h*.5];
  201. [btn target:self Tag:tag++];
  202. [sv addSubview:btn];
  203. loginBtn = btn;
  204. UIView* aView;
  205. aView = sv.subviews.lastObject;
  206. [sv setContentSize:CGSizeMake(kSize.width, aView.bottom + 20)];
  207. if (defUser.isLogin) {
  208. [self coachLogin];//判断登录是否过期
  209. // [self refreshUI];
  210. }
  211. }
  212. - (void)refreshUI
  213. {
  214. NSString *str = defUser.userDict[@"photo"];
  215. if (!str) {
  216. str = @"";
  217. }
  218. [imgHead sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]];
  219. nameLabel.text = defUser.userDict[@"name"];
  220. NSString *teachCarType = defUser.userDict[@"teachCarType"];
  221. if (!teachCarType) {
  222. teachCarType = @"";
  223. }
  224. carTypeLabel.text = teachCarType;
  225. NSString *schoolName = defUser.userDict[@"schoolName"];
  226. if (!schoolName) {
  227. schoolName = @"";
  228. }
  229. schoollabel.text = schoolName;
  230. NSString *occupationNO = defUser.userDict[@"occupationNO"];
  231. if (!occupationNO) {
  232. occupationNO = @"";
  233. }
  234. cardNumLabel.text = occupationNO;
  235. if (defUser.isLogin) {
  236. [loginBtn setTitle:@"退出登录" forState:UIControlStateNormal];
  237. }else{
  238. [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
  239. }
  240. [btnAddr setTitle:defUser.userDict[@"address"] forState:UIControlStateNormal];
  241. [btnTel setTitle:defUser.userDict[@"mobile"] forState:UIControlStateNormal];
  242. }
  243. /**如果这些按钮的事件。都有某些共同点。那么可以把他们指向同一个sel.
  244. 又或者这些按钮的事件都很简单,那么也可以指向同一个sel;
  245. 否则,还是不要比较好。
  246. */
  247. -(void)btnClick:(UIButton*)sender
  248. {
  249. if (!defUser.isLogin) {
  250. [LoginVC loginFromVC:self];
  251. return ;
  252. }
  253. int tag = (int)sender.tag;
  254. if (tag == 4 || tag == 13 || tag == 14) {
  255. if (myDelegate.isPeriodIng) {
  256. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"正在带教学员,不能进行此操作" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  257. [alert show];
  258. return;
  259. }
  260. }
  261. if (1 == tag) {
  262. InputView* vi = [[InputView alloc] initWithTitle:@"请选择头像"];
  263. [vi setDelegate:self];
  264. [vi show];
  265. inputVi = vi;
  266. return;
  267. }
  268. if (3 == tag) {
  269. //地址
  270. return;
  271. }
  272. if (4 == tag) {
  273. //退出登录
  274. if (!defUser.isLogin) {
  275. [LoginVC loginFromVC:self];
  276. return;
  277. }
  278. defUser.isLogin = NO;
  279. defUser.userDict = nil;
  280. [self refreshUI];
  281. ShowMsgSuc();
  282. return;
  283. }
  284. if (tag == 10) {
  285. //NSLog(@"我的消息");
  286. MyMsgVC *vc = [[MyMsgVC alloc] init];
  287. [vc.view setBackgroundColor:[UIColor whiteColor]];
  288. [self.navigationController pushViewController:vc animated:YES];
  289. return;
  290. }
  291. if (tag == 11) {
  292. //查看评论
  293. commentVC *vc = [[commentVC alloc] init];
  294. [vc.view setBackgroundColor:[UIColor whiteColor]];
  295. [self.navigationController pushViewController:vc animated:YES];
  296. return;
  297. }
  298. if (tag == 12) {
  299. [self fixKey];//修改密码
  300. return;
  301. }
  302. if (tag == 13) {
  303. // 取消判断IMEI
  304. // if ([defUser.userDict[@"imei"] length] < 1) {
  305. // //先绑定imei 然后才能终端注册
  306. //
  307. // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"您的账号还未绑定手机,绑定后当前手机只能用于当前帐号带教学员,绑定后可以进行终端注册操作" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去绑定", nil];
  308. // alert.tag = 21;
  309. // [alert show];
  310. //
  311. // }else{
  312. [self showRegistTextField];//终端注册
  313. // }
  314. }
  315. if (tag == 14) {
  316. UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"终端注销" message:@"终端注销后您的手机将不能继续带教学员,需要重新绑定并且终端注册后方可继续带教学员,确认注销?" preferredStyle:UIAlertControllerStyleAlert];
  317. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  318. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  319. [self doDeviceLogOut];//终端注销
  320. }]];
  321. [self presentViewController:alert animated:true completion:nil];
  322. }
  323. }
  324. #pragma mark - 终端注册
  325. - (void)showRegistTextField
  326. {
  327. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"手机注册" message:@"手机未注册为终端设备,请输入当前手机带练车辆的车牌号码完成注册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
  328. alert.alertViewStyle = UIAlertViewStylePlainTextInput;
  329. RegistField = [alert textFieldAtIndex:0];
  330. RegistField.placeholder = @"请输入车牌号码";
  331. alert.tag = 20;
  332. [alert show];
  333. }
  334. - (void)doDeviceReg
  335. {
  336. if (RegistField.text.length < 1) {
  337. ShowMsg(@"请输入车牌号码");
  338. [self showRegistTextField];
  339. return;
  340. }
  341. [LoadingView showHUD];
  342. if (![Util connectedToNetWork]) {
  343. showMsgUnconnect();
  344. return;
  345. }
  346. NSMutableArray *arr=[NSMutableArray array];
  347. [arr addPro:@"sim" Value:defUser.userDict[@"mobile"]];
  348. [arr addPro:@"licnum" Value:RegistField.text];
  349. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  350. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  351. NSString* method = @"doDeviceReg";
  352. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  353. RemoveHUD();
  354. if (!root) {
  355. ShowMsg(@"注册失败!");
  356. return ;
  357. }
  358. if ([root[@"code"] isEqualToString:@"1"]) {
  359. ShowMsg(root[@"body"]);
  360. return;
  361. }
  362. ShowMsg(@"注册成功!");
  363. reLogin();
  364. }];
  365. }
  366. #pragma mark - 终端注销
  367. -(void)doDeviceLogOut
  368. {
  369. [LoadingView showHUD];
  370. if (![Util connectedToNetWork]) {
  371. showMsgUnconnect();
  372. return;
  373. }
  374. NSMutableArray *arr=[NSMutableArray array];
  375. [arr addPro:@"sim" Value:defUser.userDict[@"mobile"]];
  376. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  377. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  378. NSString* method = @"doDeviceLogOut";
  379. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  380. RemoveHUD();
  381. if (!root) {
  382. ShowMsg(@"注销失败!");
  383. return ;
  384. }
  385. if ([root[@"code"] isEqualToString:@"1"]) {
  386. ShowMsg(root[@"body"]);
  387. return;
  388. }
  389. ShowMsg(@"注销成功!");
  390. }];
  391. }
  392. #pragma mark 修改密码
  393. -(void)fixKey
  394. {
  395. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"验证原密码" message:@"如果忘了原密码,请重新登录即可利用找回密码设置新密码" preferredStyle:UIAlertControllerStyleAlert];
  396. [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {
  397. textField.placeholder = @"密码";
  398. }];
  399. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  400. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  401. NSString *text = [[alert.textFields firstObject] text];
  402. NSString *key = defUser.userDict[@"initPwd"];
  403. if (password.length > 1) {
  404. key = password;
  405. }
  406. if (![text isEqualToString:key]) {
  407. ShowMsg(@"原密码错误!");
  408. return;
  409. }
  410. UIAlertView *alertKey = [[UIAlertView alloc] initWithTitle:@"修改密码" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认修改",nil];
  411. [alertKey setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
  412. alertKey.tag = 11;
  413. psw1 = [alertKey textFieldAtIndex:0];
  414. psw2 = [alertKey textFieldAtIndex:1];
  415. psw1.placeholder = @"请输入新密码";
  416. psw2.placeholder = @"请确认密码";
  417. [psw1 setSecureTextEntry:YES];
  418. [alertKey show];
  419. }]];
  420. [self presentViewController:alert animated:true completion:nil];
  421. }
  422. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  423. {
  424. if (alertView.tag == 1) {
  425. [LoginVC loginFromVC:self];
  426. }
  427. if (alertView.tag == 11) {
  428. if (buttonIndex == 1)
  429. {
  430. [self submit];
  431. }
  432. }else if (alertView.tag == 20){
  433. if (buttonIndex != alertView.cancelButtonIndex) {
  434. [self doDeviceReg];
  435. }
  436. }else if (alertView.tag == 21){
  437. if (buttonIndex != alertView.cancelButtonIndex) {
  438. //手机绑定
  439. BindVC *bindVC = [[BindVC alloc] init];
  440. [bindVC bindSuccessWithBlock:^{
  441. reLogin();
  442. }];
  443. [self.navigationController pushViewController:bindVC animated:YES];
  444. }
  445. }
  446. }
  447. -(void)submit
  448. {
  449. //NSLog(@"修改密码");
  450. if (![psw1.text isEqualToString:psw2.text])
  451. {
  452. dispatch_async(dispatch_get_main_queue(), ^{
  453. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"密码不一致,请您核查" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  454. [alert show];
  455. });
  456. return;
  457. }
  458. NSMutableArray *arr=[NSMutableArray array];
  459. [arr addPro:@"loginCode" Value:defUser.sfzmhm];
  460. [arr addPro:@"pwd" Value:psw1.text];
  461. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  462. NSString* method = @"saveCoachPwd";
  463. //NSLog(@"密码信息---->%@",arr);
  464. ShowHUD();
  465. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  466. if (!root)
  467. {
  468. ShowMsgFailed();
  469. return;
  470. }
  471. if ( 1 == [root[@"code"] integerValue]) {
  472. ShowMsgFailed();
  473. return;
  474. }
  475. ShowMsg(@"修改成功,请登录!");
  476. //此时的密码
  477. password = psw1.text;
  478. defUser.isLogin = NO;
  479. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:defUser.userDict];
  480. if ([[dic allKeys] containsObject:@"initPwd"]) {
  481. [dic setValue:@"" forKey:@"initPwd"];
  482. }
  483. defUser.userDict = dic;
  484. //跳到登陆页面
  485. [LoginVC loginFromVC:self];
  486. }];
  487. }
  488. #pragma mark 上传头像
  489. -(void)InputView:(InputView *)view didGetImage:(UIImage *)image
  490. {
  491. [self uploadCoachHeadImg:image];
  492. }
  493. -(void)InputViewWillPickImage:(InputView *)view
  494. {
  495. UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
  496. if([UIImagePickerController isSourceTypeAvailable:view.type]) {
  497. pickerImage.sourceType = view.type;
  498. pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
  499. }
  500. pickerImage.delegate = self;
  501. pickerImage.allowsEditing = NO;
  502. [self presentViewController:pickerImage animated:YES completion:nil];
  503. }
  504. - (void)imagePickerController:(UIImagePickerController *)picker
  505. didFinishPickingMediaWithInfo:(NSDictionary *)info
  506. {
  507. [inputVi cancelAction];
  508. [picker dismissViewControllerAnimated:YES completion:^{
  509. UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  510. [self uploadCoachHeadImg:image];
  511. }];
  512. }
  513. -(void)uploadCoachHeadImg:(UIImage*)image
  514. {
  515. if (![Util connectedToNetWork]) {
  516. showMsgUnconnect();
  517. return;
  518. }
  519. NSData *data = UIImagePNGRepresentation([image scaledToWid:100]);
  520. NSArray *dataArray = [NSArray arrayWithObject:data];
  521. ShowHUD();
  522. [jiaPeiManager requestAnythingWithURL:@"uploadUserImg" array:dataArray data:data completion:^(NSDictionary *root) {
  523. RemoveHUD();
  524. if (!root) {
  525. ShowMsg(@"上传失败");
  526. return;
  527. }
  528. if (![root[@"code"] isEqualToString:@"0"]) {
  529. ShowMsg(root[@"body"]);
  530. return;
  531. }
  532. ShowHUD();
  533. NSMutableArray *arr = [NSMutableArray array];
  534. [arr addPro:@"coachId" Value:defUser.userDict[@"id"]];
  535. [arr addPro:@"photo" Value:root[@"body"]];
  536. [jiaPeiManager requestAnythingWithURL:@"uploadHeadImg" array:arr data:nil completion:^(NSDictionary *root) {
  537. RemoveHUD();
  538. if (!root) {
  539. ShowMsg(@"上传失败");
  540. return;
  541. }
  542. ShowMsg(root[@"body"]);
  543. if (![root[@"code"] isEqualToString:@"0"]) {
  544. return;
  545. }
  546. //上传头像后 在获取下最新信息
  547. reLogin();
  548. imgHead.image = [UIImage imageWithData:data];
  549. }];
  550. }];
  551. }
  552. //更新登录信息
  553. -(void)coachLogin
  554. {
  555. if (![Util connectedToNetWork]) {
  556. showMsgUnconnect();
  557. return;
  558. }
  559. NSMutableArray *arr = [NSMutableArray array];
  560. [arr addPro:@"sfzhm" Value:defUser.sfzmhm];
  561. [arr addPro:@"pwd" Value:defUser.userDict[@"pwd"]];
  562. NSString* method = @"coachLogin";
  563. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  564. RemoveHUD();
  565. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  566. defUser.isLogin = NO;
  567. defUser.userDict = nil;
  568. UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"登录信息已过期,请重新登陆" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
  569. alert.tag = 1;
  570. [alert show];
  571. return;
  572. }
  573. //更新信息
  574. defUser.isLogin = YES;
  575. defUser.userDict = root[@"body"];
  576. [self refreshUI];
  577. //NSLog(@"----><>%@",defUser.userDict);
  578. }];
  579. }
  580. - (void)didReceiveMemoryWarning {
  581. [super didReceiveMemoryWarning];
  582. }
  583. @end