//
//  smallTableVController.m
//  Open
//
//  Created by gao on 2017/2/9.
//  Copyright © 2017年 黄江涛 . All rights reserved.
//

#import "smallTableVController.h"
#import "VoucherRecordViewController.h"
#import "regardTableViewController.h"
#import "postMessgaeTotal.h"
#import "XHChatQQ.h"

#import "LoginVC.h"





@interface smallTableVController ()
@property (strong, nonatomic) IBOutlet UITableView *tableViewController;
@property (weak, nonatomic) IBOutlet UITableViewCell *socialAuthentication;
@property (weak, nonatomic) IBOutlet UITableViewCell *VoucherCenter;
@property (weak, nonatomic) IBOutlet UITableViewCell *recommendFriend;
@property (weak, nonatomic) IBOutlet UITableViewCell *mineJourney;
@property (weak, nonatomic) IBOutlet UITableViewCell *messageFeedBack;
@property (weak, nonatomic) IBOutlet UITableViewCell *versionNumber;
@property (weak, nonatomic) IBOutlet UITableViewCell *lastNumber;

@property(nonatomic,strong)NSMutableArray *baocun;
@property(nonatomic,strong)PostMessageViewModel*postVM;
@property(nonatomic,strong)NSMutableArray *array_k1;
@property(nonatomic,strong)NSMutableArray *array_k2;
@property(nonatomic,strong)NSMutableArray *array_k3;
@property(nonatomic,strong)NSMutableArray *array_k4;
@property(nonatomic,strong)NSMutableArray *array_k5;

@end

@implementation smallTableVController
-(NSMutableArray *)baocun
{
    if (!_baocun) {
        _baocun=[NSMutableArray new];
    }
    return _baocun;
}
-(NSMutableArray *)array_k1
{
    if (!_array_k1) {
        _array_k1 =[NSMutableArray new];
    }
    return _array_k1;
}
-(NSMutableArray *)array_k2
{
    if (!_array_k2) {
        _array_k2 =[NSMutableArray new];
    }
    return _array_k2;
}
-(NSMutableArray *)array_k3
{
    if (!_array_k3) {
        _array_k3 =[NSMutableArray new];
    }
    return _array_k3;
}
-(NSMutableArray *)array_k4
{
    if (!_array_k4) {
        _array_k4 =[NSMutableArray new];
    }
    return _array_k4;
}
-(NSMutableArray *)array_k5
{
    if (!_array_k5) {
        _array_k5 =[NSMutableArray new];
    }
    return _array_k5;
}

-(PostMessageViewModel *)postVM
{
    if (!_postVM) {
        _postVM =[PostMessageViewModel new];
    }
    return _postVM;
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.toolbarHidden=YES;
    [self.tableViewController reloadData];
   
 //   [self getSuperData];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    
   NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    self.view.layer.cornerRadius=20.0;
    self.navigationController.toolbarHidden=YES;
    self.tableViewController.bounces=NO;
    self.tableViewController.scrollEnabled=NO;
    self.lastNumber.detailTextLabel.text =app_Version;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
     [self getSuperData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
//V1.3.2 注释了版本
//#pragma mark - Table view data source
//-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if (indexPath.row == 0) {
//        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//            governmentViewController *gVC   =   [[governmentViewController alloc]init];
//            gVC.hidesBottomBarWhenPushed =YES;
//            if ([getPeopleID getpeopleLimited]  ==YES) gVC.personPrivate =1; else gVC.personPrivate =0;
//            [self.navigationController pushViewController:gVC  animated:YES];
//
//        }else
//        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
//        }
//
//
//
//
//
//
//    }else if(indexPath.row ==1){
//        //        [self getUserInfoForPlatform:UMSocialPlatformType_QQ ];
//        //        [self shareWebPageToPlatformType:UMSocialPlatformType_QQ ];
//        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//            UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//
//            socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
//            vc.hidesBottomBarWhenPushed =YES;
//            [self.navigationController pushViewController:vc animated:YES];
//        }else
//        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
//
//        }
//
//    }else if(indexPath.row ==3){//4->3
//        //        self.mm =YES;
//        //        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        //        logViewController *tc=[sb instantiateViewControllerWithIdentifier:@"logViewControllers"];
//        //
//        //        tc.greybackgroundView.hidden =NO;
//        //        tc.shareFourView.hidden=NO;
//        //
//        //                [self.Delegate senderVC:self andPutOtherSan:NO];
//
//
//
//        //        self.greybackgroundView.hidden=NO;
//        //        self.greybackgroundView.hidden =NO;
//        //            [self getUserInfoForPlatform:UMSocialPlatformType_Sina];
//
//
//
//        //        tc.shareFourView.hidden =NO;
//        //        tc.greybackgroundView.hidden=NO;
//
//        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//            [self performSegueWithIdentifier:@"postMessageTWo" sender:self];
//        }else
//        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
//        }
//    }else if (indexPath.row == 4){//5->4
//
//    [self performSegueWithIdentifier:@"small" sender:self];
//
//    }else if (indexPath.row == 5){//6->5
////        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
////        VoucherRecordViewController *tc=[sb instantiateViewControllerWithIdentifier:@"feedbackViewController"];
////        [self.navigationController pushViewController:tc animated:YES];
////        if([XHChatQQ haveQQ])//是否有安装QQ客户端
////        {
////
////            //2.此处传入的QQ号,需开通QQ推广功能,不然"陌生人"无法向此QQ号发送临时消,(发送时会直接失败).
////            //开通QQ推广方法:1.打开QQ推广网址http://shang.qq.com并用QQ登录  2.点击顶部导航栏:推广工具  3.在弹出菜单中点击'立即免费开通' 即可
////            [XHChatQQ chatWithQQ:QQ_KEFU];//发起QQ临时会话
////
////
////
////
////        }
////        else
////        {
////            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备尚未安装QQ客户端,不能进行QQ临时会话" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
////            [alert show];
////        }
//        [self jumpToHTML5:@"http://v3.faqrobot.org/robot/wxChat.html?sysNum=150422973695622305" andJAnalytics:@"智能客服"];
//
//
//
//    }else if (indexPath.row == 6){//7->6
//        regardTableViewController *vc =[regardTableViewController sharedInstance];
//        vc.hidesBottomBarWhenPushed =YES;
//        [self.navigationController pushViewController:vc animated:YES];
//
//
//
//
//
//    }
////    else if (indexPath.row == 2){
////        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
////            UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
////
////            socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
////            vc.record = 1;
////            vc.hidesBottomBarWhenPushed =YES;
////            [self.navigationController pushViewController:vc animated:YES];
////        }else
////        {
////            LoginViewController *logVC =    [LoginViewController sharedInstance];
////            logVC.hidesBottomBarWhenPushed =YES;
////            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
////                [self.navigationController pushViewController:logVC animated:YES];
////            }
////        }
////
////    }
//else if (indexPath.row == 2){//3->2
//        // 这里写等于3 的时候怎么办
//        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//            chooseAddressViewController*once  = [sb instantiateViewControllerWithIdentifier:@"chooseAddressViewController"];
//            once.isSearch = YES;
//            once.hidesBottomBarWhenPushed =YES;
//            [self.navigationController pushViewController:once animated:YES];
//        }else
//        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
//        }
//
//
//    }
//
//}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"small"])  {
        logViewController *avc = segue.destinationViewController;
        avc.changeView=YES;
        avc.greybackgroundView.hidden=NO;
        avc.shareFourView.hidden=NO;
        //    avc.hidesBottomBarWhenPushed =YES;
    }
    if ([segue.identifier isEqualToString:@"postMessageTWo"])  {
        postMessgaeTotal *blueVC = segue.destinationViewController;
        if (self.baocun.count >0) {
            blueVC.superData = [self.baocun copy];
        }
        if (self.array_k1.count >0) {
            blueVC.superChildData_1 =[self.array_k1 copy];
        }
        if (self.array_k2.count >0) {
            blueVC.superChildData_2 =[self.array_k2 copy];
        }
        if (self.array_k3.count >0) {
            blueVC.superChildData_3 =[self.array_k3 copy];
        }
        if (self.array_k4.count >0) {
            blueVC.superChildData_4 =[self.array_k4 copy];
        }
        if (self.array_k5.count >0) {
            blueVC.superChildData_5 =[self.array_k5 copy];
        }
        blueVC.isMyPublish =YES;
        blueVC.hidesBottomBarWhenPushed=YES;
    }
    
    
    
//    if ([segue.identifier isEqualToString:@"postMessageTWo"])  {
//        postMessgaeTotal *blueVC = segue.destinationViewController;
//
//        blueVC.superData = [self.baocun copy];
//        blueVC.superChildData_1 =[self.array_k1 copy];
//        blueVC.superChildData_2 =[self.array_k2 copy];
//        blueVC.superChildData_3 =[self.array_k3 copy];
//        blueVC.superChildData_4 =[self.array_k4 copy];
//        blueVC.superChildData_5 =[self.array_k5 copy];
//        blueVC.isMyPublish =YES;
//        blueVC.hidesBottomBarWhenPushed=YES;
//    }
}


-(void)getSuperData
{
    
    [postMessageMNet getSuperCatalogcompletionHandle:^(postMessageModel *model, NSError *error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //              [self.baocun addObjectsFromArray:model.Result];
            [self.baocun removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [self.baocun addObject:models.categoryname];
                    NSLog(@"_superData:%@",self.baocun);
                }
            }
            
        });
    }];
    
    __weak __typeof(self)weakSelf = self;
    [postMessageMNet getChildCatalog:1 completionHandle:^(postMessageModel *model, NSError *error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [weakSelf.array_k1 removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [weakSelf.array_k1 addObject:models.categoryname];
                    NSLog(@"_superData:%@",weakSelf.array_k1);
                }
                
            }
            
        });
    }];
    [postMessageMNet getChildCatalog:2 completionHandle:^(postMessageModel *model, NSError *error) {
        [self.array_k2 removeAllObjects];
        if (model.Result.count >0) {
            for (postMessageResultModel *models in model.Result) {
                
                [self.array_k2 addObject:models.categoryname];
            }
        }
        
    }];
    [postMessageMNet getChildCatalog:3 completionHandle:^(postMessageModel *model, NSError *error) {
        [self.array_k3 removeAllObjects];
        if (model.Result.count >0) {
            for (postMessageResultModel *models in model.Result) {
                
                [self.array_k3 addObject:models.categoryname];
            }
        }
        
    }];
    [postMessageMNet getChildCatalog:4 completionHandle:^(postMessageModel *model, NSError *error) {
        [self.array_k4 removeAllObjects];
        if (model.Result.count >0) {
            for (postMessageResultModel *models in model.Result) {
                
                [self.array_k4 addObject:models.categoryname];
            }
        }
        
    }];
    [postMessageMNet getChildCatalog:5 completionHandle:^(postMessageModel *model, NSError *error) {
        [self.array_k5 removeAllObjects];
        if (model.Result.count >0) {
            for (postMessageResultModel *models in model.Result) {
                
                [self.array_k5 addObject:models.categoryname];
            }
        }
        
    }];
    
}

- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        if ([getPeopleID getpeopleLimited]  ==NO) {
            return 0;
        }else{
            if([[UIScreen mainScreen]bounds].size.height == 480)
                return 33;  else  return  44;
        }
    }else{
        if([[UIScreen mainScreen]bounds].size.height == 480)
                 return 33;  else  return  44;
    }

}

-(void)jumpToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    WebViewController *tc=[sb instantiateViewControllerWithIdentifier:@"webViewController"];
    tc.URL =[NSURL URLWithString:url];
    tc.hidesBottomBarWhenPushed =YES;
    tc.janalytics = janalytics;
    [self.navigationController pushViewController:tc animated:YES];
    
    
    
}


#pragma mark - Table view data source
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            
            governmentViewController *gVC   =   [[governmentViewController alloc]init];
            gVC.hidesBottomBarWhenPushed =YES;
            if ([getPeopleID getpeopleLimited]  ==YES) gVC.personPrivate =1; else gVC.personPrivate =0;
            [self.navigationController pushViewController:gVC  animated:YES];
            
        }else
        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
            
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
        }
        
        
        
        
        
        
    }else if(indexPath.row ==1){
        //        [self getUserInfoForPlatform:UMSocialPlatformType_QQ ];
        //        [self shareWebPageToPlatformType:UMSocialPlatformType_QQ ];
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            
            socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
            vc.hidesBottomBarWhenPushed =YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else
        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
            
        }
        
    }else if(indexPath.row ==4){//4->3
        //        self.mm =YES;
        //        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        //        logViewController *tc=[sb instantiateViewControllerWithIdentifier:@"logViewControllers"];
        //
        //        tc.greybackgroundView.hidden =NO;
        //        tc.shareFourView.hidden=NO;
        //
        //                [self.Delegate senderVC:self andPutOtherSan:NO];
        
        
        
        //        self.greybackgroundView.hidden=NO;
        //        self.greybackgroundView.hidden =NO;
        //            [self getUserInfoForPlatform:UMSocialPlatformType_Sina];
        
        
        
        //        tc.shareFourView.hidden =NO;
        //        tc.greybackgroundView.hidden=NO;
        
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            [self performSegueWithIdentifier:@"postMessageTWo" sender:self];
        }else
        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
        }
    }else if (indexPath.row == 5){//5->4
        
        [self performSegueWithIdentifier:@"small" sender:self];
        
    }else if (indexPath.row == 6){//6->5
        //        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        //        VoucherRecordViewController *tc=[sb instantiateViewControllerWithIdentifier:@"feedbackViewController"];
        //        [self.navigationController pushViewController:tc animated:YES];
        //        if([XHChatQQ haveQQ])//是否有安装QQ客户端
        //        {
        //
        //            //2.此处传入的QQ号,需开通QQ推广功能,不然"陌生人"无法向此QQ号发送临时消,(发送时会直接失败).
        //            //开通QQ推广方法:1.打开QQ推广网址http://shang.qq.com并用QQ登录  2.点击顶部导航栏:推广工具  3.在弹出菜单中点击'立即免费开通' 即可
        //            [XHChatQQ chatWithQQ:QQ_KEFU];//发起QQ临时会话
        //
        //
        //
        //
        //        }
        //        else
        //        {
        //            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备尚未安装QQ客户端,不能进行QQ临时会话" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        //            [alert show];
        //        }
        [self jumpToHTML5:@"https://nginx.weface.com.cn/appH5/appoutlink/#/customer" andJAnalytics:@"智能客服"];
        
        
        
    }else if (indexPath.row == 7){//7->6
        regardTableViewController *vc =[regardTableViewController sharedInstance];
        vc.hidesBottomBarWhenPushed =YES;
        [self.navigationController pushViewController:vc animated:YES];
        
        
        
        
        
    }
        else if (indexPath.row == 2){
            if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
                socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
                vc.record = 1;
                vc.hidesBottomBarWhenPushed =YES;
                [self.navigationController pushViewController:vc animated:YES];
            }else
            {
//                LoginViewController *logVC =    [LoginViewController sharedInstance];
//                logVC.hidesBottomBarWhenPushed =YES;
//                if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                    [self.navigationController pushViewController:logVC animated:YES];
//                }
                LoginVC *loginVC = [[LoginVC alloc]init];
                UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                [self presentViewController:nav animated:YES completion:nil];
            }
    
        }
    else if (indexPath.row == 3){//3->2
        // 这里写等于3 的时候怎么办
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            chooseAddressViewController*once  = [sb instantiateViewControllerWithIdentifier:@"chooseAddressViewController"];
            once.isSearch = YES;
            once.hidesBottomBarWhenPushed =YES;
            [self.navigationController pushViewController:once animated:YES];
        }else
        {
//            LoginViewController *logVC =    [LoginViewController sharedInstance];
//            logVC.hidesBottomBarWhenPushed =YES;
//            if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                [self.navigationController pushViewController:logVC animated:YES];
//            }
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
        }
        
        
    }
    
}


@end
