RightViewController.m 7.54 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  RightViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/28.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RightViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "AppDelegate.h"
11 12
#import "RightControlSectionView.h"
#import "RightControlTableViewCell.h"
13 14 15 16 17





曹云霄's avatar
曹云霄 committed
18 19
@interface RightViewController ()<UITableViewDataSource,UITableViewDelegate>

20 21 22 23 24 25

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

/**
 *  section数据源
 */
26
@property (nonatomic,strong) NSMutableArray *dataArray;
27 28 29 30 31

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

/**
34
 *  控制section 闭合开启
35
 */
36
@property (nonatomic,strong) NSMutableArray *sectionClosedArray;
37 38 39 40

/**
 *  图片数组
 */
曹云霄's avatar
曹云霄 committed
41
@property (nonatomic,strong) NSArray *imageArray;
曹云霄's avatar
曹云霄 committed
42

43
/**
44
 *  指示线
45
 */
46 47
@property (nonatomic,strong) UIView *lineView;

曹云霄's avatar
曹云霄 committed
48 49 50 51 52

@end

@implementation RightViewController

曹云霄's avatar
曹云霄 committed
53 54 55 56 57
/**
 *  初始化数据源
 *
 *  @return NSArray
 */
58
- (NSMutableArray *)dataArray
曹云霄's avatar
曹云霄 committed
59 60
{
    if (_dataArray == nil) {
61 62
        _dataArray = [NSMutableArray arrayWithObjects:@"体验中心",@"体验中心3D",@"场景库",@"产品库",@"客户管理",@"学习中心",@"关于", nil];
        //判断是否有学习中心权限
63
        if ([[Shoppersmanager manager].shoppers.employee.userKey rangeOfString:@"学习人员"].location == NSNotFound) {
64 65
            [_dataArray removeObject:@"学习中心"];
        }
曹云霄's avatar
曹云霄 committed
66 67 68 69
    }
    return _dataArray;
}

70 71 72
- (NSArray *)subSectionArray
{
    if (!_subSectionArray) {
73
        _subSectionArray = @[@"",@"",@"",@"",@[@"所有客户",@"客户订单"],@"",@""];
74 75 76
    }
    return _subSectionArray;
}
曹云霄's avatar
曹云霄 committed
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
- (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;
}
曹云霄's avatar
曹云霄 committed
99 100 101 102 103 104 105 106

/**
 *  图片
 */
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
107
        _imageArray = [NSArray arrayWithObjects:@"tiyan",@"3DCenter",@"changjing",@"chanping",@"kehu",@"Learningcenter",@"guanyu", nil];
曹云霄's avatar
曹云霄 committed
108 109 110 111
    }
    return _imageArray;
}

曹云霄's avatar
曹云霄 committed
112 113
- (void)viewDidLoad {
    [super viewDidLoad];
114
    [self createHeaderview];
曹云霄's avatar
曹云霄 committed
115 116 117 118 119 120
    [self uiConfigAction];
}

#pragma mark -布局
- (void)uiConfigAction
{
121
    self.rightTableview.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
122
    [self.rightTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"rightcell"];
123
    [self.rightTableview registerClass:[RightControlSectionView class] forHeaderFooterViewReuseIdentifier:@"RightControlSectionView"];
曹云霄's avatar
曹云霄 committed
124 125 126 127 128
}

#pragma mark -头部视图
- (void)createHeaderview
{
129 130 131 132 133 134 135
    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];
136
    label.text = @"功能菜单";
勾芒's avatar
勾芒 committed
137
    label.font = [UIFont boldSystemFontOfSize:20];
138
    [label setTextColor:[UIColor whiteColor]];
139
    [navigationView addSubview:label];
勾芒's avatar
勾芒 committed
140
    label.textAlignment = NSTextAlignmentCenter;
141 142
    [self.view addSubview:navigationView];
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, NavigationHeight)];
143
    self.rightTableview.tableHeaderView = headerView;
曹云霄's avatar
曹云霄 committed
144 145
}

勾芒's avatar
勾芒 committed
146

曹云霄's avatar
曹云霄 committed
147 148
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
149
    RightControlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RightControlTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
150
    cell.sectionTitle.text = self.subSectionArray[indexPath.section][indexPath.row];
151 152
    return cell;
    
曹云霄's avatar
曹云霄 committed
153 154 155 156
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
157
    BOOL controlClose = [self.sectionClosedArray[section] boolValue];
158
    if (section == 4) {
曹云霄's avatar
曹云霄 committed
159 160
        NSArray *subArray = self.subSectionArray[section];
        return controlClose?subArray.count:0;
161 162
    }
    return 0;
曹云霄's avatar
曹云霄 committed
163
}
曹云霄's avatar
曹云霄 committed
164

曹云霄's avatar
曹云霄 committed
165 166
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
167 168 169
    RightControlTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    CGPoint point = [cell convertPoint:cell.sectionTitle.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
曹云霄's avatar
曹云霄 committed
170
    [self closeSidebarAndPassEvents:self.subSectionArray[indexPath.section][indexPath.row]];
曹云霄's avatar
曹云霄 committed
171 172
}

曹云霄's avatar
曹云霄 committed
173 174 175 176
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
曹云霄's avatar
曹云霄 committed
177

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    RightControlSectionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"RightControlSectionView"];
    sectionView.sectionTitle.text = [self.dataArray objectAtIndex_opple:section];
    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;
}
曹云霄's avatar
曹云霄 committed
202

203 204
#pragma mark - section Click
- (void)sectionClickAction:(UITapGestureRecognizer *)sender
曹云霄's avatar
曹云霄 committed
205
{
206
    NSInteger index = sender.view.tag;
207
    if (index == 4) {
208 209 210
        BOOL controlClose = [self.sectionClosedArray[index] boolValue];
        self.sectionClosedArray[index] = controlClose?@0:@1;
        [self.rightTableview reloadSections:[NSIndexSet indexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationFade];
曹云霄's avatar
曹云霄 committed
211
    }else{
212
        self.sectionClosedArray[4] = @0;
曹云霄's avatar
曹云霄 committed
213
        NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc]init];
214
        [indexSet addIndex:4];
曹云霄's avatar
曹云霄 committed
215
        [self.rightTableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
216
       [self closeSidebarAndPassEvents:self.dataArray[index]];
曹云霄's avatar
曹云霄 committed
217
    }
218 219 220
    RightControlSectionView *sectionView = (RightControlSectionView *)sender.view;
    CGPoint point = [sender.view convertPoint:sectionView.sectionImageView.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
曹云霄's avatar
曹云霄 committed
221 222
}

223 224 225 226
#pragma mark - 收起侧边栏并传递事件
- (void)closeSidebarAndPassEvents:(NSString *)name
{
    [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
227 228
    if ([self.delegate respondsToSelector:@selector(selectedControllerWithIndex:)]) {
        [self.delegate selectedControllerWithIndex:name];
229 230 231 232 233 234 235 236 237 238 239
    }
}

#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];
}
曹云霄's avatar
曹云霄 committed
240

曹云霄's avatar
曹云霄 committed
241 242 243 244 245 246 247
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end