ExploreVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. //
  2. // ExploreVC.m
  3. // JSJPCoach
  4. //
  5. // Created by apple on 2017/3/20.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "ExploreVC.h"
  9. #import "MyUINavigationController.h"
  10. #import "fpVC.h"
  11. #import "MyMsgVC.h"
  12. #import "LoginVC.h"
  13. #import "StudentSignInVC.h"
  14. #import "SelfAppointmentVC.h"
  15. #import "IssuePlanVC.h"
  16. #import "MyOrderVC.h"
  17. #import "StuRecordVC.h"
  18. #import "LoginVC.h"
  19. #import "BindVC.h"
  20. #import "TerminalScreenVC.h"
  21. #import "MBProgressHUD+Add.h"
  22. //计划
  23. #import "MyPlanVC.h"
  24. //客服
  25. #import "QMChatRoomViewController.h"
  26. #import <QMLineSDK/QMLineSDK.h>
  27. #import "QMAlert.h"
  28. #define PersonVCTop_H kStatusHeight+20
  29. #define PersonVCRate 1.0/(PersonVCTop_H+100-kNavOffSet)//100为透视图高度
  30. @interface ExploreVC ()<UIAlertViewDelegate>
  31. {
  32. UIView *secondView;
  33. UIImageView *pageControl1, *pageControl2;
  34. UITextField *BindNumberField;
  35. UITextField *RegistField;
  36. //客服
  37. BOOL _isFirstClick; // 判断点击状态
  38. BOOL _isPushed; // 判断跳转状态
  39. CGFloat _scrHeight;
  40. }
  41. //客服
  42. @property (nonatomic, assign) BOOL isPushed; // 控制跳转
  43. @property (nonatomic, assign) BOOL isConnecting; // 控制多次注册
  44. @property (nonatomic, copy) NSDictionary * dictionary; //客服一些配置
  45. @end
  46. @implementation ExploreVC
  47. -(instancetype)initWithScrFrame:(CGRect)frame{
  48. if (self = [super init]) {
  49. _scrHeight = frame.size.height;
  50. self.view.frame = frame;
  51. }
  52. return self;
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. [self myInit];
  57. }
  58. -(void)viewWillAppear:(BOOL)animated {
  59. [super viewWillAppear:animated];
  60. _isPushed = NO;
  61. self.navigationController.navigationBar.translucent = YES;
  62. self.navigationController.navigationBar.barTintColor = nil;
  63. }
  64. -(void)viewWillDisappear:(BOOL)animated {
  65. [super viewWillDisappear:animated];
  66. _isPushed = YES;
  67. }
  68. - (void)myInit
  69. {
  70. CGFloat x,y,w,h,bd;
  71. bd = 10;
  72. x = y = 0;
  73. w = kSize.width;
  74. h = _scrHeight;
  75. UIScrollView *scrollView = [[UIScrollView alloc] setxywh];
  76. [scrollView setShowsVerticalScrollIndicator:YES];
  77. [self.view addSubview:scrollView];
  78. NSArray *titileArray = @[
  79. // @"带教记录",
  80. @"教学日志",
  81. @"我的学员",
  82. @"我的订单",
  83. @"分配记录",
  84. @"预考成绩",
  85. @"训练照片",
  86. @"发布计划",
  87. @"我的预约",
  88. @"终端投屏",
  89. @"联系客服"
  90. // @"预约查询"
  91. ];
  92. //功能块的个数
  93. NSInteger functionCount = titileArray.count;
  94. CGFloat wid = kSize.width/3.0 - 2*bd;
  95. for (int i = 0; i < functionCount; i ++) {
  96. int row = i/3;
  97. int queue = i%3;
  98. //功能按钮
  99. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(2*bd + queue*(wid + bd), 2*bd + row*(wid + bd), wid, wid)];
  100. btn.layer.masksToBounds = YES;
  101. btn.layer.cornerRadius = 5;
  102. btn.backgroundColor = RGBA_COLOR(247, 247, 247, 0.3);
  103. [btn target:self Tag:i + 1];
  104. [scrollView addSubview:btn];
  105. //图片
  106. x = wid/4.0;
  107. y = wid/6.0;
  108. w = h = wid/2.0;
  109. UIImageView *btnImageView = [[UIImageView alloc] setxywh];
  110. btnImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"img%d.png",i + 1]];
  111. [btn addSubview:btnImageView];
  112. //文字
  113. x = 0;
  114. y += h + wid/15.0;
  115. w = wid;
  116. h = wid/5.0;
  117. UILabel *label = [[UILabel alloc] setxywh];
  118. [label setText:titileArray[i] Font:Font17 TextColor:RGB_COLOR(49, 51, 84) Alignment:NSTextAlignmentCenter];
  119. [btn addSubview:label];
  120. }
  121. [scrollView setContentSize:CGSizeMake(kSize.width, (functionCount/3 + 1)*(wid + bd) + 4*bd)];
  122. //客服
  123. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerSuccess:) name:CUSTOM_LOGIN_SUCCEED object:nil];
  124. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerFailure:) name:CUSTOM_LOGIN_ERROR_USER object:nil];
  125. _isConnecting = NO;
  126. _isPushed = NO;
  127. }
  128. - (void)btnClick:(UIButton *)sender
  129. {
  130. if (!defUser.isLogin) {
  131. [LoginVC loginFromVC:self];
  132. return ;
  133. }
  134. UIButton *btn = (UIButton *)sender;
  135. NSArray *titles = @[@"教学日志",
  136. @"我的学员",
  137. @"我的订单",
  138. @"分配记录",
  139. @"预考成绩",
  140. @"训练照片",
  141. @"发布计划",
  142. @"我的预约",
  143. @"终端投屏",
  144. @"联系客服"
  145. // @"预约查询"
  146. ];
  147. NSArray *arr = @[@"StudentSignInVC",
  148. @"StudentSignInVC",
  149. @"MyOrderVC",
  150. @"fpVC",
  151. @"StuRecordVC",//预考成绩
  152. @"StudentSignInVC",
  153. @"IssuePlanVC",
  154. @"MyPlanVC",
  155. @"TerminalScreenVC",
  156. @""
  157. // @"SelfAppointmentVC"
  158. ];
  159. //客服-联系客服
  160. if (btn.tag == 10) {
  161. if (_isConnecting) {
  162. return;
  163. }
  164. _isConnecting = YES;
  165. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  166. self.navigationController.navigationBar.translucent = NO;
  167. // userId 只能使用 数字 字母(包括大小写) 下划线
  168. NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  169. NSString *name = [NSString stringWithFormat:@"%@[闽I教练_%@]",defUser.userDict[@"name"],version];
  170. [QMConnect registerSDKWithAppKey:@"16889d90-4f41-11e7-a416-f12e96c638e0" userName:name userId:defUser.userDict[@"id"]];
  171. }
  172. if (btn.tag == 1 || btn.tag == 2 || btn.tag == 6) {
  173. StudentSignInVC *stuVC = [[StudentSignInVC alloc] init];
  174. stuVC.skipType = btn.tag;
  175. [stuVC.view setBackgroundColor:[UIColor whiteColor]];
  176. [stuVC setTitle:titles[btn.tag - 1]];
  177. [stuVC configNavBar];
  178. [self.navigationController pushViewController:stuVC animated:YES];
  179. return;
  180. }
  181. // if (btn.tag == 11){
  182. //
  183. // SelfAppointmentVC *vc = [[SelfAppointmentVC alloc] init];
  184. // vc.type = @"2";
  185. // [self.navigationController pushViewController:vc animated:YES];
  186. // return;
  187. // }
  188. UIViewController *vc = [NSClassFromString(arr[btn.tag - 1]) new];
  189. [vc.view setBackgroundColor:[UIColor whiteColor]];
  190. [vc setTitle:titles[btn.tag - 1]];
  191. [vc configNavBar];
  192. [self.navigationController pushViewController:vc animated:YES];
  193. }
  194. #pragma mark 客服
  195. - (void)registerSuccess:(NSNotification *)sender {
  196. NSLog(@"注册成功");
  197. if (_isPushed) {
  198. [MBProgressHUD hideHUDForView:self.view animated:NO];
  199. _isConnecting = NO;
  200. return;
  201. }
  202. [QMConnect sdkGetWebchatScheduleConfig:^(NSDictionary * _Nonnull scheduleDic) {
  203. dispatch_async(dispatch_get_main_queue(), ^{
  204. self.dictionary = scheduleDic;
  205. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  206. NSLog(@"日程管理");
  207. [self starSchedule];
  208. }else{
  209. NSLog(@"技能组");
  210. [self getPeers];
  211. }
  212. });
  213. } failBlock:^{
  214. }];
  215. }
  216. - (void)registerFailure:(NSNotification *)sender {
  217. NSLog(@"注册失败::%@", sender.object);
  218. self.isConnecting = NO;
  219. [MBProgressHUD hideHUDForView:self.view animated:NO];
  220. }
  221. #pragma mark - 技能组选择
  222. - (void)getPeers {
  223. [QMConnect sdkGetPeers:^(NSArray * _Nonnull peerArray) {
  224. dispatch_async(dispatch_get_main_queue(), ^{
  225. NSLog(@"%@", peerArray);
  226. NSArray *peers = peerArray;
  227. self.isConnecting = NO;
  228. [MBProgressHUD hideHUDForView:self.view animated:NO];
  229. if (peers.count == 1 && peers.count != 0) {
  230. [self showChatRoomViewController:[peers.firstObject objectForKey:@"id"] processType:@""];
  231. }else {
  232. [self showPeersWithAlert:peers messageStr:@"选择您咨询的类型或业务部门(对应技能组)"];
  233. }
  234. });
  235. } failureBlock:^{
  236. dispatch_async(dispatch_get_main_queue(), ^{
  237. [MBProgressHUD hideHUDForView:self.view animated:NO];
  238. self.isConnecting = NO;
  239. });
  240. }];
  241. }
  242. #pragma mark - 日程管理
  243. - (void)starSchedule {
  244. self.isConnecting = NO;
  245. [MBProgressHUD hideHUDForView:self.view animated:NO];
  246. if ([self.dictionary[@"scheduleId"] isEqual: @""] || [self.dictionary[@"processId"] isEqual: @""] || [self.dictionary objectForKey:@"entranceNode"] == nil || [self.dictionary objectForKey:@"leavemsgNodes"] == nil) {
  247. [QMAlert showMessage:@"对不起,由于在线咨询配置错误,暂时无法进行咨询"];
  248. }else{
  249. NSDictionary *entranceNode = self.dictionary[@"entranceNode"];
  250. NSArray *entrances = entranceNode[@"entrances"];
  251. NSLog(@" 获取到日程节点数组 ===== %@", entrances);
  252. // [self showPeersWithAlert: sdkEntrances];
  253. if (entrances.count == 1 && entrances.count != 0) {
  254. [self showChatRoomViewController:[entrances.firstObject objectForKey:@"processTo"] processType:[entrances.firstObject objectForKey:@"processType"]];
  255. }else{
  256. [self showPeersWithAlert:entrances messageStr:@"选择您咨询的日程管理类型"];
  257. }
  258. }
  259. }
  260. - (void)showPeersWithAlert: (NSArray *)peers messageStr: (NSString *)message {
  261. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择您咨询的类型或业务部门(对应技能组)" preferredStyle:UIAlertControllerStyleAlert];
  262. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  263. self.isConnecting = NO;
  264. }];
  265. [alertController addAction:cancelAction];
  266. for (NSDictionary *index in peers) {
  267. UIAlertAction *surelAction = [UIAlertAction actionWithTitle:[index objectForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  268. if ([self.dictionary[@"scheduleEnable"] integerValue] == 1) {
  269. [self showChatRoomViewController:[index objectForKey:@"processTo"] processType:[index objectForKey:@"processType"]];
  270. }else{
  271. [self showChatRoomViewController:[index objectForKey:@"id"] processType:@""];
  272. }
  273. }];
  274. [alertController addAction:surelAction];
  275. }
  276. [self presentViewController:alertController animated:YES completion:nil];
  277. }
  278. #pragma mark - 跳转聊天界面
  279. - (void)showChatRoomViewController:(NSString *)peerId processType:(NSString *)processType {
  280. QMChatRoomViewController *chatRoomViewController = [[QMChatRoomViewController alloc] init];
  281. chatRoomViewController.peerId = peerId;
  282. chatRoomViewController.isPush = NO;
  283. NSString *path = defUser.userDict[@"photo"];
  284. if (!path) {
  285. path = @"";
  286. }
  287. chatRoomViewController.avaterStr = path;
  288. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  289. chatRoomViewController.isOpenSchedule = true;
  290. chatRoomViewController.scheduleId = self.dictionary[@"scheduleId"];
  291. chatRoomViewController.processId = self.dictionary[@"processId"];
  292. chatRoomViewController.currentNodeId = peerId;
  293. chatRoomViewController.processType = processType;
  294. }else{
  295. chatRoomViewController.isOpenSchedule = false;
  296. }
  297. [self.navigationController pushViewController:chatRoomViewController animated:YES];
  298. }
  299. - (void)dealloc {
  300. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_SUCCEED object:nil];
  301. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_ERROR_USER object:nil];
  302. }
  303. - (void)didReceiveMemoryWarning {
  304. [super didReceiveMemoryWarning];
  305. }
  306. @end