SOPViewController.m 28 KB
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9 10 11 12 13
//
//  SOPViewController.m
//  redstar
//
//  Created by admin on 15/12/25.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "SOPViewController.h"
#import "GroupTabBar.h"
#import "GroupItems.h"
#import "SOPTableView.h"
#import "HttpClient.h"
14 15 16
#import "AttachmentTableViewCell.h"
#import "AttachmentModel.h"

admin's avatar
admin committed
17
#import "ReaderViewController.h"
admin's avatar
admin committed
18

admin's avatar
admin committed
19 20
#import <MBProgressHUD.h>

21
#define kAttachmentTableCell @"sopAttachmentCell"
admin's avatar
admin committed
22 23 24

#define SELECTED_VIEW_CONTROLLER_TAG 39998

admin's avatar
admin committed
25
@interface SOPViewController () <UIAlertViewDelegate,GroupTabBarDelegate, SOPTableViewDelegate, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate,ReaderViewControllerDelegate>
admin's avatar
admin committed
26 27 28
@property (nonatomic, strong) GroupTabBar *groupTabBar;

@property (nonatomic, strong) NSArray *titleArray;
admin's avatar
admin committed
29 30
@property (nonatomic, strong) NSArray *allTopicArray;
@property (nonatomic, strong) NSArray *allTableViewArray;
admin's avatar
admin committed
31

admin's avatar
admin committed
32
@property (nonatomic, strong) NSArray *titleArray0;
admin's avatar
admin committed
33 34 35 36 37 38 39 40
@property (nonatomic, strong) NSArray *titleArray1;
@property (nonatomic, strong) NSArray *titleArray2;
@property (nonatomic, strong) NSArray *titleArray3;
@property (nonatomic, strong) NSArray *titleArray4;
@property (nonatomic, strong) NSArray *titleArray5;
@property (nonatomic, strong) NSArray *titleArray6;
@property (nonatomic, strong) NSArray *titleArray7;
@property (nonatomic, strong) NSArray *titleArray8;
admin's avatar
admin committed
41
@property (nonatomic, strong) NSArray *titleArray9;
admin's avatar
admin committed
42

admin's avatar
admin committed
43
@property (nonatomic, assign) NSInteger row;
admin's avatar
admin committed
44 45 46 47

@property (nonatomic, strong) UIButton *resetBtn;
@property (nonatomic, strong) UIButton *queryBtn;

48 49 50 51
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *attachmentArray;
admin's avatar
admin committed
52

admin's avatar
admin committed
53 54
@property (nonatomic, strong) NSMutableDictionary *sopDict;

admin's avatar
admin committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
@end

@implementation SOPViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.translucent = NO;
    }
    
admin's avatar
admin committed
70 71
    [self setupData];
    
72 73
    self.attachmentArray = [NSMutableArray array];
    
admin's avatar
admin committed
74 75 76 77 78 79 80 81 82
    
    [self setupNav];
    
    [self setGroupBar];
    
    [self.resetBtn addTarget:self action:@selector(resetClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.queryBtn addTarget:self action:@selector(queryClick:) forControlEvents:UIControlEventTouchUpInside];
}

admin's avatar
admin committed
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
- (void)setupData
{
    self.titleArray = [NSArray arrayWithObjects:@"手册使用说明",@"服务口碑实施管理规定",@"质量管理",@"价格管理",@"现场服务",@"售后服务", @"环境管理",@"现场管理",@"400呼叫管理",@"单品管理",nil];
    self.titleArray0 = [NSArray arrayWithObjects:@"手册使用说明",nil];
    self.titleArray1 = [NSArray arrayWithObjects:@"服务口碑实施管理规定",nil];
    
    self.titleArray2 = [NSArray arrayWithObjects:@"商品环保、质量检测管理规定",@"商品资质管理规定",@"商场三年质保管理规定",@"绿色展陈管理规定", nil];
    self.titleArray3 = [NSArray arrayWithObjects:@"商品标价签管理规定",@"商品调价管理规定",@"商场全国大促活动执行管理规定",@"商户促销活动管理规定",@"“全场最低七折”管理规定", nil];
    self.titleArray4 = [NSArray arrayWithObjects:@"商场现场基本服务基本规范",@"便民服务管理规定",@"营业员管理规定",@"播音管理规定",@"商场实施管理者“顾客之声VOC”管理规定", @"30天无理由退货管理规定",@"15分钟退单管理规定",@"商场全员顾客服务规范管理规定",@"设计免费咨询管理规定",nil];
    self.titleArray5 = [NSArray arrayWithObjects:@"商场客诉处理管理规定",@"先行赔付管理规定",@"商品质量保证金管理规定",@"送货跟单回访管理规定", nil];
    self.titleArray6 = [NSArray arrayWithObjects:@"商场基础环境管理规范",@"口碑商场环境管理规范", @"商场停车场管理规定",@"商场洗手间管理规范",@"商场综合物料管理规定",nil];
    self.titleArray7 = [NSArray arrayWithObjects:@"楼层日常巡场管理规定",@"商户进/出货管理规定",@"商户进场管理规定",@"商户撤场管理规定",@"红星美凯龙商户信用等级评定办法", nil];
    self.titleArray8 = [NSArray arrayWithObjects:@"呼叫中心商场虚拟座席远程管理规定", nil];
    self.titleArray9 = [NSArray arrayWithObjects:@"商品信息管理规定", nil];
    
    self.allTopicArray = [NSMutableArray arrayWithObjects:_titleArray0, _titleArray1,_titleArray2,_titleArray3,_titleArray4,_titleArray5,_titleArray6,_titleArray7,_titleArray8,_titleArray9,nil];
    
    self.sopDict = [NSMutableDictionary dictionary];
    [_sopDict setObject:@"FFKB-SYSM" forKey:@"手册使用说明手册使用说明"];
    
    [_sopDict setObject:@"FFKB-SSGL-01" forKey:@"服务口碑实施管理规定服务口碑实施管理规定"];
    
    [_sopDict setObject:@"FFKB-ZLGL-01" forKey:@"质量管理商品环保、质量检测管理规定"];
    [_sopDict setObject:@"FFKB-ZLGL-02" forKey:@"质量管理商品资质管理规定"];
    [_sopDict setObject:@"FFKB-ZLGL-03" forKey:@"质量管理商场三年质保管理规定"];
    [_sopDict setObject:@"FFKB-ZLGL-04" forKey:@"质量管理绿色展陈管理规定"];
    
    [_sopDict setObject:@"FFKB-JGGL-01" forKey:@"价格管理商品标价签管理规定"];
    [_sopDict setObject:@"FFKB-JGGL-02" forKey:@"价格管理商品调价管理规定"];
    [_sopDict setObject:@"FFKB-JGGL-03" forKey:@"价格管理商场全国大促活动执行管理规定"];
    [_sopDict setObject:@"FFKB-JGGL-04" forKey:@"价格管理商户促销活动管理规定"];
    [_sopDict setObject:@"FFKB-JGGL-05" forKey:@"价格管理“全场最低七折”管理规定"];
    
    [_sopDict setObject:@"FFKB-XCFW-01" forKey:@"现场服务商场现场基本服务基本规范"];
    [_sopDict setObject:@"FFKB-XCFW-02" forKey:@"现场服务便民服务管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-03" forKey:@"现场服务营业员管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-04" forKey:@"现场服务播音管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-05" forKey:@"现场服务商场实施管理者“顾客之声VOC”管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-06" forKey:@"现场服务30天无理由退货管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-07" forKey:@"现场服务15分钟退单管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-08" forKey:@"现场服务商场全员顾客服务规范管理规定"];
    [_sopDict setObject:@"FFKB-XCFW-09" forKey:@"现场服务设计免费咨询管理规定"];
    
    [_sopDict setObject:@"FFKB-SHFW-01" forKey:@"售后服务商场客诉处理管理规定"];
    [_sopDict setObject:@"FFKB-SHFW-02" forKey:@"售后服务先行赔付管理规定"];
    [_sopDict setObject:@"FFKB-SHFW-03" forKey:@"售后服务商品质量保证金管理规定"];
    [_sopDict setObject:@"FFKB-SHFW-04" forKey:@"售后服务送货跟单回访管理规定"];
    
    [_sopDict setObject:@"FFKB-HJGL-01" forKey:@"环境管理商场基础环境管理规范"];
    [_sopDict setObject:@"FFKB-HJGL-02" forKey:@"环境管理口碑商场环境管理规范"];
    [_sopDict setObject:@"FFKB-HJGL-03" forKey:@"环境管理商场停车场管理规定"];
    [_sopDict setObject:@"FFKB-HJGL-04" forKey:@"环境管理商场洗手间管理规范"];
    [_sopDict setObject:@"FFKB-HJGL-05" forKey:@"环境管理商场综合物料管理规定"];
    
    [_sopDict setObject:@"FFKB-XCGL-01" forKey:@"现场管理楼层日常巡场管理规定"];
    [_sopDict setObject:@"FFKB-XCGL-02" forKey:@"现场管理商户进/出货管理规定"];
    [_sopDict setObject:@"FFKB-XCGL-03" forKey:@"现场管理商户进场管理规定"];
    [_sopDict setObject:@"FFKB-XCGL-04" forKey:@"现场管理商户撤场管理规定"];
    [_sopDict setObject:@"FFKB-XCGL-05" forKey:@"现场管理红星美凯龙商户信用等级评定办法"];
    
    [_sopDict setObject:@"FFKB-HJGL-01" forKey:@"400呼叫管理呼叫中心商场虚拟座席远程管理规定"];
    [_sopDict setObject:@"FFKB-DPGL-01" forKey:@"单品管理商品信息管理规定"];


}

admin's avatar
admin committed
149 150
- (void)resetClick:(UIButton *)sender
{
admin's avatar
admin committed
151 152 153 154 155 156
    NSInteger selectedIndex = 0;
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
    for (SOPTableView *sop in _allTableViewArray) {
        [sop selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    }
    _row = 0;
admin's avatar
admin committed
157 158 159 160
}

- (void)queryClick:(UIButton *)sender
{
admin's avatar
admin committed
161
    self.attachmentArray = [NSMutableArray array];
admin's avatar
admin committed
162 163
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kGetAttachmentsURL];
    HttpClient *http = [[HttpClient alloc] initWithUrl:url];
admin's avatar
admin committed
164 165 166
    
    NSMutableArray *titleArray = _allTopicArray[_groupTabBar.selectNumber];
    NSString *encode = [_sopDict objectForKey:[NSString stringWithFormat:@"%@%@", _titleArray[_groupTabBar.selectNumber],titleArray[_row]]];
admin's avatar
admin committed
167
    NSDictionary *parameters = @{@"type":@"sop",
admin's avatar
admin committed
168
                               @"encode":encode
admin's avatar
admin committed
169
                                 };
admin's avatar
admin committed
170
    NSLog(@"paaaaa  == %@", parameters);
admin's avatar
admin committed
171
    [http getAttachmentsWithParameters:parameters completion:^(id response, NSError *error) {
172
        NSArray *dataArray = response[@"data"];
admin's avatar
admin committed
173 174
        NSLog(@"sssss === %@", response);
        NSMutableArray *tempArray = [NSMutableArray array];
175 176 177
        for (NSDictionary *attaDict in dataArray) {
            AttachmentModel *atta = [[AttachmentModel alloc] init];
            [atta setValuesForKeysWithDictionary:attaDict];
admin's avatar
admin committed
178
            [tempArray addObject:atta];
179
        }
admin's avatar
admin committed
180
        _attachmentArray = tempArray;
181
        
admin's avatar
admin committed
182 183 184 185 186 187
        if (_attachmentArray.count == 0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"暂无附件!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
            return;
        }
        
188 189 190 191 192 193 194 195
        CGFloat tableH = _attachmentArray.count * 45;
        
        if (!_bgView) {
            _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
            UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeRedView)];
            [_bgView addGestureRecognizer:tapGR];
        }
        CGRect toFrame = CGRectMake(0, 0, kScreenWidth - 50, tableH + 40);
admin's avatar
admin committed
196 197 198 199 200
        
        if (_tableView) {
            [_tableView removeFromSuperview];
            _tableView = nil;
        }
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

        if (!_tableView) {
            _tableView = [[UITableView alloc] initWithFrame:toFrame style:UITableViewStyleGrouped];
            _tableView.backgroundColor = [UIColor whiteColor];
        }
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_bgView];
        [self.view insertSubview:_tableView aboveSubview:_bgView];
        
        _bgView.alpha = 0;
        _bgView.backgroundColor = [UIColor blackColor];
        
        _tableView.alpha = 0.0;
        _tableView.center = CGPointMake( _bgView.center.x, _bgView.center.y - 74);
        [UIView animateWithDuration:0.3 animations:^{
            _bgView.alpha = 0.6;
            _tableView.alpha = 1.0;
admin's avatar
admin committed
219
            [self.tableView reloadData];
220 221 222
        }];
        
        
admin's avatar
admin committed
223
    }];
admin's avatar
admin committed
224
   // _row = 0;
admin's avatar
admin committed
225 226
}

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
- (void)closeRedView
{
    [UIView animateWithDuration:0.3 animations:^{
        _bgView.alpha = .0f;
        _tableView.alpha = 0.0;
    } completion:^(BOOL finished) {
        [_bgView removeFromSuperview];
        [_tableView removeFromSuperview];
    }];
}

- (void)showFile:(UIButton *)sender
{
    NSInteger row = sender.tag - 998473;
    AttachmentModel *atta = _attachmentArray[row];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = paths.lastObject;
    NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:url]) {
admin's avatar
admin committed
248

admin's avatar
admin committed
249
        
admin's avatar
admin committed
250
        NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
admin's avatar
admin committed
251
        
admin's avatar
admin committed
252 253 254 255 256 257 258 259 260 261 262
        
        ReaderDocument *document = [ReaderDocument withDocumentFilePath:url password:phrase];
        
        if (document != nil) // Must have a valid ReaderDocument object in order to proceed with things
        {
            ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
            readerViewController.delegate = self; // Set the ReaderViewController delegate to self
            
            [self.navigationController pushViewController:readerViewController animated:YES];
        }

263 264 265 266 267 268
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请先下载在查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }
}

admin's avatar
admin committed
269
- (void)dismissReaderViewController:(ReaderViewController *)viewController
270
{
admin's avatar
admin committed
271 272 273 274 275
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
   
276 277
}

admin's avatar
admin committed
278 279


280 281 282 283 284 285 286 287
- (void)downloadFile:(UIButton *)sender
{
    NSInteger row = sender.tag - 998473;
    AttachmentModel *atta = _attachmentArray[row];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = paths.lastObject;
    
288 289
    NSString *fileName = [NSString stringWithFormat:@"%@", atta.fileName];
    [self downloadFileURL:[NSString stringWithFormat:@"%@%@", kRedStarURL, atta.fileUrl] savePath:path fileName:fileName];
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
}

- (void)downloadFileURL:(NSString *)aUrl savePath:(NSString *)aSavePath fileName:(NSString *)aFileName
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    //检查本地文件是否已存在
    NSString *fileName = [NSString stringWithFormat:@"%@/%@", aSavePath, aFileName];
    //检查附件是否存在
    if ([fileManager fileExistsAtPath:fileName]) {
    }else{
        
        //创建附件存储目录
        if (![fileManager fileExistsAtPath:aSavePath]) {
            [fileManager createDirectoryAtPath:aSavePath withIntermediateDirectories:YES attributes:nil error:nil];
        }
        //下载附件
307
        aUrl = [aUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
admin's avatar
admin committed
308
        NSLog(@"uri ==%@", aUrl);
309
        NSURL *url = [[NSURL alloc] initWithString:aUrl];
admin's avatar
admin committed
310 311
        
        
312 313 314 315 316 317 318
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        operation.inputStream   = [NSInputStream inputStreamWithURL:url];
        operation.outputStream  = [NSOutputStream outputStreamToFileAtPath:fileName append:NO];
        
        
admin's avatar
admin committed
319
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
320 321
        //已完成下载
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
322
            [self closeRedView];
323 324 325
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"下载成功!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            alert.tag = 66690;
            [alert show];
admin's avatar
admin committed
326
            [MBProgressHUD hideHUDForView:self.view animated:YES];
327
            [self.tableView reloadData];
328 329

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
330 331 332
            [self closeRedView];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"下载失败!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
admin's avatar
admin committed
333
            [MBProgressHUD hideHUDForView:self.view animated:YES];
334 335
            [self.tableView reloadData];

336 337
        }];
        
admin's avatar
admin committed
338 339
        
        
340 341 342 343 344
        [operation start];
    }
}


admin's avatar
admin committed
345 346 347 348
- (void)setupNav
{
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
349
    [customLab setText:@"营运标准"];
admin's avatar
admin committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 44);
    
    [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
}

- (void)setGroupBar
{
    self.groupTabBar = [[GroupTabBar alloc] initWithFrame:CGRectMake(0, 0, 120, kScreenHeight - 64 - 60)];
    _groupTabBar.delegate = self;
    [self.view addSubview:_groupTabBar];
    
    NSInteger selectedIndex = 0;
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
    
admin's avatar
admin committed
373 374 375 376
    SOPTableView *tableView0 = [[SOPTableView alloc] initWithTitleArray:_titleArray0];
    tableView0.sop_delegate = self;
    GroupItems *tableItem0 = [[GroupItems alloc] initWithTitle:_titleArray[0] view:tableView0];
    
admin's avatar
admin committed
377 378
    SOPTableView *tableView1 = [[SOPTableView alloc] initWithTitleArray:_titleArray1];
    tableView1.sop_delegate = self;
admin's avatar
admin committed
379
    GroupItems *tableItem1 = [[GroupItems alloc] initWithTitle:_titleArray[1] view:tableView1];
admin's avatar
admin committed
380 381 382
    
    SOPTableView *tableView2 = [[SOPTableView alloc] initWithTitleArray:_titleArray2];
    tableView2.sop_delegate = self;
admin's avatar
admin committed
383
    GroupItems *tableItem2 = [[GroupItems alloc] initWithTitle:_titleArray[2] view:tableView2];
admin's avatar
admin committed
384 385 386
    
    SOPTableView *tableView3 = [[SOPTableView alloc] initWithTitleArray:_titleArray3];
    tableView3.sop_delegate = self;
admin's avatar
admin committed
387
    GroupItems *tableItem3 = [[GroupItems alloc] initWithTitle:_titleArray[3] view:tableView3];
admin's avatar
admin committed
388 389 390
    
    SOPTableView *tableView4 = [[SOPTableView alloc] initWithTitleArray:_titleArray4];
    tableView4.sop_delegate = self;
admin's avatar
admin committed
391
    GroupItems *tableItem4 = [[GroupItems alloc] initWithTitle:_titleArray[4] view:tableView4];
admin's avatar
admin committed
392 393 394
    
    SOPTableView *tableView5 = [[SOPTableView alloc] initWithTitleArray:_titleArray5];
    tableView5.sop_delegate = self;
admin's avatar
admin committed
395
    GroupItems *tableItem5 = [[GroupItems alloc] initWithTitle:_titleArray[5] view:tableView5];
admin's avatar
admin committed
396 397 398
    
    SOPTableView *tableView6 = [[SOPTableView alloc] initWithTitleArray:_titleArray6];
    tableView6.sop_delegate = self;
admin's avatar
admin committed
399
    GroupItems *tableItem6 = [[GroupItems alloc] initWithTitle:_titleArray[6] view:tableView6];
admin's avatar
admin committed
400 401 402
    
    SOPTableView *tableView7 = [[SOPTableView alloc] initWithTitleArray:_titleArray7];
    tableView7.sop_delegate = self;
admin's avatar
admin committed
403
    GroupItems *tableItem7 = [[GroupItems alloc] initWithTitle:_titleArray[7] view:tableView7];
admin's avatar
admin committed
404 405 406
    
    SOPTableView *tableView8 = [[SOPTableView alloc] initWithTitleArray:_titleArray8];
    tableView8.sop_delegate = self;
admin's avatar
admin committed
407 408 409 410 411
    GroupItems *tableItem8 = [[GroupItems alloc] initWithTitle:_titleArray[8] view:tableView8];
    
    SOPTableView *tableView9 = [[SOPTableView alloc] initWithTitleArray:_titleArray9];
    tableView9.sop_delegate = self;
    GroupItems *tableItem9 = [[GroupItems alloc] initWithTitle:_titleArray[9] view:tableView9];
admin's avatar
admin committed
412
    
admin's avatar
admin committed
413
    [tableView0 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
admin's avatar
admin committed
414 415 416 417 418 419 420 421
    [tableView1 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView2 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView3 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView4 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView5 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView6 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView7 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [tableView8 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
admin's avatar
admin committed
422
    [tableView9 selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
admin's avatar
admin committed
423
    
admin's avatar
admin committed
424 425 426
    self.allTableViewArray = [NSMutableArray arrayWithObjects:tableView0,tableView1, tableView2,tableView3,tableView4,tableView5,tableView6,tableView7,tableView8,tableView9,nil];

    [self.view insertSubview:tableView0 belowSubview:_groupTabBar];
admin's avatar
admin committed
427 428 429 430 431 432 433 434
    [self.view insertSubview:tableView1 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView2 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView3 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView4 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView5 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView6 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView7 belowSubview:_groupTabBar];
    [self.view insertSubview:tableView8 belowSubview:_groupTabBar];
admin's avatar
admin committed
435 436
    [self.view insertSubview:tableView9 belowSubview:_groupTabBar];

admin's avatar
admin committed
437
    
admin's avatar
admin committed
438
    _groupTabBar.items = @[ tableItem0,tableItem1, tableItem2, tableItem3, tableItem4, tableItem5, tableItem6, tableItem7, tableItem8, tableItem9];
admin's avatar
admin committed
439 440 441 442 443 444 445
    [_groupTabBar showIndex:0];


}

-(void)doBack:(id)sender
{
446 447 448 449 450 451 452
    
//    if ([[self.navigationController.viewControllers objectAtIndex:0] isKindOfClass:[StandardViewController class]]) {
//        StandardViewController *masterVC = (StandardViewController *)[self.navigationController.viewControllers objectAtIndex:0];
//        [self.navigationController popToViewController:masterVC animated:YES];
//    }
//    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
admin's avatar
admin committed
453
}
454 455 456 457 458 459 460 461 462 463 464

#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 66690) {
        if (buttonIndex == 0) {
            [self.tableView reloadData];
        }
    }
}

465 466 467 468 469
#pragma mark - UITableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
admin's avatar
admin committed
470

471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _attachmentArray.count;
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    AttachmentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAttachmentTableCell];
    if (!cell) {
        cell = [[AttachmentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAttachmentTableCell];
    }
    AttachmentModel *atta = _attachmentArray[indexPath.row];
    NSString *name = atta.fileName;
    [cell.nameBtn setTitle:name forState:UIControlStateNormal];
487
    cell.nameBtn.titleLabel.numberOfLines = 0;
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
    
    [cell.nameBtn addTarget:self action:@selector(showFile:) forControlEvents:UIControlEventTouchUpInside];
    [cell.downloadBtn addTarget:self action:@selector(downloadFile:) forControlEvents:UIControlEventTouchUpInside];
    cell.downloadBtn.tag = 998473 + indexPath.row;
    cell.nameBtn.tag = 998473 + indexPath.row;
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = paths.lastObject;
    NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:url]) {
        cell.downloadBtn.selected = YES;
        cell.downloadBtn.backgroundColor = [UIColor grayColor];
    } else {
        cell.downloadBtn.selected = NO;
        cell.downloadBtn.backgroundColor = [UIColor colorWithRed:47 / 255.0 green:209/ 255.0 blue:92 / 255.0 alpha:1.0];
        
    }
    
    return cell;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 20, 40)];
    label.text = @"附件";
    label.textColor = kNavigationBarColor;
    label.font = [UIFont systemFontOfSize:14.0];
    [view addSubview:label];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
admin's avatar
admin committed
526 527

#pragma mark - SOPTableViewDelegate
admin's avatar
admin committed
528
- (void)selectRowWithDetailRow:(NSInteger)row
admin's avatar
admin committed
529
{
admin's avatar
admin committed
530
    _row = row;
admin's avatar
admin committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544
}

#pragma mark - GroupTabBarDelegate
- (void)switchView:(UIView *)view
{
    UIView *currentView = [self.view viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
    [currentView removeFromSuperview];
    currentView = nil;
    
    view.frame = CGRectMake(self.groupTabBar.frame.size.width,0,kScreenWidth - self.groupTabBar.frame.size.width, self.groupTabBar.size.height);
    
    view.tag = SELECTED_VIEW_CONTROLLER_TAG;
    
    [self.view insertSubview:view belowSubview:_groupTabBar];
admin's avatar
admin committed
545
    _row = 0;
admin's avatar
admin committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
}

#pragma mark - lazy loading
- (UIButton *)resetBtn
{
    if (!_resetBtn) {
        _resetBtn = [[UIButton alloc] init];
        _resetBtn.backgroundColor = [UIColor grayColor];
        _resetBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_resetBtn setTitle:@"重置" forState:UIControlStateNormal];
        _resetBtn.layer.cornerRadius = 4.0;
        [self.view addSubview:_resetBtn];
        
        NSLayoutConstraint *lineViewHeight = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
        [self.view addConstraint:lineViewHeight];
        
        NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-10];
        [self.view addConstraint:lineViewRight];
        
        NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-7.5];
        [self.view addConstraint:lineViewBottom];
        
        NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.view addConstraint:lineViewLeft];
    }
    return _resetBtn;
}

- (UIButton *)queryBtn
{
    if (!_queryBtn) {
        _queryBtn = [[UIButton alloc] init];
        _queryBtn.backgroundColor = kNavigationBarColor;
        _queryBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_queryBtn setTitle:@"查看附件" forState:UIControlStateNormal];
        _queryBtn.layer.cornerRadius = 4.0;
        [self.view addSubview:_queryBtn];
        
        NSLayoutConstraint *lineViewHeight = [NSLayoutConstraint constraintWithItem:_queryBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
        [self.view addConstraint:lineViewHeight];
        
        NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_queryBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.view addConstraint:lineViewRight];
        
        NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_queryBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-7.5];
        [self.view addConstraint:lineViewBottom];
        
        NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_queryBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:10];
        [self.view addConstraint:lineViewLeft];
    }
    return _queryBtn;
}


@end