FunctionVC.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. //
  2. // FunctionVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/7/27.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "FunctionVC.h"
  9. #import "StuDetailVC.h"
  10. #import "FenceSiteVC.h"
  11. #import "AllCoachPlanVC.h"
  12. #import "SelectSchoolVC.h"
  13. #import "MyReserveVC.h"
  14. #import "MyOrderVC.h"
  15. #import "MyAccountVC.h"//我的账户
  16. #import "MyAccountDetailVC.h"//详情
  17. #import "TopUpMoneyVC.h"//充值
  18. #import "BindVC.h"
  19. #import "ThirdLoginBindYunGuanVC.h"
  20. #import "ButtonView.h"
  21. #import "Tools.h"
  22. #import "MNQtTrainVC.h"
  23. #import "BigTruckVC.h"
  24. #import "ScanVC.h"
  25. //客服
  26. #import "QMChatRoomViewController.h"
  27. #import <QMLineSDK/QMLineSDK.h>
  28. #import "QMAlert.h"
  29. #import "MyUINavigationController.h"
  30. /// 转校记录
  31. #import "ChangeSchoolListViewController.h"
  32. #import "RQWebViewViewController.h"
  33. @interface FunctionVC ()<UIScrollViewDelegate,UIAlertViewDelegate>
  34. {
  35. UIScrollView *mainScroll;
  36. UIImageView *headImg;
  37. UILabel *nameLabel;
  38. UILabel *phoneLabel;
  39. UILabel *identLabel;
  40. }
  41. //客服
  42. @property (nonatomic, assign) BOOL isPushed; // 控制跳转
  43. @property (nonatomic, assign) BOOL isConnecting; // 控制多次注册
  44. @property (nonatomic, copy) NSDictionary * dictionary; //客服一些配置
  45. @end
  46. @implementation FunctionVC
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.view.backgroundColor = backGroundColor;
  50. //self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:170/255.0 blue:240/255.0 alpha:1];
  51. self.navigationController.navigationBar.translucent = NO;
  52. self.navigationItem.title = @"快捷功能";
  53. [self myInit];
  54. }
  55. -(void)viewWillAppear:(BOOL)animated{
  56. [super viewWillAppear:animated];
  57. [self setHeaderView];
  58. }
  59. -(void)viewDidAppear:(BOOL)animated{
  60. [super viewDidAppear:animated];
  61. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  62. } else {
  63. self.tabBarController.tabBar.hidden = NO;
  64. }
  65. }
  66. -(void)viewWillDisappear:(BOOL)animated
  67. {
  68. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  69. } else {
  70. self.hidesBottomBarWhenPushed = NO;
  71. }
  72. [super viewWillDisappear:animated];
  73. }
  74. -(void)viewDidDisappear:(BOOL)animated
  75. {
  76. [super viewDidDisappear:animated];
  77. self.navigationController.navigationBar.barTintColor = nil;
  78. }
  79. -(void)myInit
  80. {
  81. mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet)];
  82. mainScroll.delegate = self;
  83. [self.view addSubview:mainScroll];
  84. CGFloat x,y,w,h;
  85. x = y = 0;
  86. w = kSize.width;
  87. h = kSize.width*0.35;
  88. UIView *headView = [[UIView alloc] setxywh];
  89. headView.backgroundColor = [UIColor whiteColor];
  90. //[UIColor colorWithRed:60/255.0 green:170/255.0 blue:240/255.0 alpha:1]
  91. [mainScroll addSubview:headView];
  92. //----------------------顶部头像所在视图-----------------------
  93. w = 0.7*h;
  94. headImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0.15*h, w, w)];
  95. [headImg setBoardWid:1 Color:defGreen];
  96. [headImg setRound];
  97. [headView addSubview:headImg];
  98. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. btn.frame = headImg.frame;
  100. [btn target:self tag:1];
  101. [headView addSubview:btn];
  102. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30 + w, 0.15*h, kSize.width - 30 - w -10, 0.28*h)];
  103. [label setText:@"" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  104. [headView addSubview:label];
  105. nameLabel = label;
  106. label = [[UILabel alloc] initWithFrame:CGRectMake(30 + w, 0.43*h, kSize.width - 30 - w -10, 0.21*h)];
  107. [label setText:@"" Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  108. [headView addSubview:label];
  109. phoneLabel = label;
  110. label = [[UILabel alloc] initWithFrame:CGRectMake(30 + w, 0.64*h, kSize.width - 30 - w -10, 0.21*h)];
  111. [label setText:@"" Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  112. [headView addSubview:label];
  113. identLabel = label;
  114. [self setHeaderView];
  115. //-------------------账户信息------------------
  116. y += h;
  117. w = kSize.width/3.0;
  118. //h = 45;
  119. /// RQ-MARK:待开发功能 苹果审核无法通过 暂时隐藏
  120. h = 0;
  121. NSArray *titAndImgArray = @[@"account01.png",
  122. @"account02.png",
  123. @"account03.png",
  124. @"我的账户",
  125. @"我要充值",
  126. @"资金明细"];
  127. for (int i = 0; i < 3; i ++) {
  128. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  129. btn.frame = CGRectMake(i*w, y, w, h);
  130. [btn setBoardWid:1 Color:KlineColor];
  131. btn.backgroundColor = [UIColor clearColor];
  132. [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:.4 alpha:.3]] forState:UIControlStateHighlighted];
  133. [btn setTitle:@"" textColor:kTitleColor font:Font17 fotState:UIControlStateNormal];
  134. [btn target:self tag:i - 3];//-3 -2 -1
  135. ButtonView *view = [[ButtonView alloc] initWithFrame:btn.frame Image:titAndImgArray[i] Title:titAndImgArray[i + 3] Detail:@"" type:2];
  136. [mainScroll addSubview:view];
  137. [mainScroll addSubview:btn];
  138. }
  139. //-------------------预约相关------------------
  140. x = 20;
  141. y += h + 10;
  142. w = kSize.width - 40;
  143. h = 30;
  144. label = [[UILabel alloc] setxywh];
  145. [label setText:@"预约相关" Font:NormalFont TextColor:contentTextColor];
  146. [mainScroll addSubview:label];
  147. [label addViewWithRect:CGRectMake(0, y - 10, kSize.width, 10)];
  148. y += h;
  149. w = kSize.width/2.0;
  150. h = 60;
  151. // NSArray *titleArray = @[@"教练计划", @"我的预约",@"我的订单",@"我的学时",
  152. // @"模拟计时",@"大客/货车计时",@"转校查询",
  153. // @"线上咨询"];//@"绑定申请",
  154. // NSArray *detailArray = @[@"先学后付,计时收费",
  155. // @"我和教练的约会,点我",
  156. // @"交易过程管理,由我掌控",
  157. // @"计时结果查询,点我进入",
  158. //
  159. // @"轻松模拟课时",
  160. // @"大客/货车计时服务",
  161. // @"转校查询",
  162. //
  163. // @"您有什么问题吗,欢迎咨询",];//@"绑定后才能实操计时哦",
  164. // NSArray *imageArray = @[@"function01.png",//@"function02.png",
  165. // @"function03.png",
  166. // @"function04.png",
  167. // @"function06.png",
  168. //
  169. // @"function09.png",
  170. // @"function10.png",
  171. // @"changeSchool.png",
  172. //
  173. // @"qm_default_agent.png"];
  174. NSArray *moduleOneTitleArray = @[@"教练计划", @"我的预约",@"我的订单",@"我的学时"];
  175. NSArray *moduleOneDetailArray = @[@"先学后付,计时收费",@"我和教练的约会,点我",@"交易过程管理,由我掌控",@"计时结果查询,点我进入",];
  176. NSArray *moduleOneImageArray = @[@"function01.png",@"function03.png",@"function04.png",@"function06.png"];
  177. for (int i = 0; i < moduleOneTitleArray.count; i ++) {
  178. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  179. btn.frame = CGRectMake((i%2)*w, y + 60*(i/2), w, h);
  180. [btn setBoardWid:1 Color:KlineColor];
  181. btn.backgroundColor = [UIColor clearColor];
  182. [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:.4 alpha:.3]] forState:UIControlStateHighlighted];
  183. [btn setTitle:@"" textColor:kTitleColor font:Font17 fotState:UIControlStateNormal];
  184. [btn target:self tag:i + 2];//2345
  185. ButtonView *view = [[ButtonView alloc] initWithFrame:btn.frame Image:moduleOneImageArray[i] Title:moduleOneTitleArray[i] Detail:moduleOneDetailArray[i] type:1];
  186. [mainScroll addSubview:view];
  187. [mainScroll addSubview:btn];
  188. }
  189. //-----------学时相关-----------------
  190. NSArray *moduleTwoTitleArray = @[ @"模拟计时",@"大客/货车计时",@"转校查询",@"查看合同"];
  191. NSArray *moduleTwoDetailArray = @[@"轻松模拟课时",@"大客/货车计时服务",@"转校查询",@"查看报名合同"];
  192. NSArray *moduleTwoImageArray = @[ @"function09.png",@"function10.png",@"changeSchool.png",@"stuProtocol.png"];
  193. x = 20;
  194. y += 2*h + 10;
  195. w = kSize.width - 40;
  196. h = 30;
  197. label = [[UILabel alloc] setxywh];
  198. [label setText:@"学车计时" Font:NormalFont TextColor:contentTextColor];
  199. [mainScroll addSubview:label];
  200. [label addViewWithRect:CGRectMake(0, y - 10, kSize.width, 10)];
  201. label = [[UILabel alloc] setxywh];
  202. [label setText:@"" Font:FontTitle TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentRight];
  203. [mainScroll addSubview:label];
  204. myDelegate.trainStateLabel = label;
  205. y += h;
  206. w = kSize.width/2.0;
  207. h = 60;
  208. for (int i = 0; i < moduleTwoTitleArray.count; i ++) {
  209. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  210. btn.frame = CGRectMake((i%2)*w, y + 60*(i/2), w, h);
  211. [btn setBoardWid:1 Color:KlineColor];
  212. btn.backgroundColor = [UIColor clearColor];
  213. [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:.4 alpha:.3]] forState:UIControlStateHighlighted];
  214. [btn setTitle:@"" textColor:kTitleColor font:Font17 fotState:UIControlStateNormal];
  215. [btn target:self tag:i + 2 + moduleOneTitleArray.count];//678
  216. ButtonView *view = [[ButtonView alloc] initWithFrame:btn.frame Image:moduleTwoImageArray[i] Title:moduleTwoTitleArray[i] Detail:moduleTwoDetailArray[i] type:1];
  217. [mainScroll addSubview:view];
  218. [mainScroll addSubview:btn];
  219. }
  220. //-----------咨询相关-----------------
  221. NSArray *moduleThreeTitleArray = @[@"线上咨询"];
  222. NSArray *moduleThreeDetailArray = @[@"您有什么问题吗,欢迎咨询"];
  223. NSArray *moduleThreeImageArray = @[@"qm_default_agent.png"];
  224. x = 20;
  225. y += h * 2 + 10;
  226. w = kSize.width - 40;
  227. h = 30;
  228. label = [[UILabel alloc] setxywh];
  229. [label setText:@"咨询相关" Font:NormalFont TextColor:contentTextColor];
  230. [mainScroll addSubview:label];
  231. [label addViewWithRect:CGRectMake(0, y - 10, kSize.width, 10)];
  232. y += h;
  233. w = kSize.width;
  234. h = 60;
  235. for (int i = 0; i < moduleThreeTitleArray.count; i ++) {
  236. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  237. btn.frame = CGRectMake((i%2)*w, y + 60*(i/2), w, h);
  238. [btn setBoardWid:1 Color:KlineColor];
  239. btn.backgroundColor = [UIColor clearColor];
  240. [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:.4 alpha:.3]] forState:UIControlStateHighlighted];
  241. [btn setTitle:@"" textColor:kTitleColor font:Font17 fotState:UIControlStateNormal];
  242. [btn target:self tag:i + 2 + moduleOneTitleArray.count + moduleTwoTitleArray.count];
  243. ButtonView *view = [[ButtonView alloc] initWithFrame:btn.frame Image:moduleThreeImageArray[i] Title:moduleThreeTitleArray[i] Detail:moduleThreeDetailArray[i] type:1];
  244. [mainScroll addSubview:view];
  245. [mainScroll addSubview:btn];
  246. }
  247. [mainScroll setContentSize:CGSizeMake(kSize.width, y + h + 30)];
  248. //客服
  249. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerSuccess:) name:CUSTOM_LOGIN_SUCCEED object:nil];
  250. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registerFailure:) name:CUSTOM_LOGIN_ERROR_USER object:nil];
  251. _isConnecting = NO;
  252. _isPushed = NO;
  253. }
  254. -(void)setHeaderView
  255. {
  256. NSString *str = defUser.userDict[@"photo"];
  257. if (str && ![str hasPrefix:@"http"]){
  258. str = [imgPreFix stringByAppendingString:str];
  259. }
  260. if (str == nil) {
  261. str = @"";
  262. }
  263. [headImg sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"drawer_head.png"]];
  264. //NSLog(@"%@",defUser.userDict);
  265. NSString *nameString = defUser.userDict[@"userName"];
  266. if (nameString.length < 1) {
  267. nameString = defUser.userDict[@"nickName"];
  268. }
  269. if (nameString.length < 1) {
  270. nameString = defUser.userDict[@"loginCode"];
  271. }
  272. if (nameString.length < 1) {
  273. nameString = @"暂未登录";
  274. }
  275. nameLabel.text = nameString;
  276. NSString *telString = @"";
  277. //NSLog(@"%@",defUser.userDict);
  278. if ([defUser.userTel length] > 0) {
  279. telString = defUser.userTel;
  280. if (telString.length > 10) {
  281. NSMutableString *mutTel = [NSMutableString stringWithString:telString];
  282. [mutTel replaceCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
  283. telString = (NSString *)mutTel;
  284. }
  285. }
  286. phoneLabel.text = telString;
  287. NSMutableString *sfzhmString = nil;
  288. if ([defUser.userDict[@"sfzmhm"] length] > 0) {
  289. sfzhmString = [NSMutableString stringWithString:defUser.userDict[@"sfzmhm"]];
  290. [sfzhmString replaceCharactersInRange:NSMakeRange(sfzhmString.length - 8, 6) withString:@"******"];
  291. }else{
  292. sfzhmString = [NSMutableString stringWithString:@""];
  293. }
  294. identLabel.text = sfzhmString;
  295. }
  296. -(void)btnClick:(UIButton *)sender
  297. {
  298. // if (sender.tag == -1 || sender.tag == -2 || sender.tag == -3) {
  299. // UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"" message:@"建设中,暂未开放" preferredStyle:UIAlertControllerStyleAlert];
  300. // [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
  301. // [self presentViewController:alertC animated:YES completion:nil];
  302. // return;
  303. // }
  304. switch (sender.tag) {
  305. case -3://我的账户
  306. if (myDelegate.isLogin) {
  307. [self gotoVC:@"MyAccountVC"];
  308. }else{
  309. ShowMsg(@"请登录后再操作!");
  310. [self userLoginAction];
  311. }
  312. break;
  313. case -2://我要充值
  314. if (myDelegate.isLogin) {
  315. TopUpMoneyVC* vc = [[TopUpMoneyVC alloc] init];
  316. vc.type = 1;
  317. }else{
  318. ShowMsg(@"请登录后再操作!");
  319. [self userLoginAction];
  320. }
  321. break;
  322. case -1://资金明细
  323. if (myDelegate.isLogin) {
  324. [self gotoVC:@"MyAccountDetailVC"];
  325. }else{
  326. ShowMsg(@"请登录后再操作!");
  327. [self userLoginAction];
  328. }
  329. break;
  330. case 1://个人中心
  331. if (myDelegate.isLogin) {
  332. [self gotoStuDetaiVC];
  333. }else{
  334. ShowMsg(@"请登录后再操作!");
  335. [self userLoginAction];
  336. }
  337. break;
  338. case 2://@"教练计划"
  339. if (myDelegate.isLogin) {
  340. //如果是驾校学员
  341. if (defUser.userDict[@"outId"] && [defUser.userDict[@"outId"] length] > 0) {
  342. [self getSchPlaces];//跳转选择训练场地或者选择教练页面
  343. }else{
  344. SelectSchoolVC *selectVC = [[SelectSchoolVC alloc] init];
  345. selectVC.skipType = @"2";
  346. [self navPushHideTabbarToVC:selectVC];
  347. }
  348. }else{
  349. ShowMsg(@"请登录后再操作!");
  350. [self userLoginAction];
  351. }
  352. break;
  353. case 3://@"我的预约"
  354. if (myDelegate.isLogin) {
  355. if (defUser.userDict[@"outId"] && [defUser.userDict[@"outId"] length] > 0) {
  356. [self gotoVC:@"MyReserveVC"];
  357. }else{
  358. [self judgeLoginType];
  359. }
  360. }else{
  361. ShowMsg(@"请登录后再操作!");
  362. [self userLoginAction];
  363. }
  364. break;
  365. case 4://@"我的订单"
  366. {
  367. if (myDelegate.isLogin) {
  368. if (defUser.userDict[@"outId"] && [defUser.userDict[@"outId"] length] > 0) {
  369. [self gotoVC:@"MyOrderVC"];
  370. }else{
  371. [self judgeLoginType];
  372. }
  373. }else{
  374. ShowMsg(@"请登录后再操作!");
  375. [self userLoginAction];
  376. }
  377. }
  378. break;
  379. case 5://@"我的学时"
  380. {
  381. if (!myDelegate.isLogin) {
  382. ShowMsg(@"请登录后再操作!");
  383. [self userLoginAction];
  384. break;
  385. }
  386. if(defUser.userDict[@"outId"] && [defUser.userDict[@"outId"] length] > 0){
  387. [self gotoVC:@"TrainInfoVC"];
  388. }else{
  389. [self judgeLoginType];
  390. }
  391. }
  392. break;
  393. case 6://@"模拟器训练"
  394. {
  395. if (!myDelegate.isLogin) {
  396. ShowMsg(@"请登录后再操作!");
  397. [self userLoginAction];
  398. break;
  399. }
  400. /// RQ-MARk
  401. [Tools confirmImeiWithLogType:@"3" successBlock:^{
  402. [self gotoMNTrain];
  403. }];
  404. }
  405. break;
  406. case 7://@"大车"
  407. {
  408. if (!myDelegate.isLogin) {
  409. ShowMsg(@"请登录后再操作!");
  410. [self userLoginAction];
  411. break;
  412. }
  413. [Tools confirmImeiWithLogType:@"4" successBlock:^{
  414. [self gotoBigCar];
  415. }];
  416. }
  417. break;
  418. case 8: {
  419. if (!myDelegate.isLogin) {
  420. ShowMsg(@"请登录后再操作!");
  421. [self userLoginAction];
  422. break;
  423. }
  424. [Tools confirmImeiWithLogType:@"3" successBlock:^{
  425. ChangeSchoolListViewController *vc = [[ChangeSchoolListViewController alloc] init];
  426. [self navPushHideTabbarToVC:vc];
  427. }];
  428. break;
  429. }
  430. case 9: {
  431. if (!myDelegate.isLogin) {
  432. ShowMsg(@"请登录后再操作!");
  433. [self userLoginAction];
  434. break;
  435. }
  436. [Tools confirmImeiWithLogType:@"3" successBlock:^{
  437. [self getStuProtocolResult:^(BOOL isSuccess, NSString *urlStr) {
  438. if (isSuccess) {
  439. RQWebViewViewController *vc = [[RQWebViewViewController alloc] init];
  440. vc.webType = WebTypeStuProtocol;
  441. vc.url = urlStr;
  442. [self navPushHideTabbarToVC:vc];
  443. } else {
  444. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"该学员查询暂无报名合同!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil preferredActionTitle:nil completion:nil];
  445. }
  446. }];
  447. }];
  448. break;
  449. }
  450. case 10://@"线上咨询"
  451. {
  452. if (!myDelegate.isLogin)
  453. if (_isConnecting) {
  454. return;
  455. }
  456. _isConnecting = YES;
  457. [MBProgressHUD showLoadToView:self.view];
  458. // userId 只能使用 数字 字母(包括大小写) 下划线
  459. NSString *name = defUser.userDict[@"userName"];
  460. if ([defUser.userDict[@"userName"] length] < 1) {
  461. name = defUser.userDict[@"nickName"];
  462. }
  463. NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  464. name = [NSString stringWithFormat:@"%@[辽I学员_%@]",name,version];
  465. [QMConnect registerSDKWithAppKey:CUSTOMERSERVICE_APPKEY userName:name userId:[NSString stringWithFormat:@"%@",defUser.userDict[@"id"]]];
  466. }
  467. break;
  468. default:
  469. ShowMsg(@"暂未开通,敬请期待");
  470. break;
  471. }
  472. }
  473. - (void)judgeLoginType
  474. {
  475. NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
  476. NSDictionary *udDic = [ud objectForKey:@"jiaPeiLoginTest"];
  477. if ([udDic[@"loginType"] isEqualToString:@"1"]){
  478. ShowMsg(@"您的账号暂未在计时系统受理");
  479. }else{
  480. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"您的账号还未绑定学员账号" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"绑定", nil];
  481. [alert show];
  482. }
  483. }
  484. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  485. {
  486. if (buttonIndex != alertView.cancelButtonIndex) {
  487. //第三方登录 提示到绑定学员账号页面
  488. ThirdLoginBindYunGuanVC *vc = [[ThirdLoginBindYunGuanVC alloc] init];
  489. [self navPushHideTabbarToVC:vc];
  490. }
  491. }
  492. -(void)userLoginAction{
  493. LoginViewController* vc = [[LoginViewController alloc] init];
  494. vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  495. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  496. [self.parentViewController presentViewController:vc animated:YES completion:nil];
  497. }
  498. -(void)gotoVC:(NSString*)name
  499. {
  500. UIViewController* vc = [NSClassFromString(name) new];
  501. [self navPushHideTabbarToVC:vc];
  502. }
  503. -(void)gotoStuDetaiVC{
  504. StuDetailVC* vc = [[StuDetailVC alloc] init];
  505. vc.tag = 2;
  506. [self navPushHideTabbarToVC:vc];
  507. }
  508. - (void)getSchPlaces
  509. {
  510. if (![Util connectedToNetWork]) {
  511. ShowMsg(@"无网络连接");
  512. return;
  513. }
  514. NSMutableArray *arr=[NSMutableArray array];
  515. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  516. [arr addPro:@"jxbh" Value:defUser.userSchoolId];
  517. NSString* method = @"getSchPlaces";
  518. [MBProgressHUD showLoadToView:self.view];
  519. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  520. [MBProgressHUD hideHUDForView:self.view];
  521. if (!root) {
  522. [self goAllCoachPlanVC];
  523. return;
  524. }
  525. if ([root[@"code"] intValue] == 0) {
  526. if ([root[@"body"] count] < 1) {
  527. [self goAllCoachPlanVC];
  528. }else {
  529. FenceSiteVC *vc = [[FenceSiteVC alloc] init];
  530. vc.dataArray = root[@"body"];
  531. vc.dqbh = defUser.userDict[@"city"];
  532. [self navPushHideTabbarToVC:vc];
  533. }
  534. }else {
  535. [self goAllCoachPlanVC];
  536. }
  537. }];
  538. }
  539. // 获取学员合同
  540. - (void)getStuProtocolResult:(void (^)(BOOL isSuccess, NSString *urlStr))result {
  541. if (![Util connectedToNetWork]) {
  542. ShowMsg(@"无网络连接");
  543. return;
  544. }
  545. NSMutableArray *arr=[NSMutableArray array];
  546. [arr addPro:@"stuid" Value:defUser.userDict[@"outId"]];
  547. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  548. NSString* method = @"getStuProtocol";
  549. [MBProgressHUD showLoadToView:self.view];
  550. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  551. [MBProgressHUD hideHUDForView:self.view];
  552. if (!root) {
  553. ShowMsgFailed();
  554. return;
  555. }
  556. if ([root[@"code"] intValue] == 0) {
  557. if (root[@"data"] && ![root[@"data"] isEqualToString:@""]) {
  558. result(true, root[@"data"]);
  559. } else {
  560. result(false, @"");
  561. }
  562. }else {
  563. if (root[@"body"] && ![root[@"body"] isEqualToString:@""]) {
  564. ShowMsg(root[@"body"]);
  565. } else if (root[@"msg"] && ![root[@"msg"] isEqualToString:@""]) {
  566. ShowMsg(root[@"msg"]);
  567. } else {
  568. ShowMsg(@"数据异常");
  569. }
  570. result(false, @"");
  571. }
  572. }];
  573. }
  574. #pragma mark - gotoxxxx计时
  575. -(void)gotoMNTrain{
  576. if (myDelegate.mnTrainType == nil) {
  577. [self getCurrentState];
  578. return;
  579. }
  580. if ([myDelegate.dcTrainType isEqualToString:@"0"]) {
  581. showMsgByAlert(self, @"当前正在进行大客/货车计时");
  582. return;
  583. }
  584. NSString *kemu = [NSString stringWithFormat:@"%@",defUser.userDict[@"pxjd"]];
  585. if ([kemu isEqualToString:@"1"] || [kemu isEqualToString:@"4"]) {
  586. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"当前培训阶段无法进行模拟计时" preferredStyle:UIAlertControllerStyleAlert];
  587. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  588. [self presentViewController:alertFind animated:true completion:nil];
  589. return;
  590. }
  591. if (myDelegate.mnPeriodVC) {
  592. [self navPushHideTabbarToVC:myDelegate.mnPeriodVC];
  593. }else{
  594. switch ([myDelegate.mnTrainType integerValue]) {
  595. case 1:
  596. {
  597. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"请扫描模拟设备登录二维码" preferredStyle:UIAlertControllerStyleAlert];
  598. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  599. }]];
  600. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  601. [self openScan];
  602. }]];
  603. [self presentViewController:alertFind animated:true completion:nil];
  604. }
  605. break;
  606. default:
  607. [self gotoVC:@"MNQtTrainVC"];
  608. break;
  609. }
  610. }
  611. }
  612. #pragma mark 打开相机扫描二维码
  613. -(void)openScan{
  614. ScanVC *scan = [[ScanVC alloc] init];
  615. scan.type = @"2";
  616. [scan scanBlock:^(NSString *dataString) {
  617. if ([dataString isEqualToString:@"success"]) {
  618. myDelegate.mnTrainType = @"2";
  619. [self gotoVC:@"MNQtTrainVC"];
  620. }
  621. }];
  622. [self navPushHideTabbarToVC:scan];
  623. }
  624. -(void)gotoBigCar{
  625. if ([myDelegate.mnTrainType isEqualToString:@"0"]) {
  626. showMsgByAlert(self, @"当前正在进行模拟计时");
  627. return;
  628. }
  629. //判断培训类型
  630. NSArray *arr = @[@"A1",@"A2",@"A3",@"B1",@"B2"];
  631. if (![arr containsObject:defUser.userDict[@"carType"]]) {
  632. showMsgByAlert(self, [NSString stringWithFormat:@"您当前培训车型为%@,不允许进行大客/货车计时",defUser.userDict[@"carType"]]);
  633. return;
  634. }
  635. NSString *kemu = [NSString stringWithFormat:@"%@",defUser.userDict[@"pxjd"]];
  636. if ([kemu isEqualToString:@"1"] || [kemu isEqualToString:@"4"]) {
  637. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"当前培训阶段不允许进行大客/货车计时" preferredStyle:UIAlertControllerStyleAlert];
  638. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  639. [self presentViewController:alertFind animated:true completion:nil];
  640. return;
  641. }
  642. if (myDelegate.dcPeriodVC) {
  643. [self navPushHideTabbarToVC:myDelegate.dcPeriodVC];
  644. }else{
  645. [self gotoVC:@"BigTruckVC"];
  646. }
  647. }
  648. - (void)goAllCoachPlanVC{
  649. AllCoachPlanVC* vc = [[AllCoachPlanVC alloc] init];
  650. vc.searchJXBH = defUser.userSchoolId;
  651. [self navPushHideTabbarToVC:vc];
  652. }
  653. #pragma mark 网络请求
  654. //获取当前训练状态
  655. -(void)getCurrentState
  656. {
  657. [MBProgressHUD showMessage:@"正在获取当前训练状态" toView:self.view];
  658. //这个主要目的是为了更新本地学时编号等数据
  659. [LoginViewController getCurrentStateWithCompleteBlock:^(NSDictionary *root) {
  660. [MBProgressHUD hideHUDForView:self.view animated:NO];
  661. if (!root) {
  662. ShowMsg(@"请求失败");
  663. return;
  664. }
  665. if ([root[@"code"] isEqualToString:@"0"]) {
  666. [self gotoMNTrain];
  667. }else{
  668. ShowMsg(root[@"msg"]);
  669. }
  670. }];
  671. }
  672. #pragma mark 客服
  673. - (void)registerSuccess:(NSNotification *)sender {
  674. NSLog(@"注册成功");
  675. if (_isPushed) {
  676. [MBProgressHUD hideHUDForView:self.view];
  677. _isConnecting = NO;
  678. return;
  679. }
  680. [QMConnect sdkGetWebchatScheduleConfig:^(NSDictionary * _Nonnull scheduleDic) {
  681. dispatch_async(dispatch_get_main_queue(), ^{
  682. self.dictionary = scheduleDic;
  683. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  684. NSLog(@"日程管理");
  685. [self starSchedule];
  686. }else{
  687. NSLog(@"技能组");
  688. [self getPeers];
  689. }
  690. });
  691. } failBlock:^{
  692. }];
  693. }
  694. - (void)registerFailure:(NSNotification *)sender {
  695. NSLog(@"注册失败::%@", sender.object);
  696. self.isConnecting = NO;
  697. [MBProgressHUD hideHUDForView:self.view];
  698. }
  699. #pragma mark - 技能组选择
  700. - (void)getPeers {
  701. [QMConnect sdkGetPeers:^(NSArray * _Nonnull peerArray) {
  702. dispatch_async(dispatch_get_main_queue(), ^{
  703. NSLog(@"%@", peerArray);
  704. NSArray *peers = peerArray;
  705. self.isConnecting = NO;
  706. [MBProgressHUD hideHUDForView:self.view];
  707. if (peers.count == 1 && peers.count != 0) {
  708. [self showChatRoomViewController:[peers.firstObject objectForKey:@"id"] processType:@""];
  709. }else {
  710. [self showPeersWithAlert:peers messageStr:@"选择您咨询的类型或业务部门(对应技能组)"];
  711. }
  712. });
  713. } failureBlock:^{
  714. dispatch_async(dispatch_get_main_queue(), ^{
  715. [MBProgressHUD hideHUDForView:self.view];
  716. self.isConnecting = NO;
  717. });
  718. }];
  719. }
  720. #pragma mark - 日程管理
  721. - (void)starSchedule {
  722. self.isConnecting = NO;
  723. [MBProgressHUD hideHUDForView:self.view];
  724. if ([self.dictionary[@"scheduleId"] isEqual: @""] || [self.dictionary[@"processId"] isEqual: @""] || [self.dictionary objectForKey:@"entranceNode"] == nil || [self.dictionary objectForKey:@"leavemsgNodes"] == nil) {
  725. [QMAlert showMessage:@"对不起,由于在线咨询配置错误,暂时无法进行咨询"];
  726. }else{
  727. NSDictionary *entranceNode = self.dictionary[@"entranceNode"];
  728. NSArray *entrances = entranceNode[@"entrances"];
  729. NSLog(@" 获取到日程节点数组 ===== %@", entrances);
  730. // [self showPeersWithAlert: sdkEntrances];
  731. if (entrances.count == 1 && entrances.count != 0) {
  732. [self showChatRoomViewController:[entrances.firstObject objectForKey:@"processTo"] processType:[entrances.firstObject objectForKey:@"processType"]];
  733. }else{
  734. [self showPeersWithAlert:entrances messageStr:@"选择您咨询的日程管理类型"];
  735. }
  736. }
  737. }
  738. - (void)showPeersWithAlert: (NSArray *)peers messageStr: (NSString *)message {
  739. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择您咨询的类型或业务部门(对应技能组)" preferredStyle:UIAlertControllerStyleAlert];
  740. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  741. self.isConnecting = NO;
  742. }];
  743. [alertController addAction:cancelAction];
  744. for (NSDictionary *index in peers) {
  745. UIAlertAction *surelAction = [UIAlertAction actionWithTitle:[index objectForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  746. if ([self.dictionary[@"scheduleEnable"] integerValue] == 1) {
  747. [self showChatRoomViewController:[index objectForKey:@"processTo"] processType:[index objectForKey:@"processType"]];
  748. }else{
  749. [self showChatRoomViewController:[index objectForKey:@"id"] processType:@""];
  750. }
  751. }];
  752. [alertController addAction:surelAction];
  753. }
  754. [self presentViewController:alertController animated:YES completion:nil];
  755. }
  756. #pragma mark - 跳转聊天界面
  757. - (void)showChatRoomViewController:(NSString *)peerId processType:(NSString *)processType {
  758. QMChatRoomViewController *chatRoomViewController = [[QMChatRoomViewController alloc] init];
  759. chatRoomViewController.peerId = peerId;
  760. chatRoomViewController.isPush = NO;
  761. NSString *path = defUser.userDict[@"photo"];
  762. if (!path) {
  763. path = @"";
  764. }
  765. chatRoomViewController.avaterStr = path;
  766. if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
  767. chatRoomViewController.isOpenSchedule = true;
  768. chatRoomViewController.scheduleId = self.dictionary[@"scheduleId"];
  769. chatRoomViewController.processId = self.dictionary[@"processId"];
  770. chatRoomViewController.currentNodeId = peerId;
  771. chatRoomViewController.processType = processType;
  772. }else{
  773. chatRoomViewController.isOpenSchedule = false;
  774. }
  775. MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:chatRoomViewController];
  776. [nav.view setBackgroundColor:[UIColor whiteColor]];
  777. nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  778. nav.navigationBar.translucent = NO;
  779. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  780. [self.parentViewController presentViewController:nav animated:YES completion:nil];
  781. // 此处为了统一“退出登录”返回方式 就选择了present进去
  782. }
  783. - (NSMutableAttributedString *)setSpace:(CGFloat)line kern:(NSNumber *)kern font:(UIFont *)font text:(NSString *)text {
  784. NSMutableParagraphStyle * paraStyle = [NSMutableParagraphStyle new];
  785. paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
  786. paraStyle.alignment = NSTextAlignmentCenter;
  787. paraStyle.lineSpacing = line;
  788. paraStyle.hyphenationFactor = 1.0;
  789. paraStyle.firstLineHeadIndent = 0.0;
  790. paraStyle.paragraphSpacingBefore = 0.0;
  791. paraStyle.headIndent = 0;
  792. paraStyle.tailIndent = 0;
  793. NSDictionary *attributes = @{
  794. NSFontAttributeName: font,
  795. NSParagraphStyleAttributeName: paraStyle,
  796. NSKernAttributeName: kern
  797. };
  798. NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes];
  799. return attributeStr;
  800. }
  801. - (void)dealloc {
  802. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_SUCCEED object:nil];
  803. [[NSNotificationCenter defaultCenter] removeObserver:self name:CUSTOM_LOGIN_ERROR_USER object:nil];
  804. }
  805. - (void)didReceiveMemoryWarning {
  806. [super didReceiveMemoryWarning];
  807. }
  808. @end