// // ExploreVC.m // JSJPCoach // // Created by apple on 2017/3/20. // Copyright © 2017年 Danson. All rights reserved. // #import "ExploreVC.h" #import "MyUINavigationController.h" #import "fpVC.h" #import "MyMsgVC.h" #import "LoginVC.h" #import "StudentSignInVC.h" #import "SelfAppointmentVC.h" #import "IssuePlanVC.h" #import "MyOrderVC.h" #import "StuRecordVC.h" #import "LoginVC.h" #import "BindVC.h" #import "RepairViewController.h" #import "ClassTheoryList.h" #import "MBProgressHUD.h" //计划 #import "MyPlanVC.h" //客服 #import "QMChatRoomViewController.h" #import #import "QMAlert.h" #define PersonVCTop_H kStatusHeight+20 #define PersonVCRate 1.0/(PersonVCTop_H+100-kNavOffSet)//100为透视图高度 @interface ExploreVC () { UIView *secondView; UIImageView *pageControl1, *pageControl2; UITextField *BindNumberField; UITextField *RegistField; NSArray *titles; //客服 BOOL _isFirstClick; // 判断点击状态 BOOL _isPushed; // 判断跳转状态 CGFloat _scrHeight; } //客服 @property (nonatomic, assign) BOOL isPushed; // 控制跳转 @property (nonatomic, assign) BOOL isConnecting; // 控制多次注册 @property (nonatomic, copy) NSDictionary * dictionary; //客服一些配置 @end @implementation ExploreVC -(instancetype)initWithScrFrame:(CGRect)frame{ if (self = [super init]) { _scrHeight = frame.size.height; self.view.frame = frame; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; _isPushed = NO; self.navigationController.navigationBar.translucent = YES; // self.navigationController.navigationBar.barTintColor = nil; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; _isPushed = YES; } - (void)myInit { CGFloat x,y,w,h,bd; bd = 10; x = y = 0; w = kSize.width; h = _scrHeight; UIScrollView *scrollView = [[UIScrollView alloc] setxywh]; [scrollView setShowsVerticalScrollIndicator:YES]; [self.view addSubview:scrollView]; titles = @[@"带教记录", @"我的学员", @"我的订单", @"分配记录", @"预考成绩", @"训练照片", @"发布计划", @"我的预约", @"教学日志", // @"集中培训", @"车辆报修", @"联系客服" // @"预约查询" ]; //功能块的个数 NSInteger functionCount = titles.count; CGFloat wid = kSize.width/3.0 - 2*bd; for (int i = 0; i < functionCount; i ++) { int row = i/3; int queue = i%3; //功能按钮 UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(2*bd + queue*(wid + bd), 2*bd + row*(wid + bd), wid, wid)]; btn.layer.masksToBounds = YES; btn.layer.cornerRadius = 5; btn.backgroundColor = RGBA_COLOR(247, 247, 247, 0.3); [btn target:self Tag:i + 1]; [scrollView addSubview:btn]; //图片 x = wid/4.0; y = wid/6.0; w = h = wid/2.0; UIImageView *btnImageView = [[UIImageView alloc] setxywh]; btnImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"img%d.png",i + 1]]; [btn addSubview:btnImageView]; //文字 x = 0; y += h + wid/15.0; w = wid; h = wid/5.0; UILabel *label = [[UILabel alloc] setxywh]; [label setText:titles[i] Font:Font17 TextColor:RGB_COLOR(49, 51, 84) Alignment:NSTextAlignmentCenter]; [btn addSubview:label]; } [scrollView setContentSize:CGSizeMake(kSize.width, (functionCount/3 + 1)*(wid + bd) + 4*bd)]; //客服 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerSuccess:) name:CUSTOM_LOGIN_SUCCEED object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerFailure:) name:CUSTOM_LOGIN_ERROR_USER object:nil]; _isConnecting = NO; _isPushed = NO; } - (void)btnClick:(UIButton *)sender { if (!defUser.isLogin) { [LoginVC loginFromVC:self]; return ; } UIButton *btn = (UIButton *)sender; NSArray *arr = @[@"StudentSignInVC", @"StudentSignInVC", @"MyOrderVC", @"fpVC", @"StuRecordVC",//预考成绩 @"StudentSignInVC", @"IssuePlanVC", @"MyPlanVC", @"StudentSignInVC",//电子教学日志 // @"ClassTheoryList", @"RepairViewController", @""//客服 // @"SelfAppointmentVC" ]; //客服-联系我们 if (btn.tag == 11) { if (_isConnecting) { return; } _isConnecting = YES; [MBProgressHUD showHUDAddedTo:self.view animated:NO]; self.navigationController.navigationBar.translucent = NO; // userId 只能使用 数字 字母(包括大小写) 下划线 NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSString *name = [NSString stringWithFormat:@"%@[辽I教练_%@]",defUser.userDict[@"name"],version]; [QMConnect registerSDKWithAppKey:@"fbc60790-4f40-11e7-a416-f12e96c638e0" userName:name userId:defUser.userDict[@"id"]]; } if (btn.tag == 1 || btn.tag == 2 || btn.tag == 6 || btn.tag == 9) { StudentSignInVC *stuVC = [[StudentSignInVC alloc] init]; stuVC.skipType = btn.tag; [stuVC.view setBackgroundColor:[UIColor whiteColor]]; [stuVC setTitle:titles[btn.tag - 1]]; [stuVC configNavBar]; [self.navigationController pushViewController:stuVC animated:YES]; return; } // if (预约查询){ // // SelfAppointmentVC *vc = [[SelfAppointmentVC alloc] init]; // vc.type = @"2"; // [self.navigationController pushViewController:vc animated:YES]; // return; // } UIViewController *vc = [NSClassFromString(arr[btn.tag - 1]) new]; [vc.view setBackgroundColor:[UIColor whiteColor]]; [vc setTitle:titles[btn.tag - 1]]; [vc configNavBar]; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark 客服 - (void)registerSuccess:(NSNotification *)sender { NSLog(@"注册成功"); if (_isPushed) { [MBProgressHUD hideHUDForView:self.view animated:NO]; _isConnecting = NO; return; } [QMConnect sdkGetWebchatScheduleConfig:^(NSDictionary * _Nonnull scheduleDic) { dispatch_async(dispatch_get_main_queue(), ^{ self.dictionary = scheduleDic; if ([self.dictionary[@"scheduleEnable"] intValue] == 1) { NSLog(@"日程管理"); [self starSchedule]; }else{ NSLog(@"技能组"); [self getPeers]; } }); } failBlock:^{ }]; } - (void)registerFailure:(NSNotification *)sender { NSLog(@"注册失败::%@", sender.object); self.isConnecting = NO; [MBProgressHUD hideHUDForView:self.view animated:NO]; } #pragma mark - 技能组选择 - (void)getPeers { [QMConnect sdkGetPeers:^(NSArray * _Nonnull peerArray) { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"%@", peerArray); NSArray *peers = peerArray; self.isConnecting = NO; [MBProgressHUD hideHUDForView:self.view animated:NO]; if (peers.count == 1 && peers.count != 0) { [self showChatRoomViewController:[peers.firstObject objectForKey:@"id"] processType:@""]; }else { [self showPeersWithAlert:peers messageStr:@"选择您咨询的类型或业务部门(对应技能组)"]; } }); } failureBlock:^{ dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.view animated:NO]; self.isConnecting = NO; }); }]; } #pragma mark - 日程管理 - (void)starSchedule { self.isConnecting = NO; [MBProgressHUD hideHUDForView:self.view animated:NO]; if ([self.dictionary[@"scheduleId"] isEqual: @""] || [self.dictionary[@"processId"] isEqual: @""] || [self.dictionary objectForKey:@"entranceNode"] == nil || [self.dictionary objectForKey:@"leavemsgNodes"] == nil) { [QMAlert showMessage:@"对不起,由于在线咨询配置错误,暂时无法进行咨询"]; }else{ NSDictionary *entranceNode = self.dictionary[@"entranceNode"]; NSArray *entrances = entranceNode[@"entrances"]; NSLog(@" 获取到日程节点数组 ===== %@", entrances); // [self showPeersWithAlert: sdkEntrances]; if (entrances.count == 1 && entrances.count != 0) { [self showChatRoomViewController:[entrances.firstObject objectForKey:@"processTo"] processType:[entrances.firstObject objectForKey:@"processType"]]; }else{ [self showPeersWithAlert:entrances messageStr:@"选择您咨询的日程管理类型"]; } } } - (void)showPeersWithAlert: (NSArray *)peers messageStr: (NSString *)message { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择您咨询的类型或业务部门(对应技能组)" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { self.isConnecting = NO; }]; [alertController addAction:cancelAction]; for (NSDictionary *index in peers) { UIAlertAction *surelAction = [UIAlertAction actionWithTitle:[index objectForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if ([self.dictionary[@"scheduleEnable"] integerValue] == 1) { [self showChatRoomViewController:[index objectForKey:@"processTo"] processType:[index objectForKey:@"processType"]]; }else{ [self showChatRoomViewController:[index objectForKey:@"id"] processType:@""]; } }]; [alertController addAction:surelAction]; } [self presentViewController:alertController animated:YES completion:nil]; } #pragma mark - 跳转聊天界面 - (void)showChatRoomViewController:(NSString *)peerId processType:(NSString *)processType { QMChatRoomViewController *chatRoomViewController = [[QMChatRoomViewController alloc] init]; chatRoomViewController.peerId = peerId; chatRoomViewController.isPush = NO; NSString *path = defUser.userDict[@"photo"]; if (!path) { path = @""; } chatRoomViewController.avaterStr = path; if ([self.dictionary[@"scheduleEnable"] intValue] == 1) { chatRoomViewController.isOpenSchedule = true; chatRoomViewController.scheduleId = self.dictionary[@"scheduleId"]; chatRoomViewController.processId = self.dictionary[@"processId"]; chatRoomViewController.currentNodeId = peerId; chatRoomViewController.processType = processType; }else{ chatRoomViewController.isOpenSchedule = false; } [self.navigationController pushViewController:chatRoomViewController animated:YES]; } - (NSMutableAttributedString *)setSpace:(CGFloat)line kern:(NSNumber *)kern font:(UIFont *)font text:(NSString *)text { NSMutableParagraphStyle * paraStyle = [NSMutableParagraphStyle new]; paraStyle.lineBreakMode = NSLineBreakByCharWrapping; paraStyle.alignment = NSTextAlignmentCenter; paraStyle.lineSpacing = line; paraStyle.hyphenationFactor = 1.0; paraStyle.firstLineHeadIndent = 0.0; paraStyle.paragraphSpacingBefore = 0.0; paraStyle.headIndent = 0; paraStyle.tailIndent = 0; NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paraStyle, NSKernAttributeName: kern }; NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes]; return attributeStr; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_SUCCEED object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_ERROR_USER object:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end