123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- //
- // RQProfileViewModel.m
- // RQCommon
- //
- // Created by 张嵘 on 2018/11/21.
- // Copyright © 2018 张嵘. All rights reserved.
- //
- #import "RQProfileViewModel.h"
- #import "RQCustomWebViewViewController.h"
- #import "QMChatRoomViewController.h"
- #import <QMLineSDK/QMLineSDK.h>
- #import "QMAlert.h"
- @interface RQProfileViewModel ()
- @property (nonatomic, readwrite , copy) NSArray *menuInfoArr;
- @property (nonatomic, readwrite, strong) RACCommand *requestMenuInfoCommand;
- //客服
- @property (nonatomic, assign) BOOL isPushed; // 控制跳转
- @property (nonatomic, assign) BOOL isConnecting; // 控制多次注册
- @property (nonatomic, copy) NSDictionary * dictionary; //客服一些配置
- @end
- @implementation RQProfileViewModel
- - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params{
- if (self = [super initWithServices:services params:params]) {
- }
- return self;
- }
- - (void)initialize {
- [super initialize];
- @weakify(self);
- self.title = @"";
- self.prefersNavigationBarBottomLineHidden = YES;
- self.prefersNavigationBarHidden = YES;
- [self rq_configureData];
-
-
-
- // RAC(self, menuInfoArr) = self.requestMenuInfoCommand.executionSignals.switchToLatest;
- // /// 过滤错误信息
- // [[self.requestMenuInfoCommand.errors
- // filter:^(NSError *error) {
- // return YES;
- // }] subscribe:self.errors];
-
- [[self.requestMenuInfoCommand execute:nil] subscribeNext:^(id _Nullable x) {
- @strongify(self)
- self.menuInfoArr = x;
- } completed:^{
-
- }];
-
-
-
- [RQ_Profile_Module getVipInfo];
-
- //客服
- [[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];
- }
- - (RACCommand *)requestMenuInfoCommand {
- @weakify(self)
- return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
- @strongify(self)
- return [[self requestMenuInfoSignal] takeUntil:self.rac_willDeallocSignal];
- }];
- }
- - (RACSignal *)requestMenuInfoSignal {
- return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
- [[RQ_HTTP_Service getMenuInfo] subscribeNext:^(NSArray *arr) {
- NSArray *itemArr = [arr.rac_sequence.signal map:^id _Nullable(RQMenuInfoModel *menuInfoModel) {
- RQCommonCollectionItemViewModel *menuInfoItem = [RQCommonCollectionItemViewModel itemViewModelWithTitle:menuInfoModel.MENU_NAME icon:menuInfoModel.MENU_ICON];
- menuInfoItem.operation = ^{
- if ([menuInfoModel.MENU_TYPE isEqualToString:@"1"]) {
- [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:menuInfoModel.MENU_URL];
- } else if ([menuInfoModel.MENU_TYPE isEqualToString:@"2"]) {
- [RQ_SHARE_FUNCTION miniwithUserName:menuInfoModel.MENU_URL path:menuInfoModel.MENU_XCX_URL];
- } else if ([menuInfoModel.MENU_TYPE isEqualToString:@"3"]) {
- if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:menuInfoModel.MENU_URL]]) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:menuInfoModel.MENU_URL] options:@{} completionHandler:^(BOOL success) {}];
- } else {
- if (![menuInfoModel.MENU_WEB_URL isEqualToString:@""]) {
- [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:menuInfoModel.MENU_WEB_URL];
- } else {
- NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8",menuInfoModel.MENU_IOS];
- NSURL *url = [NSURL URLWithString:urlStr];
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
- }];
- }
- }
- } else if ([menuInfoModel.MENU_TYPE isEqualToString:@"4"]) {
- // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"是否捐赠少量资金" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{
- // [[RQ_HTTP_Service postPrepareOrderWithDictCode:35 userId:RQ_USER_MANAGER.currentUser._id] subscribeNext:^(RQPrepareOrderModel *prepareOrderModel) {
- // PayReq *req = [[PayReq alloc] init];
- // req.openID = RQ_WECHAT_MANAGER.appID;
- // req.partnerId = prepareOrderModel.partnerId;
- // req.prepayId = prepareOrderModel.prepayId;
- // req.package = prepareOrderModel.packageValue;
- // req.nonceStr = prepareOrderModel.nonceStr;
- // NSString * stamp = prepareOrderModel.timeStamp;
- // req.timeStamp = (UInt32)stamp.intValue;
- // req.sign = prepareOrderModel.sign;
- //// [RQWechatManager hangleWechatPayWith:req];
- // }];
- // } cancelAction:^{
- // }];
- }
- };
- return menuInfoItem;
- }].toArray;
- [subscriber sendNext:itemArr];
- } error:^(NSError * _Nullable error) {
- [subscriber sendError:error];
- } completed:^{
- [subscriber sendCompleted];
- }];
- return [RACDisposable disposableWithBlock:^{}];
- }];
- }
- #pragma mark - 配置数据
- - (void)rq_configureData {
- @weakify(self)
- /// 第一组
- RQCommonGroupViewModel *group0 = [RQCommonGroupViewModel groupViewModel];
-
- RQProfileUserAndVipItemViewModel *profileUserAndVipItemViewModel = [[RQProfileUserAndVipItemViewModel alloc] initViewModelWithUser:RQ_USER_MANAGER.currentUser];
- group0.itemViewModels = @[profileUserAndVipItemViewModel];
-
- /// 第二组
- RQCommonGroupViewModel *group1 = [RQCommonGroupViewModel groupViewModel];
- group1.footerHeight = 10.f;
- RQProfilePracticeItemViewModel *profilePracticeItemViewModel = [[RQProfilePracticeItemViewModel alloc] init];
- group1.itemViewModels = @[profilePracticeItemViewModel];
-
- /// 第三组
- RQProfileUserAndVipHeaderGroupViewModel *group2 = [RQProfileUserAndVipHeaderGroupViewModel groupViewModel];
- group2.header = @"我的工具";
-
- RQCommonCollectionItemViewModel *coupon = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"优惠券" icon:@"优惠券"];
- RQCommonCollectionItemViewModel *synchronizationProgress = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"同步进度" icon:@"同步进度"];
- synchronizationProgress.operation = ^{
- RQSynchronizationViewModel *synchronizationViewModel = [[RQSynchronizationViewModel alloc] initWithServices:self.services params:@{}];
- [self.services pushViewModel:synchronizationViewModel animated:YES];
- };
- RQCommonCollectionItemViewModel *myOrder = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"我的订单" icon:@"我的订单"];
- // RQCommonCollectionItemViewModel *retraining = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"复训" icon:@"复训"];
- RQCommonCollectionItemViewModel *transferQuery = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"转校查询" icon:@"转校"];
- transferQuery.operation = ^{
- @strongify(self)
- RQStudentChangeSchoolViewModel *studentChangeSchoolViewModel = [[RQStudentChangeSchoolViewModel alloc] initWithServices:self.services params:nil];
- [self.services pushViewModel:studentChangeSchoolViewModel animated:YES];
- };
-
- RQCommonCollectionItemViewModel *commonQuestion = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"常见问题" icon:@"常见问题"];
- commonQuestion.operation = ^{
- NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://support.qq.com/products/361288"]];
- RQCustomWebViewViewController *vc = [[RQCustomWebViewViewController alloc] init];
- vc.url = URL.absoluteString;
- vc.bodyDicArr = @[
- @{@"key" : @"nickname", @"value" : RQStringIsEmpty(RQ_USER_MANAGER.currentUser.userName)? @"游客" : RQ_USER_MANAGER.currentUser.userName},
- @{@"key" : @"avatar", @"value" : RQStringIsEmpty(RQ_USER_MANAGER.currentUser.photo)? @"" : RQ_USER_MANAGER.currentUser.photo},
- @{@"key" : @"openid", @"value" : RQStringIsEmpty(RQ_USER_MANAGER.currentUser.outId)? @"" : RQ_USER_MANAGER.currentUser.outId}
- ];
-
- RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc];
- [RQControllerHelper.topViewController presentViewController:nav animated:NO completion:nil];
- };
-
- RQCommonCollectionItemViewModel *test = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"电子资料" icon:@"电子资料"];
- test.operation = ^{
- NSLog(@"点击了-电子资料");
- [RQ_SHARE_FUNCTION miniwithUserName:RQ_COMMON_MANAGER.JSJP_XCX_NAME path:RQ_COMMON_MANAGER.JSJP_XCX_PAGE];
- };
-
- RQCommonCollectionItemViewModel *onlineService = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"联系客服" icon:@"联系客服"];
- onlineService.operation = ^{
- NSString *name = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.userName)? RQ_USER_MANAGER.currentUser.userName : (RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.nickName)? RQ_USER_MANAGER.currentUser.nickName : @"游客");
- name = [NSString stringWithFormat:@"%@[极I学员_%@]",name,RQ_APP_VERSION];
- [QMConnect registerSDKWithAppKey:@"74442d40-9dc6-11e7-957d-a30a08c3a2c0" userName:name userId:RQ_USER_MANAGER.currentUser._id];
- };
-
- // group2.itemViewModels = @[coupon, synchronizationProgress, myOrder, transferQuery];
- group2.itemViewModels = @[test, synchronizationProgress, transferQuery, onlineService];
- // group2.itemViewModels = @[test, synchronizationProgress, onlineService];
- /// 第四组
- RQProfileUserAndVipHeaderGroupViewModel *group3 = [RQProfileUserAndVipHeaderGroupViewModel groupViewModel];
- group3.header = @"优惠相关";
- RAC(group3, itemViewModels) = [RACObserve(self, menuInfoArr) takeUntil:self.rac_willDeallocSignal];
-
- /// 第五组
- RQProfileUserAndVipHeaderGroupViewModel *group4 = [RQProfileUserAndVipHeaderGroupViewModel groupViewModel];
- group4.header = @"其他";
- #if defined(DEBUG)||defined(_DEBUG)
- /// 调试模式
- RQCommonCollectionItemViewModel *debug = [RQCommonCollectionItemViewModel itemViewModelWithTitle:@"打开/关闭调试器" icon:@"assistivetouch"];
- debug.operation = ^{
- [[RQDebugTouchView sharedInstance] setHide:![RQDebugTouchView sharedInstance].isHide];
- [RQSharedAppDelegate.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
- };
- group4.itemViewModels = @[debug];
- #else
- /// 发布模式
- group4.itemViewModels = @[];
- #endif
-
-
-
- self.dataSource = group4.itemViewModels.count > 0? @[group0, group1, group2, group3, group4] : @[group0, group1, group2, group3];
- }
- #pragma mark 客服
- - (void)registerSuccess:(NSNotification *)sender {
- NSLog(@"注册成功");
- if (_isPushed) {
- [MBProgressHUD rq_showProgressHUD:@""];
- _isConnecting = NO;
- return;
- }
- [QMConnect sdkGetWebchatScheduleConfig:^(NSDictionary *scheduleDic) {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.dictionary = scheduleDic;
- if ([self.dictionary[@"scheduleEnable"] intValue] == 1) {
- NSLog(@"日程管理");
- [self starSchedule];
- }else{
- NSLog(@"技能组");
- [self getPeers];
- }
- });
- } failBlock:^(NSString *str) {
-
- }];
- }
- - (void)registerFailure:(NSNotification *)sender {
- NSLog(@"注册失败::%@", sender.object);
- self.isConnecting = NO;
- [MBProgressHUD rq_hideHUD];
- }
- #pragma mark - 技能组选择
- - (void)getPeers {
- @weakify(self)
- [QMConnect sdkGetPeers:^(NSArray * _Nonnull peerArray) {
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
- NSLog(@"%@", peerArray);
- NSArray *peers = peerArray;
- self.isConnecting = NO;
- [MBProgressHUD rq_hideHUD];
- if (peers.count == 1 && peers.count != 0) {
- [self showChatRoomViewController:[peers.firstObject objectForKey:@"id"] processType:@""];
- }else {
- [self showPeersWithAlert:peers messageStr:@"选择您咨询的类型或业务部门(对应技能组)"];
- }
- });
- } failureBlock:^(NSString *str) {
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
- [MBProgressHUD rq_hideHUD];
- self.isConnecting = NO;
- });
- }];
- }
- #pragma mark - 日程管理
- - (void)starSchedule {
- self.isConnecting = NO;
- [MBProgressHUD rq_hideHUD];
- 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];
- }
- [RQControllerHelper.currentViewController 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;
- }
- // MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:chatRoomViewController];
-
- // [nav.view setBackgroundColor:[UIColor whiteColor]];
- // nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- // nav.navigationBar.translucent = NO;
- // nav.modalPresentationStyle = UIModalPresentationFullScreen;
- // [RQControllerHelper.currentViewController.parentViewController presentViewController:nav animated:YES completion:nil];
-
- RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:chatRoomViewController];
- [RQControllerHelper.topViewController presentViewController:nav animated:YES completion:nil];
-
- // 此处为了统一“退出登录”返回方式 就选择了present进去
- }
- - (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];
- }
- #pragma mark - LazyLoad
- - (NSArray *)menuInfoArr {
- if (!_menuInfoArr) {
- _menuInfoArr = @[];
- }
- return _menuInfoArr;
- }
- @end
|