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

#import "AddQuestionViewController.h"
#import "OnLineTableViewCell.h"

#import "AddQuestionFooterView.h"
#import "CheckPicViewController.h"
admin's avatar
admin committed
14 15 16
#import "InspectAddCell.h"
#import "InspectPicAddCell.h"
#import "InpectPictureCell.h"
admin's avatar
admin committed
17 18 19
#import "CommonFunc.h"
#import "HttpClient.h"
#import <MBProgressHUD.h>
admin's avatar
admin committed
20
#import "AddQuestionTableCell.h"
admin's avatar
admin committed
21
#import "UIImage+Fit.h"
22
#import "LargePictureViewController.h"
admin's avatar
admin committed
23

admin's avatar
admin committed
24 25
#define kPhotoTag 3339922

admin's avatar
admin committed
26
#define CATEGORYLIST @"服务", @"环境企划", @"环境物业",@"价格",@"质量",@"商户信用分类",@"审批比价采购",@"送货跟单",@"指标",@"其他", nil
admin's avatar
admin committed
27
#define QUESTIONLIST @"15分钟退单", @"便民服务", @"基础管理",@"轻松购系统",@"全员服务",@"人员信息",@"营运物流及服务硬件", nil
admin's avatar
admin committed
28

admin's avatar
admin committed
29 30 31

#define kAddQuestionCell @"UITableViewCellIdentifier"

admin's avatar
admin committed
32
@interface AddQuestionViewController () <UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate, UITextViewDelegate>
admin's avatar
admin committed
33 34 35
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) AddQuestionFooterView *footerView;
admin's avatar
admin committed
36
@property (nonatomic, strong) NSMutableArray *imageNameArray;
admin's avatar
admin committed
37
@property (nonatomic, strong) NSArray *titleArray;
admin's avatar
admin committed
38 39

@property (nonatomic, strong) NSString *imageMD5;
admin's avatar
admin committed
40 41 42 43

@property (nonatomic, strong) UIActionSheet *categoryActionSheet;
@property (nonatomic, strong) UIActionSheet *questionActionSheet;

44 45
@property (nonatomic, strong) UIActionSheet *selectActionSheet;

admin's avatar
admin committed
46 47
@property (nonatomic ,strong) UILabel *selectLabel;
@property (nonatomic ,strong) UILabel *selectLabel1;
admin's avatar
admin committed
48
@property (nonatomic, assign) int rowNumber;
admin's avatar
admin committed
49

admin's avatar
admin committed
50
@property (nonatomic, strong) NSMutableDictionary *saveDict;
admin's avatar
admin committed
51 52

@property (nonatomic, strong) NSMutableArray *categoryArray;
admin's avatar
admin committed
53 54
@property (nonatomic, strong) NSMutableArray *questionArray;

admin's avatar
admin committed
55 56 57
@property (nonatomic, assign) NSInteger categoryNum;
@property (nonatomic, assign) NSInteger questionNum;

admin's avatar
admin committed
58 59 60
@property (nonatomic) BOOL isComplete;
@property (nonatomic) BOOL isLoad;
@property (nonatomic, strong) NSMutableDictionary *groupUuidDict;
admin's avatar
admin committed
61 62 63 64 65 66
@end

@implementation AddQuestionViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
admin's avatar
admin committed
67 68 69
    
    self.categoryArray = [NSMutableArray array];
    self.questionArray = [NSMutableArray array];
admin's avatar
admin committed
70

71 72
    self.view.backgroundColor = kFootViewBackGroundColor;
    
admin's avatar
admin committed
73 74 75 76 77 78
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"新问题提报"];
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
79 80 81 82 83 84 85 86
    
    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;
    
admin's avatar
admin committed
87
    self.imageNameArray = [NSMutableArray array];
88

admin's avatar
admin committed
89 90
    self.titleArray = [NSArray arrayWithObjects:@"选择对应专业组", @"选择问题分类", nil];
    [self addTableView];
admin's avatar
admin committed
91

admin's avatar
admin committed
92
    
93
    // takePhoto代理
admin's avatar
admin committed
94
    [self.footerView.reportBtn addTarget:self action:@selector(upLoadQuestionPic:) forControlEvents:UIControlEventTouchUpInside];
admin's avatar
admin committed
95
    
admin's avatar
admin committed
96
    [self requestGroupTitle];
admin's avatar
admin committed
97 98
    
    _rowNumber = 4;
admin's avatar
admin committed
99 100
    _categoryNum = 0;
    _questionNum = 0;
admin's avatar
admin committed
101 102
    _isComplete = NO;
    _isLoad = NO;
admin's avatar
admin committed
103 104
}

admin's avatar
admin committed
105 106
// 请求问题专业组
- (void)requestGroupTitle
admin's avatar
admin committed
107
{
admin's avatar
admin committed
108
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionGroupURL]];
admin's avatar
admin committed
109
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
admin's avatar
admin committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    [httpClient getQuestionGroupWithCompletion:^(id response, NSError *error) {
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSMutableArray *nameArray = [NSMutableArray array];
        for (NSDictionary *groupDict in dataArray) {
            NSString *name = [NSString stringWithFormat:@"%@", groupDict[@"name"]];
            NSString *groupUuid = [NSString stringWithFormat:@"%@", groupDict[@"uuid"]];
            [dict setObject:groupUuid forKey:name];
            [nameArray addObject:name];
        }
        _groupUuidDict = dict;
        _categoryArray = nameArray;
        _isComplete = YES;
        
        if (nameArray.count != 0) {
            NSString *nameStr = [NSString stringWithFormat:@"%@", nameArray[0]];
            [self requestCategoryWithGroupUuid:[dict objectForKey:nameStr]];
        }
admin's avatar
admin committed
129
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
admin's avatar
admin committed
130 131 132 133

        [self.tableView reloadData];
    }];
}
admin's avatar
admin committed
134

admin's avatar
admin committed
135 136 137 138 139
- (void)requestCategoryWithGroupUuid:(NSString *)groupUuid
{
    NSString *url = [NSString stringWithFormat:@"%@%@%@",kRedStarURL, kQuestionCategoryURL, groupUuid];
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    HttpClient *http = [[HttpClient alloc] initWithUrl:url];
admin's avatar
admin committed
140
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
admin's avatar
admin committed
141
    [http getQuestionCategoryWithCompletion:^(id response, NSError *error) {
admin's avatar
admin committed
142 143 144 145 146 147
        NSDictionary *dictData = response[@"data"];
        NSArray *array = dictData[@"records"];
        NSMutableArray *categoryArray = [NSMutableArray array];
        for (NSDictionary *dict in array) {
            NSString *category = [NSString stringWithFormat:@"%@", dict[@"name"]];
            [categoryArray addObject:category];
admin's avatar
admin committed
148
        }
admin's avatar
admin committed
149 150 151 152
        _questionArray = categoryArray;
        _isLoad = YES;
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [self.tableView reloadData];
admin's avatar
admin committed
153
    }];
admin's avatar
admin committed
154 155
}

admin's avatar
admin committed
156

admin's avatar
admin committed
157 158 159 160 161 162
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Private Methods
163

admin's avatar
admin committed
164 165
- (void)upLoadQuestionPic:(UIButton *)sender
{
admin's avatar
admin committed
166 167 168 169 170 171 172 173 174 175 176
    if ([_selectLabel.text isEqualToString:@"请选择"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"请选择对应专业组" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        return;
    }
    
    if ([_selectLabel1.text isEqualToString:@"请选择"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"请选择问题分类" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        return;
    }
admin's avatar
admin committed
177 178
    
    
179 180 181
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要提交新问题吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag = 9211232;
    [alert show];
admin's avatar
admin committed
182 183 184
    
}

185 186 187 188 189
// 返回上一页面
- (void)doBack:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
admin's avatar
admin committed
190 191
- (void)showPicture:(UIButton *)sender
{
192 193 194 195 196 197 198 199 200 201 202 203
    LargePictureViewController *lager = [[LargePictureViewController alloc] init];
    lager.index = sender.tag - kPhotoTag;
    lager.pictureSaveMode = PictureLocalMode;
    lager.allImageArray = _imageNameArray;
    [self.navigationController pushViewController:lager animated:YES];
    
//    CheckPicViewController *checkVC = [[CheckPicViewController alloc] init];
//    NSString *imageName = _imageNameArray[sender.tag - kPhotoTag];
//    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
//    UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
//    checkVC.checkImage = image;
//    [self.navigationController pushViewController:checkVC animated:YES];
admin's avatar
admin committed
204
}
205

admin's avatar
admin committed
206 207
- (void)addTableView
{
admin's avatar
admin committed
208
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kAddQuestionCell];
admin's avatar
admin committed
209
    self.tableView.tableFooterView = self.footerView;
210
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
admin's avatar
admin committed
211 212
}

admin's avatar
admin committed
213
- (void)createImagePicker:(UIButton *)sender
admin's avatar
admin committed
214
{
215 216 217 218 219 220
    self.selectActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"直接拍照上传", @"从本地相册选择", nil];
    _selectActionSheet.delegate = self;
    _selectActionSheet.tag = 999283;
    [_selectActionSheet showInView:self.view];
    
    
admin's avatar
admin committed
221 222
    if (sender.tag == 2201) {
        _rowNumber++;
admin's avatar
admin committed
223
    }
admin's avatar
admin committed
224 225 226
}


admin's avatar
admin committed
227

admin's avatar
admin committed
228
- (void)saveImage:(UIImage *)currentImage {
admin's avatar
admin committed
229 230
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
    
admin's avatar
admin committed
231
    NSString *imageName = [CommonFunc md5Data:imageData];
admin's avatar
admin committed
232 233 234 235 236
    [_imageNameArray addObject:imageName];
    
    
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
admin's avatar
admin committed
237 238 239
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}
admin's avatar
admin committed
240

241 242 243
#pragma mark - UIImagePickerController 代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
admin's avatar
admin committed
244
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
admin's avatar
admin committed
245
    [self saveImage:image];
246 247
    
    // 退出图片选择控制器
admin's avatar
admin committed
248 249 250 251 252
    [picker dismissViewControllerAnimated:YES completion:^{
        [self.tableView reloadData];
    }];
    
}
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
#pragma mark - UITextView Delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
    AddQuestionTableCell *cell = (AddQuestionTableCell *)[_tableView cellForRowAtIndexPath:indexPath];

    if (![text isEqualToString:@""]) {
        if (textView.tag == 1001) {
            cell.placeholderLabel1.hidden = YES;
        } else {
            cell.placeholderLabel2.hidden = YES;
        }
    }
    
    if ([text isEqualToString:@""] && range.location == 0 && range.length == 1) {
        if (textView.tag == 1001) {
            cell.placeholderLabel1.hidden = NO;
        } else {
            cell.placeholderLabel2.hidden = NO;
        }
    }
    
    if ([text isEqualToString:@"\n"]) {
        [cell.titleTextView resignFirstResponder];
        [cell.contentTextView resignFirstResponder];
        
        if (textView.tag == 1001) {
            if (textView.text.length != 0) {
                cell.placeholderLabel1.hidden = YES;
            } else {
                cell.placeholderLabel1.hidden = NO;
            }
        } else {
            if (textView.text.length != 0) {
                cell.placeholderLabel2.hidden = YES;
            } else {
                cell.placeholderLabel2.hidden = NO;
            }
        }
        return NO;
    }
    
    if (range.location>=500) {
        return  NO;
    }
    else {
        return YES;
    }
    
    
    return YES;
}

admin's avatar
admin committed
307 308 309
#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    if (alertView.tag == 90393) {
        if (buttonIndex == 0) {
            [self.navigationController popViewControllerAnimated:YES];
            NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
            [notification postNotificationName:kRefreshQuestionNotification object:self];
        }
    } else if (alertView.tag == 9211232) {
        if (buttonIndex == 0) {
            return;
        } else {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
            
            AddQuestionTableCell *cell = (AddQuestionTableCell *)[_tableView cellForRowAtIndexPath:indexPath];
            
            NSString *title = [cell titleTextView].text;
            NSString *content = [cell contentTextView].text;
            
            NSDictionary *parameters;
            if (_imageNameArray.count == 0) {
admin's avatar
admin committed
329 330
                parameters = @{@"category":_selectLabel1.text,
                               @"group":_selectLabel.text,
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
                               @"title":content,
                               @"content":title
                               };
            } else {
                NSMutableArray *imageArray = [NSMutableArray array];
                for (int i = 0; i < _imageNameArray.count; i++) {
                    NSString *imageName = _imageNameArray[i];
                    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
                    UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
                    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
                    NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0];
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    [dict setObject:imageBase64 forKey:@"fileContent"];
                    [dict setObject:imageName forKey:@"fileName"];
                    [dict setObject:@(i) forKey:@"index"];
                    [imageArray addObject:dict];
                }
                
admin's avatar
admin committed
349 350
                parameters = @{@"category":_selectLabel1.text,
                               @"group":_selectLabel.text,
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
                               @"title":content,
                               @"content":title,
                               @"attachments":imageArray};
            }
            
            
            NSDate *date = [NSDate date];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"YYYY-MM-dd+hh:mm:ss"];
            NSString *dateString = [dateFormatter stringFromDate:date];
            
            NSString *operId = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_code"];
            NSString *operName = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"];
            
            
            NSString *url = [NSString stringWithFormat:@"%@%@?time=%@&operId=%@&operName=%@", kRedStarURL, kUpLoadQuestionURL, dateString, operId, operName];
            url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
            
            HttpClient *client = [[HttpClient alloc] initWithUrl:url];
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            [client uploadNewQuestionWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
372 373
                                
                if ([response[@"success"] boolValue]) {
374 375 376 377 378 379 380 381 382 383
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"新问题提报成功!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    alert.tag = 90393;
                    [alert show];
                    [MBProgressHUD hideHUDForView:self.view animated:YES];
                } else {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"新问题提报失败!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                }
            }];
        }
admin's avatar
admin committed
384
    }
385 386
}

admin's avatar
admin committed
387 388


admin's avatar
admin committed
389 390 391
#pragma mark - TableView Delegate/DateSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
admin's avatar
admin committed
392
    return _rowNumber;
admin's avatar
admin committed
393 394 395 396 397
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
398 399 400 401 402 403 404 405 406 407 408
    if (indexPath.row < 2) {
        
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAddQuestionCell];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAddQuestionCell];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"%@", _titleArray[indexPath.row]];
        cell.textLabel.font = [UIFont systemFontOfSize:16.0];
        cell.textLabel.textColor = kOnLineCellTitleColor;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
409 410 411
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, kScreenWidth, 1)];
        line.backgroundColor = kSeparateLineColor;
        [cell.contentView addSubview:line];
admin's avatar
admin committed
412
        
admin's avatar
admin committed
413 414 415 416 417 418 419 420 421 422 423 424
        NSString *cateStr = nil;
        
        if (_categoryArray.count != 0) {
            if (_isComplete) {
                cateStr = _categoryArray[_categoryNum];
            } else {
                cateStr = @"";
            }
        } else {
            cateStr = @"";
        }
        
admin's avatar
admin committed
425
        
admin's avatar
admin committed
426 427 428 429
        if (indexPath.row == 0) {
            if (!self.selectLabel) {
                _selectLabel = [[UILabel alloc] init];
            }
admin's avatar
admin committed
430
            _selectLabel.text = cateStr;
admin's avatar
admin committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
            _selectLabel.translatesAutoresizingMaskIntoConstraints = NO;
            _selectLabel.textColor = kOnLineCellDetailColor;
            _selectLabel.textAlignment = NSTextAlignmentRight;
            _selectLabel.translatesAutoresizingMaskIntoConstraints = NO;
            _selectLabel.font = [UIFont systemFontOfSize:15.0];
            [cell.contentView addSubview:_selectLabel];
            // 顶端
            NSLayoutConstraint *selectTop = [NSLayoutConstraint constraintWithItem:_selectLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectTop];
            
            // 左边
            NSLayoutConstraint *selectRight = [NSLayoutConstraint constraintWithItem:_selectLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectRight];
            
            // 高度
            NSLayoutConstraint *selectBottom = [NSLayoutConstraint constraintWithItem:_selectLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectBottom];
            
            // 高度
            NSLayoutConstraint *selectHeight = [NSLayoutConstraint constraintWithItem:_selectLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
            [cell.contentView addConstraint:selectHeight];

        } else {
            if (!self.selectLabel1) {
                self.selectLabel1 = [[UILabel alloc] init];
            }
admin's avatar
admin committed
457 458 459 460 461 462 463 464 465 466 467 468 469
            
            if (_questionArray.count != 0) {
                if (_isLoad) {
                    _selectLabel1.text = _questionArray[_questionNum];
                } else {
                    _selectLabel1.text = @"";
                }
            } else {
                _selectLabel1.text = @"";
            }
            
            
            
admin's avatar
admin committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
            _selectLabel1.translatesAutoresizingMaskIntoConstraints = NO;
            _selectLabel1.textColor = kOnLineCellDetailColor;
            _selectLabel1.textAlignment = NSTextAlignmentRight;
            _selectLabel1.translatesAutoresizingMaskIntoConstraints = NO;
            _selectLabel1.font = [UIFont systemFontOfSize:15.0];
            [cell.contentView addSubview:_selectLabel1];
            // 顶端
            NSLayoutConstraint *selectTop = [NSLayoutConstraint constraintWithItem:_selectLabel1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectTop];
            
            // 左边
            NSLayoutConstraint *selectRight = [NSLayoutConstraint constraintWithItem:_selectLabel1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectRight];
            
            // 高度
            NSLayoutConstraint *selectBottom = [NSLayoutConstraint constraintWithItem:_selectLabel1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
            [cell.contentView addConstraint:selectBottom];
            
            // 高度
            NSLayoutConstraint *selectHeight = [NSLayoutConstraint constraintWithItem:_selectLabel1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
            [cell.contentView addConstraint:selectHeight];

        }
        return cell;
    } else if (indexPath.row == 2){
        AddQuestionTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"kAddQuestionCell"];
        if (!cell) {
            cell = [[AddQuestionTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"kAddQuestionCell"];
        }
499 500
        cell.titleTextView.delegate = self;
        cell.contentTextView.delegate = self;
501 502
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

admin's avatar
admin committed
503 504 505 506 507 508 509 510 511 512 513
        return cell;
    } else if (indexPath.row == _rowNumber - 1) {
        if ((_imageNameArray.count + 1) % 2 == 0) {
            NSString *identifier = [NSString stringWithFormat:@"InspectaddPicCell"];
            InspectPicAddCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
            if (!cell) {
                cell = [[InspectPicAddCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            }
            NSString *imageName = _imageNameArray[_imageNameArray.count - 1];
            NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
            UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
admin's avatar
admin committed
514
            UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
admin's avatar
admin committed
515
            cell.photoButton1.tag = kPhotoTag + _imageNameArray.count - 1;
516 517
            [cell.photoButton1 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];

admin's avatar
admin committed
518
            [cell.photoButton1 setImage:image00 forState:UIControlStateNormal];
admin's avatar
admin committed
519 520 521
            
            cell.photoButton2.tag = 2201;
            [cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
522
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
admin's avatar
admin committed
523 524 525 526 527 528 529 530
            return cell;
        } else {
            
            NSString *identifier = [NSString stringWithFormat:@"InspectaddCell"];
            InspectAddCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
            if (!cell) {
                cell = [[InspectAddCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            }
531 532
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

admin's avatar
admin committed
533 534 535 536 537
            cell.photoButton.tag = 2200;
            [cell.photoButton addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
        }
admin's avatar
admin committed
538 539 540 541
        
        
    } else {
        
admin's avatar
admin committed
542 543 544 545 546 547 548 549
        NSString *identifier = [NSString stringWithFormat:@"InspectPictureCell"];
        InpectPictureCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[InpectPictureCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        NSString *imageName0 = _imageNameArray[(indexPath.row - 3) * 2];
        NSString *fullPath0 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName0];
        UIImage *image0 = [UIImage imageWithContentsOfFile:fullPath0];
admin's avatar
admin committed
550
        UIImage *image00 = [UIImage image:image0 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
admin's avatar
admin committed
551
        [cell.photoButton1 setImage:image00 forState:UIControlStateNormal];
admin's avatar
admin committed
552
        
admin's avatar
admin committed
553 554 555
        NSString *imageName1 = _imageNameArray[(indexPath.row - 3) * 2 + 1];
        NSString *fullPath1 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName1];
        UIImage *image1 = [UIImage imageWithContentsOfFile:fullPath1];
admin's avatar
admin committed
556
        UIImage *image11 = [UIImage image:image1 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
admin's avatar
admin committed
557
        [cell.photoButton2 setImage:image11 forState:UIControlStateNormal];
admin's avatar
admin committed
558 559 560 561 562 563 564
        
        [cell.photoButton1 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
        cell.photoButton1.tag = kPhotoTag + (indexPath.row - 3) * 2;
        
        [cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
        cell.photoButton2.tag = kPhotoTag + (indexPath.row - 3) * 2 + 1;

admin's avatar
admin committed
565
        return cell;
admin's avatar
admin committed
566 567
    }

admin's avatar
admin committed
568 569 570 571
    
    
}

admin's avatar
admin committed
572 573 574
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
admin's avatar
admin committed
575 576 577 578 579 580
        self.categoryActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
        
        for (NSString *groupName in _categoryArray) {
            [_categoryActionSheet addButtonWithTitle:groupName];
        }
        
admin's avatar
admin committed
581 582 583
        _categoryActionSheet.delegate = self;
        [_categoryActionSheet showInView:self.view];

admin's avatar
admin committed
584
    } else if (indexPath.row == 1) {
admin's avatar
admin committed
585
        self.questionActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
admin's avatar
admin committed
586 587
    
        for (NSString *selectStr in _questionArray) {
admin's avatar
admin committed
588 589 590
            [_questionActionSheet addButtonWithTitle:selectStr];
        }
        
admin's avatar
admin committed
591 592
        _questionActionSheet.delegate = self;
        [_questionActionSheet showInView:self.view];
admin's avatar
admin committed
593 594
    } else {
        return;
admin's avatar
admin committed
595 596 597 598 599 600 601
    }
}

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
    if (actionSheet.tag == 999283) {
        if (buttonIndex == 0) {
            if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"找不到相机" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alert show];
            } else {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.delegate = self;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                picker.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
                picker.videoQuality = UIImagePickerControllerQualityTypeLow;
                [self presentViewController:picker animated:YES completion:nil];
            }
        } else if (buttonIndex == 1){
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self;
            //设置选择后的图片可被编辑
            picker.allowsEditing = YES;
            [self presentViewController:picker animated:YES completion:nil];
        }
    }
    
    
admin's avatar
admin committed
626 627
    if (actionSheet == _categoryActionSheet) {
        
admin's avatar
admin committed
628 629 630 631 632 633
        if ((buttonIndex -1) < _categoryArray.count) {
            _selectLabel.text = [_categoryArray objectAtIndex:(buttonIndex -1)];
            _categoryNum = (buttonIndex -1);
            NSString *groupUuid = [_groupUuidDict objectForKey:_selectLabel.text];
            _isLoad = NO;
            [self requestCategoryWithGroupUuid:groupUuid];
admin's avatar
admin committed
634 635
            _questionNum = 0;
            [self.tableView reloadData];
admin's avatar
admin committed
636
        }
637
    } else if (actionSheet == _questionActionSheet){
admin's avatar
admin committed
638
        
admin's avatar
admin committed
639 640
        if ((buttonIndex -1) < _questionArray.count) {
            _selectLabel1.text = [_questionArray objectAtIndex:(buttonIndex -1)];
admin's avatar
admin committed
641
            _questionNum = buttonIndex - 1;
admin's avatar
admin committed
642 643 644 645
        }
    }
}

admin's avatar
admin committed
646 647 648 649 650 651 652 653 654 655 656

#pragma mark - lazy loading
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        _tableView.translatesAutoresizingMaskIntoConstraints = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
admin's avatar
admin committed
657 658
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 100.0;
admin's avatar
admin committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
        [self.view addSubview:_tableView];
        
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self.view addConstraint:tableTop];
        
        NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:tableLeft];
        
        NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:tableRight];
        
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

- (AddQuestionFooterView *)footerView
{
    if (!_footerView) {
679
        _footerView = [[AddQuestionFooterView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 65)];
admin's avatar
admin committed
680 681 682 683
    }
    return _footerView;
}

admin's avatar
admin committed
684 685 686 687
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.tableView endEditing:YES];
}

admin's avatar
admin committed
688

admin's avatar
admin committed
689

admin's avatar
admin committed
690 691

@end