ExploreVC.m 13 KB

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