PersonalVC.m 22 KB

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