personVC.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //
  2. // personVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/5.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "personVC.h"
  9. #import "SelectHeadImgView.h"
  10. #import "LoginViewController.h"
  11. #import "AboutVC.h"
  12. #import <TOCropViewController.h>
  13. //客服
  14. #import "QMChatRoomViewController.h"
  15. #import <QMLineSDK/QMLineSDK.h>
  16. #import "QMAlert.h"
  17. #define PersonVCTop_H kStatusHeight+20
  18. #define PersonVCRate 1.0/(PersonVCTop_H+100-kNavOffSet)//100为透视图高度
  19. @interface personVC ()<UITableViewDataSource, UITableViewDelegate, SelectHeadImgViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
  20. {
  21. UITableView *mainTableView;
  22. UIImageView *headImg;
  23. UILabel *nameLabel;
  24. UILabel *schoolNamelabel;
  25. SelectHeadImgView *selectImgView;
  26. NSArray *titles;
  27. NSArray *imgArray;
  28. }
  29. @property(nonatomic,strong)UIView *topView;
  30. //客服
  31. @property (nonatomic, assign) BOOL isPushed; // 控制跳转
  32. @property (nonatomic, assign) BOOL isConnecting; // 控制多次注册
  33. @property (nonatomic, copy) NSDictionary * dictionary; //客服一些配置
  34. @end
  35. @implementation personVC
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.view.backgroundColor = [UIColor whiteColor];
  39. self.title = @"我的";
  40. //个人中心的头
  41. CGFloat x,y,w,h;
  42. x = 0;
  43. y = 0;
  44. w = kSize.width;
  45. h = PersonVCTop_H;
  46. _topView = [[UIView alloc] KSetxywh];
  47. _topView.backgroundColor = defGreen;
  48. [self.view addSubview:_topView];
  49. y+=h;
  50. h=117;
  51. UIView *headView = [[UIView alloc] KSetxywh];
  52. headView.backgroundColor = KBackGroundColor;
  53. y -= PersonVCTop_H;
  54. h = 100;
  55. UIView *view = [[UIView alloc] KSetxywh];
  56. view.backgroundColor = defGreen;
  57. [headView addSubview:view];
  58. x = y = 15;
  59. w = h = 70;
  60. UIImageView *imgView = [[UIImageView alloc] KSetxywh];
  61. [imgView setModeAspectFill];
  62. [imgView setRound];
  63. [view addSubview:imgView];
  64. headImg = imgView;
  65. UIButton *btn = [[UIButton alloc] KSetxywh];
  66. [btn addTarget:self action:@selector(changeHeadImg) forControlEvents:UIControlEventTouchUpInside];
  67. [view addSubview:btn];
  68. x += w + 10;
  69. y -= 5;
  70. w = kSize.width - x;
  71. h = 40;
  72. UILabel *label = [[UILabel alloc] KSetxywh];
  73. [label setText:@"欢迎您!" Font:Font18 TextColor:KTitleColor];
  74. [view addSubview:label];
  75. nameLabel = label;
  76. y += h;
  77. label = [[UILabel alloc] KSetxywh];
  78. [label setText:@"" Font:Font16 TextColor:KTitleColor];
  79. [view addSubview:label];
  80. schoolNamelabel = label;
  81. [self setPersonData];
  82. titles = @[@[@"修改头像",@"修改昵称"],@[@"修改密码",@"退出登录"],@[@"使用说明",@"关于",@"线上咨询"]];
  83. imgArray = @[@[@"center_img1",@"center_img2"],@[@"center_img3",@"center_img4"],@[@"center_img5",@"center_img6",@"center_img7"]];
  84. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, PersonVCTop_H, kSize.width, kSize.height) style:UITableViewStyleGrouped];
  85. mainTableView.height -= kTabBarHeight+PersonVCTop_H;
  86. [mainTableView setDelegate:self];
  87. [mainTableView setDataSource:self];
  88. // mainTableView.contentInset = UIEdgeInsetsMake(84, 0, 0, 0);
  89. [mainTableView setTableHeaderView:headView];
  90. [self.view addSubview:mainTableView];
  91. [self.view insertSubview:mainTableView belowSubview:_topView];
  92. [self setPersonData];
  93. //客服
  94. //客服
  95. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerSuccess:) name:CUSTOM_LOGIN_SUCCEED object:nil];
  96. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerFailure:) name:CUSTOM_LOGIN_ERROR_USER object:nil];
  97. _isConnecting = NO;
  98. _isPushed = NO;
  99. }
  100. - (void)viewWillAppear:(BOOL)animated {
  101. [super viewWillAppear:animated];
  102. _isPushed = NO;
  103. self.navigationController.navigationBar.translucent = YES;
  104. self.navigationController.navigationBar.alpha = 0;
  105. }
  106. - (void)viewWillDisappear:(BOOL)animated {
  107. [super viewWillDisappear:animated];
  108. _isPushed = YES;
  109. self.navigationController.navigationBar.alpha = 1.0;//这个5s测试去”关于“的时候不起作用。请参考关于didAppear
  110. }
  111. -(void)viewDidAppear:(BOOL)animated {
  112. [super viewDidAppear:animated];
  113. self.tabBarController.tabBar.hidden = NO;
  114. //刷新待办事项
  115. [self setPersonData];
  116. }
  117. - (void)setPersonData
  118. {
  119. NSString *imagePath = defUser.userDict[@"photo"];
  120. if (!imagePath) {
  121. imagePath = @"";
  122. }
  123. [headImg sd_setImageWithURL:[NSURL URLWithString:imagePath] placeholderImage:[UIImage imageNamed:@"headImg"]];
  124. NSString *nameString = @"欢迎您!";
  125. if ([defUser.userDict[@"realName"] length] > 0) {
  126. nameString = [NSString stringWithFormat:@"%@,欢迎您!",defUser.userDict[@"realName"]];
  127. }
  128. nameLabel.text = nameString;
  129. schoolNamelabel.text = defUser.userDict[@"schoolName"];
  130. }
  131. #pragma mark tableView
  132. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  133. {
  134. return titles.count;
  135. }
  136. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  137. {
  138. return [titles[section] count];
  139. }
  140. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  141. {
  142. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  143. if (cell == nil) {
  144. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  145. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  146. [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  147. }
  148. cell.imageView.image = [UIImage imageNamed:[imgArray[indexPath.section] objectAtIndex:indexPath.row]];
  149. cell.textLabel.text = [titles[indexPath.section] objectAtIndex:indexPath.row];
  150. return cell;
  151. }
  152. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  153. {
  154. if (indexPath.section == 0) {
  155. if (indexPath.row == 0) {
  156. //修改头像
  157. [self changeHeadImg];
  158. }else if (indexPath.row == 1) {
  159. //修改昵称
  160. [MBProgressHUD showAutoMessage:@"暂未开放"];
  161. }
  162. }else if (indexPath.section == 1) {
  163. if (indexPath.row == 0) {
  164. //修改密码
  165. [self fixKey];
  166. }else if (indexPath.row == 1) {
  167. //退出登录
  168. [self loginOut];
  169. }
  170. }else{
  171. if (indexPath.row == 0) {
  172. //使用说明
  173. [MBProgressHUD showAutoMessage:@"暂未开放"];
  174. }else if (indexPath.row == 1) {
  175. //关于
  176. AboutVC * vc = [[AboutVC alloc]init];
  177. [self navPushHideTabbarToVC:vc];
  178. }else if (indexPath.row == 2) {
  179. if (_isConnecting) {
  180. return;
  181. }
  182. _isConnecting = YES;
  183. [MBProgressHUD showLoadToView:self.view];
  184. // userId 只能使用 数字 字母(包括大小写) 下划线
  185. NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  186. NSString *name = [NSString stringWithFormat:@"%@[辽I驾校_%@]",defUser.userDict[@"realName"],version];
  187. [QMConnect registerSDKWithAppKey:CUSTOMERSERVICE_APPKEY userName:name userId:[NSString stringWithFormat:@"%@",defUser.userDict[@"id"]]];
  188. }
  189. }
  190. }
  191. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  192. //topview
  193. CGRect newFrame = self.topView.frame;
  194. CGFloat settingViewOffsetY = PersonVCTop_H - scrollView.contentOffset.y;
  195. newFrame.size.height = settingViewOffsetY;
  196. if (settingViewOffsetY < PersonVCTop_H) {
  197. newFrame.size.height = PersonVCTop_H;
  198. }
  199. self.topView.frame = newFrame;
  200. //navBar
  201. self.navigationController.navigationBar.alpha = PersonVCRate*scrollView.contentOffset.y;
  202. // NSLog(@"-->> %f", self.navigationController.navigationBar.alpha);
  203. }
  204. #pragma mark 修改密码
  205. -(void)fixKey
  206. {
  207. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"验证原密码" message:nil preferredStyle:UIAlertControllerStyleAlert];
  208. [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {
  209. textField.placeholder = @"请输入原密码";
  210. }];
  211. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  212. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  213. NSString *text = [[alert.textFields firstObject] text];
  214. NSString *key = defUser.userDict[@"password"];
  215. if (![[text md5Encrypt] isEqualToString:key]) {
  216. ShowMsg(@"原密码错误!");
  217. return;
  218. }
  219. [self willModifyPwd];
  220. }]];
  221. dispatch_async(dispatch_get_main_queue(), ^{
  222. [self.tabBarController presentViewController:alert animated:true completion:nil];
  223. });
  224. }
  225. -(void)willModifyPwd{
  226. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"修改密码" message:nil preferredStyle:UIAlertControllerStyleAlert];
  227. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  228. textField.placeholder = @"请输入新密码";
  229. textField.secureTextEntry = YES;
  230. }];
  231. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  232. textField.placeholder = @"请确认密码";
  233. textField.secureTextEntry = YES;
  234. }];
  235. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  236. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定修改" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  237. // 读取文本框的值显示出来
  238. UITextField *newtf1 = alertFind.textFields[0];
  239. UITextField *newtf = alertFind.textFields[1];
  240. if (newtf1.text.length < 6 || newtf.text.length < 6) {
  241. ShowMsg(@"密码长度不能少于6个字符");
  242. return;
  243. }
  244. if (![newtf1.text isEqualToString:newtf.text])
  245. {
  246. UIAlertController *noname = [UIAlertController alertControllerWithTitle:@"提示" message:@"密码不一致,请您核查" preferredStyle:UIAlertControllerStyleAlert];
  247. [noname addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  248. dispatch_async(dispatch_get_main_queue(), ^{
  249. [self.tabBarController presentViewController:noname animated:true completion:nil];
  250. });
  251. return;
  252. }
  253. [self chanagePasswordWithOldStr:defUser.userDict[@"password"] newStr:[newtf.text md5Encrypt]];
  254. }]];
  255. dispatch_async(dispatch_get_main_queue(), ^{
  256. [self.tabBarController presentViewController:alertFind animated:true completion:nil];
  257. });
  258. }
  259. -(void)chanagePasswordWithOldStr:(NSString *)oldpwd newStr:(NSString *)newpwd{
  260. NSMutableDictionary * mdic = [NSMutableDictionary new];
  261. [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"];
  262. [mdic setValue:oldpwd forKey:@"oldPwd"];
  263. [mdic setValue:newpwd forKey:@"newPwd"];
  264. [MBProgressHUD showLoadToView:self.view];
  265. [NetManager requestAnythingWithURL:@"modifyPwd" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  266. [MBProgressHUD hideHUDForView:self.view];
  267. if (!root) {
  268. ShowMsg(@"修改密码失败!");
  269. return;
  270. }
  271. if ([root[@"code"] isEqualToString:@"1"]) {
  272. ShowErrorMsg(root[@"msg"]);
  273. return;
  274. }
  275. ShowMsg(@"修改成功,请重新登录");
  276. [LoginViewController loginFromVC:self];
  277. }];
  278. }
  279. #pragma mark 上传头像
  280. - (void)changeHeadImg
  281. {
  282. selectImgView = [[SelectHeadImgView alloc] initWithTitle:@"请选择头像"];
  283. [selectImgView setDelegate:self];
  284. [selectImgView show];
  285. }
  286. -(void)SelectHeadImgView:(SelectHeadImgView *)view didGetImage:(UIImage*)image
  287. {
  288. [self cropImage:image];
  289. }
  290. -(void)SelectHeadImgWillPickImage:(SelectHeadImgView *)view
  291. {
  292. UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
  293. if([UIImagePickerController isSourceTypeAvailable:view.type]) {
  294. pickerImage.sourceType = view.type;
  295. pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
  296. }
  297. pickerImage.delegate = self;
  298. pickerImage.allowsEditing = NO;
  299. [self presentViewController:pickerImage animated:YES completion:nil];
  300. }
  301. - (void)imagePickerController:(UIImagePickerController *)picker
  302. didFinishPickingMediaWithInfo:(NSDictionary *)info
  303. {
  304. [selectImgView cancelAction];
  305. [picker dismissViewControllerAnimated:YES completion:^{
  306. UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  307. [self cropImage:image];
  308. }];
  309. }
  310. -(void)cropImage:(UIImage *)img
  311. {
  312. if (!img) {
  313. return;
  314. }
  315. TOCropViewController *cropController = [[TOCropViewController alloc] initWithCroppingStyle:TOCropViewCroppingStyleCircular image:img];
  316. __weak TOCropViewController *weakCropC = cropController;
  317. cropController.onDidCropToCircleImage = ^(UIImage * _Nonnull image, CGRect cropRect, NSInteger angle) {
  318. [weakCropC dismissViewControllerAnimated:YES completion:nil];
  319. [self uploadCoachHeadImg:image];
  320. };
  321. [self presentViewController:cropController animated:NO completion:nil];
  322. }
  323. -(void)uploadCoachHeadImg:(UIImage*)image
  324. {
  325. if (![NetManager connectedToNetWork]) {
  326. showMsgUnconnect();
  327. return;
  328. }
  329. NSData *data = UIImagePNGRepresentation([image scaledToWid:100]);
  330. NSString *imgString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  331. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  332. [dic setObject:imgString forKey:@"content"];
  333. [dic setObject:defUser.userDict[@"id"] forKey:@"keyword"];
  334. [dic setObject:@"1" forKey:@"type"];
  335. NSString *method = @"upload-1";
  336. [MBProgressHUD showLoadToView:self.view];
  337. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  338. [MBProgressHUD hideHUDForView:self.view];
  339. if (!root) {
  340. ShowMsg(@"上传头像失败!");
  341. return;
  342. }
  343. if ([root[@"code"] isEqualToString:@"1"]) {
  344. ShowErrorMsg(root[@"msg"]);
  345. return;
  346. }
  347. NSString *imgPath = root[@"body"];
  348. if (!imgPath) {
  349. imgPath = @"";
  350. }
  351. if ([imgPath length] > 0) {
  352. [headImg sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"headImg"]];
  353. }
  354. //上传头像成功
  355. [self schoolLogin];
  356. }];
  357. }
  358. - (void)schoolLogin
  359. {
  360. if (![NetManager connectedToNetWork]) {
  361. showMsgUnconnect();
  362. return;
  363. }
  364. NSString *systemName = [[UIDevice currentDevice] systemName];
  365. NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
  366. NSString *identifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
  367. NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  368. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  369. [dic setObject:defUser.userDict[@"loginCode"] forKey:@"loginCode"];
  370. [dic setObject:defUser.userDict[@"password"] forKey:@"password"];
  371. [dic setObject:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  372. [dic setObject:@"2" forKey:@"appType"];
  373. [dic setObject:[NSString stringWithFormat:@"%@%@",systemName,systemVersion] forKey:@"systemVersion"];
  374. [dic setObject:[NSString stringWithFormat:@"%@%@",identifier,currentVersion] forKey:@"version"];
  375. NSString *method = @"login";
  376. [MBProgressHUD showLoadToView:self.view];
  377. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  378. [MBProgressHUD hideHUDForView:self.view];
  379. if (!root){
  380. return;
  381. }
  382. if ([root[@"code"] isEqualToString:@"1"]) {
  383. return;
  384. }
  385. ShowMsg(@"操作成功");
  386. defUser.userDict = root[@"body"];
  387. [self setPersonData];
  388. }];
  389. }
  390. #pragma mark - 退出登录
  391. -(void)loginOut{
  392. //退出登录
  393. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"您确定要退出登录吗" preferredStyle:UIAlertControllerStyleAlert];
  394. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  395. }]];
  396. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  397. defUser.userDict = nil;
  398. myDelegate.isLogin = NO;
  399. [LoginViewController saveIosMei];
  400. [LoginViewController loginFromVC:self];
  401. }]];
  402. dispatch_async(dispatch_get_main_queue(), ^{
  403. [self.tabBarController presentViewController:alertFind animated:true completion:nil];
  404. });
  405. }
  406. - (void)didReceiveMemoryWarning {
  407. [super didReceiveMemoryWarning];
  408. }
  409. #pragma mark 客服
  410. - (void)registerSuccess:(NSNotification *)sender {
  411. NSLog(@"注册成功");
  412. if (_isPushed) {
  413. [MBProgressHUD hideHUDForView:self.view];
  414. _isConnecting = NO;
  415. return;
  416. }
  417. [QMConnect sdkGetWebchatScheduleConfig:^(NSDictionary * _Nonnull scheduleDic) {
  418. dispatch_async(dispatch_get_main_queue(), ^{
  419. self.dictionary = scheduleDic;
  420. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  421. NSLog(@"日程管理");
  422. [self starSchedule];
  423. }else{
  424. NSLog(@"技能组");
  425. [self getPeers];
  426. }
  427. });
  428. } failBlock:^{
  429. }];
  430. }
  431. - (void)registerFailure:(NSNotification *)sender {
  432. NSLog(@"注册失败::%@", sender.object);
  433. self.isConnecting = NO;
  434. [MBProgressHUD hideHUDForView:self.view];
  435. }
  436. #pragma mark - 技能组选择
  437. - (void)getPeers {
  438. [QMConnect sdkGetPeers:^(NSArray * _Nonnull peerArray) {
  439. dispatch_async(dispatch_get_main_queue(), ^{
  440. NSLog(@"%@", peerArray);
  441. NSArray *peers = peerArray;
  442. self.isConnecting = NO;
  443. [MBProgressHUD hideHUDForView:self.view];
  444. if (peers.count == 1 && peers.count != 0) {
  445. [self showChatRoomViewController:[peers.firstObject objectForKey:@"id"] processType:@""];
  446. }else {
  447. [self showPeersWithAlert:peers messageStr:@"选择您咨询的类型或业务部门(对应技能组)"];
  448. }
  449. });
  450. } failureBlock:^{
  451. dispatch_async(dispatch_get_main_queue(), ^{
  452. [MBProgressHUD hideHUDForView:self.view];
  453. self.isConnecting = NO;
  454. });
  455. }];
  456. }
  457. #pragma mark - 日程管理
  458. - (void)starSchedule {
  459. self.isConnecting = NO;
  460. [MBProgressHUD hideHUDForView:self.view];
  461. if ([self.dictionary[@"scheduleId"] isEqual: @""] || [self.dictionary[@"processId"] isEqual: @""] || [self.dictionary objectForKey:@"entranceNode"] == nil || [self.dictionary objectForKey:@"leavemsgNodes"] == nil) {
  462. [QMAlert showMessage:@"对不起,由于在线咨询配置错误,暂时无法进行咨询"];
  463. }else{
  464. NSDictionary *entranceNode = self.dictionary[@"entranceNode"];
  465. NSArray *entrances = entranceNode[@"entrances"];
  466. NSLog(@" 获取到日程节点数组 ===== %@", entrances);
  467. // [self showPeersWithAlert: sdkEntrances];
  468. if (entrances.count == 1 && entrances.count != 0) {
  469. [self showChatRoomViewController:[entrances.firstObject objectForKey:@"processTo"] processType:[entrances.firstObject objectForKey:@"processType"]];
  470. }else{
  471. [self showPeersWithAlert:entrances messageStr:@"选择您咨询的日程管理类型"];
  472. }
  473. }
  474. }
  475. - (void)showPeersWithAlert: (NSArray *)peers messageStr: (NSString *)message {
  476. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择您咨询的类型或业务部门(对应技能组)" preferredStyle:UIAlertControllerStyleAlert];
  477. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  478. self.isConnecting = NO;
  479. }];
  480. [alertController addAction:cancelAction];
  481. for (NSDictionary *index in peers) {
  482. UIAlertAction *surelAction = [UIAlertAction actionWithTitle:[index objectForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  483. if ([self.dictionary[@"scheduleEnable"] integerValue] == 1) {
  484. [self showChatRoomViewController:[index objectForKey:@"processTo"] processType:[index objectForKey:@"processType"]];
  485. }else{
  486. [self showChatRoomViewController:[index objectForKey:@"id"] processType:@""];
  487. }
  488. }];
  489. [alertController addAction:surelAction];
  490. }
  491. [self presentViewController:alertController animated:YES completion:nil];
  492. }
  493. #pragma mark - 跳转聊天界面
  494. - (void)showChatRoomViewController:(NSString *)peerId processType:(NSString *)processType {
  495. QMChatRoomViewController *chatRoomViewController = [[QMChatRoomViewController alloc] init];
  496. chatRoomViewController.peerId = peerId;
  497. chatRoomViewController.isPush = NO;
  498. NSString *path = defUser.userDict[@"photo"];
  499. if (!path) {
  500. path = @"";
  501. }
  502. chatRoomViewController.avaterStr = path;
  503. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  504. chatRoomViewController.isOpenSchedule = true;
  505. chatRoomViewController.scheduleId = self.dictionary[@"scheduleId"];
  506. chatRoomViewController.processId = self.dictionary[@"processId"];
  507. chatRoomViewController.currentNodeId = peerId;
  508. chatRoomViewController.processType = processType;
  509. }else{
  510. chatRoomViewController.isOpenSchedule = false;
  511. }
  512. [self navPushHideTabbarToVC:chatRoomViewController];
  513. // 此处为了统一“注销”返回方式 就选择了present进去
  514. }
  515. - (NSMutableAttributedString *)setSpace:(CGFloat)line kern:(NSNumber *)kern font:(UIFont *)font text:(NSString *)text {
  516. NSMutableParagraphStyle * paraStyle = [NSMutableParagraphStyle new];
  517. paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
  518. paraStyle.alignment = NSTextAlignmentCenter;
  519. paraStyle.lineSpacing = line;
  520. paraStyle.hyphenationFactor = 1.0;
  521. paraStyle.firstLineHeadIndent = 0.0;
  522. paraStyle.paragraphSpacingBefore = 0.0;
  523. paraStyle.headIndent = 0;
  524. paraStyle.tailIndent = 0;
  525. NSDictionary *attributes = @{
  526. NSFontAttributeName: font,
  527. NSParagraphStyleAttributeName: paraStyle,
  528. NSKernAttributeName: kern
  529. };
  530. NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes];
  531. return attributeStr;
  532. }
  533. - (void)dealloc {
  534. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_SUCCEED object:nil];
  535. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_ERROR_USER object:nil];
  536. }
  537. @end