RightViewController.m 7.54 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
//
//  RightViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/28.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RightViewController.h"
#import "AppDelegate.h"
#import "RightControlSectionView.h"
#import "RightControlTableViewCell.h"





@interface RightViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (weak, nonatomic) IBOutlet UITableView *rightTableview;

/**
 *  section数据源
 */
@property (nonatomic,strong) NSMutableArray *dataArray;

/**
 *  客户管理下级菜单
 */
@property (nonatomic,strong) NSArray *subSectionArray;

/**
 *  控制section 闭合开启
 */
@property (nonatomic,strong) NSMutableArray *sectionClosedArray;

/**
 *  图片数组
 */
@property (nonatomic,strong) NSArray *imageArray;

/**
 *  指示线
 */
@property (nonatomic,strong) UIView *lineView;


@end

@implementation RightViewController

/**
 *  初始化数据源
 *
 *  @return NSArray
 */
- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray arrayWithObjects:@"体验中心",@"体验中心3D",@"场景库",@"产品库",@"客户管理",@"学习中心",@"关于", nil];
        //判断是否有学习中心权限
        if ([[Shoppersmanager manager].shoppers.employee.userKey rangeOfString:@"学习人员"].location == NSNotFound) {
            [_dataArray removeObject:@"学习中心"];
        }
    }
    return _dataArray;
}

- (NSArray *)subSectionArray
{
    if (!_subSectionArray) {
        _subSectionArray = @[@"",@"",@"",@"",@[@"所有客户",@"客户订单"],@"",@""];
    }
    return _subSectionArray;
}

- (NSMutableArray *)sectionClosedArray
{
    if (!_sectionClosedArray) {
        _sectionClosedArray = [NSMutableArray array];
        //** @0表示闭合,@1表示开启 */
        for (int i=0; i<self.dataArray.count; i++) {
            [_sectionClosedArray addObject:@0];
        }
    }
    return _sectionClosedArray;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = kMainBlueColor;
        [self.rightTableview addSubview:_lineView];
    }
    return _lineView;
}

/**
 *  图片
 */
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
        _imageArray = [NSArray arrayWithObjects:@"tiyan",@"3DCenter",@"changjing",@"chanping",@"kehu",@"Learningcenter",@"guanyu", nil];
    }
    return _imageArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createHeaderview];
    [self uiConfigAction];
}

#pragma mark -布局
- (void)uiConfigAction
{
    self.rightTableview.tableFooterView = [UIView new];
    [self.rightTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"rightcell"];
    [self.rightTableview registerClass:[RightControlSectionView class] forHeaderFooterViewReuseIdentifier:@"RightControlSectionView"];
}

#pragma mark -头部视图
- (void)createHeaderview
{
    UIView *navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, NavigationHeight)];
    navigationView.layer.shadowColor = [UIColor blackColor].CGColor;
    navigationView.layer.shadowRadius = 4;
    navigationView.layer.shadowOpacity = 0.5;
    navigationView.layer.shadowOffset = CGSizeMake(0,0);
    navigationView.backgroundColor = kMainBlueColor;
    UILabel *label = [[UILabel alloc] initWithFrame:navigationView.frame];
    label.text = @"功能菜单";
    label.font = [UIFont boldSystemFontOfSize:20];
    [label setTextColor:[UIColor whiteColor]];
    [navigationView addSubview:label];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:navigationView];
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, NavigationHeight)];
    self.rightTableview.tableHeaderView = headerView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RightControlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RightControlTableViewCell" forIndexPath:indexPath];
    cell.sectionTitle.text = self.subSectionArray[indexPath.section][indexPath.row];
    return cell;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    BOOL controlClose = [self.sectionClosedArray[section] boolValue];
    if (section == 4) {
        NSArray *subArray = self.subSectionArray[section];
        return controlClose?subArray.count:0;
    }
    return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RightControlTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    CGPoint point = [cell convertPoint:cell.sectionTitle.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
    [self closeSidebarAndPassEvents:self.subSectionArray[indexPath.section][indexPath.row]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    RightControlSectionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"RightControlSectionView"];
曹云霄's avatar
曹云霄 committed
181
    sectionView.sectionTitle.text = [self.dataArray objectAtIndex_opple:section];
曹云霄's avatar
曹云霄 committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    sectionView.sectionImageView.image = TCImage(self.imageArray[section]);
    sectionView.tag = section;
    [sectionView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionClickAction:)]];
    return sectionView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}

#pragma mark - section Click
- (void)sectionClickAction:(UITapGestureRecognizer *)sender
{
    NSInteger index = sender.view.tag;
    if (index == 4) {
        BOOL controlClose = [self.sectionClosedArray[index] boolValue];
        self.sectionClosedArray[index] = controlClose?@0:@1;
        [self.rightTableview reloadSections:[NSIndexSet indexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationFade];
    }else{
        self.sectionClosedArray[4] = @0;
        NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc]init];
        [indexSet addIndex:4];
        [self.rightTableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
       [self closeSidebarAndPassEvents:self.dataArray[index]];
    }
    RightControlSectionView *sectionView = (RightControlSectionView *)sender.view;
    CGPoint point = [sender.view convertPoint:sectionView.sectionImageView.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
}

#pragma mark - 收起侧边栏并传递事件
- (void)closeSidebarAndPassEvents:(NSString *)name
{
    [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
    if ([self.delegate respondsToSelector:@selector(selectedControllerWithIndex:)]) {
        [self.delegate selectedControllerWithIndex:name];
    }
}

#pragma mark - 添加指示线
- (void)addInstructionsLine:(CGFloat)offsetY
{
    WS(weakSelf);
    [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
        weakSelf.lineView.frame = CGRectMake(0, offsetY, 10, 25);
    } completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end