NewSurveyViewController.m 19 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11 12
//
//  NewSurveyViewController.m
//  XFFurit
//
//  Created by 陈俊俊 on 15/8/1.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//  新建行情调研



#import "NewSurveyViewController.h"
#import "SurveyCell.h"
n22's avatar
n22 committed
13
#import "SurveyViewController.h"
陈俊俊's avatar
陈俊俊 committed
14 15
#import "HPGrowingTextView.h"
#import "StartTimeView.h"
n22's avatar
n22 committed
16
#import "ChosePersonViewController.h"
n22's avatar
n22 committed
17
#import "ChooseProductViewController.h"
陈俊俊's avatar
陈俊俊 committed
18
#import "SurveyUser.h"
19
#import "Survey.h"
n22's avatar
n22 committed
20
#import "Product.h"
陈俊俊's avatar
陈俊俊 committed
21 22
#define LeftMargin 15
#define BtnHeight 44
陈俊俊's avatar
陈俊俊 committed
23
#define TableRowHeight 46
陈俊俊's avatar
陈俊俊 committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#define CornerRadius 5
#define BtnSize 19
#define TotalHeight 432
#define KeyboardHeight 258
#define DateViewHeight 300
typedef enum : NSUInteger {
    SaveTag = 2000,
    CommitTag,
} BtnTag;

@interface NewSurveyViewController ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate,StartTimeViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
    UITextField *_titleField;
    UILabel *_productLabel;
    UILabel *_startDateLabel;
    UILabel *_endDateLabel;
    UILabel *_personLabel;
    HPGrowingTextView *_noteTextView;
    UIDatePicker *_timePicker;
    BOOL _isClickStart;
    StartTimeView *_startTimeView;
n22's avatar
n22 committed
47 48
    id uuidObject;
    id billNumberObject;
n22's avatar
n22 committed
49 50
    NSNumber *versionObject;
    NSString *_clickState;
陈俊俊's avatar
陈俊俊 committed
51
}
陈俊俊's avatar
陈俊俊 committed
52 53 54 55 56 57 58
@property (nonatomic,strong)NSString *titleStr;
@property (nonatomic,strong)NSString *productCodeStr;
@property (nonatomic,strong)NSString *productNameStr;
@property (nonatomic,strong)NSString *productUuidStr;
@property (nonatomic,strong)NSString *beginDateStr;
@property (nonatomic,strong)NSString *endDateStr;
@property (nonatomic,strong)NSString *remarkStr;
陈俊俊's avatar
陈俊俊 committed
59 60
@property (nonatomic,strong)NSMutableArray *users;

陈俊俊's avatar
陈俊俊 committed
61 62 63 64 65 66
@end

@implementation NewSurveyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
67
    self.title = self.navTitle;
陈俊俊's avatar
陈俊俊 committed
68
    [self initData];
陈俊俊's avatar
陈俊俊 committed
69 70 71 72
    [self createTableView];
    if (self.survey) {
        [self getDataFromServer];
    }
陈俊俊's avatar
陈俊俊 committed
73
}
陈俊俊's avatar
陈俊俊 committed
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
- (void)getDataFromServer{
    __weak typeof(self)weakSelf = self;

    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
                NSDictionary *dictData = data[@"data"];
                Survey *survey = [[Survey alloc]init];
                [survey setValuesForKeysWithDictionary:dictData];
                 strongSelf.survey = survey;

                [strongSelf preferDataInPersonLabel];
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getResultWithSurveyUuid:self.survey.uuid success:succ failure:fail];
}


陈俊俊's avatar
陈俊俊 committed
104
- (void)initData{
n22's avatar
n22 committed
105

陈俊俊's avatar
陈俊俊 committed
106
    _dataArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
107
    self.users = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
108 109 110 111 112 113
    [_dataArr addObject:@"标题"];
    [_dataArr addObject:@"商品"];
    [_dataArr addObject:@"开始日期"];
    [_dataArr addObject:@"结束日期"];
    [_dataArr addObject:@"调研人员"];
    [_dataArr addObject:@"备注"];
n22's avatar
n22 committed
114 115
    uuidObject = [NSNull null];
    billNumberObject  = [NSNull null];
n22's avatar
n22 committed
116
    versionObject = [NSNumber numberWithInt:0];
陈俊俊's avatar
陈俊俊 committed
117 118 119 120
}

- (void)createTableView
{
陈俊俊's avatar
陈俊俊 committed
121 122
    self.view.backgroundColor  = XXFBgColor;

陈俊俊's avatar
陈俊俊 committed
123 124 125 126 127 128 129 130
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, LeftMargin,ScreenSize.width, ScreenSize.height - 64 - LeftMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 50)];
    
陈俊俊's avatar
陈俊俊 committed
131
    UIButton *saveBtn =  [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, 10, (ScreenSize.width - LeftMargin*3)/2, BtnHeight) target:self sel:@selector(btnClick:) tag:SaveTag image:nil title:@"保存" titleColor: [UIColor whiteColor] isCorner:YES corner:CornerRadius bgColor:GXF_SAVE_COLOR];
陈俊俊's avatar
陈俊俊 committed
132 133
    [footView addSubview:saveBtn];
    
陈俊俊's avatar
陈俊俊 committed
134
    UIButton *commitBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(saveBtn.frame.origin.x + saveBtn.frame.size.width + LeftMargin, 10, (ScreenSize.width - LeftMargin*3)/2, BtnHeight) target:self sel:@selector(btnClick:) tag:CommitTag image:nil title:@"提交" titleColor: [UIColor whiteColor] isCorner:YES corner:CornerRadius bgColor:GXF_COMMIT_COLOR];
陈俊俊's avatar
陈俊俊 committed
135 136 137 138 139 140 141 142 143 144 145
    [footView addSubview:commitBtn];
    
    _tableView.tableFooterView = footView;
    [self.view addSubview:_tableView];
}

#pragma mark - 按钮点击事件
- (void)btnClick:(UIButton *)btn{
    switch (btn.tag) {
        case SaveTag:
        {
陈俊俊's avatar
陈俊俊 committed
146
            if ([self checkSurvey]) {
n22's avatar
n22 committed
147
                _clickState = @"initial";
n22's avatar
n22 committed
148
                [self saveSurvey:@"initial" message:@"正在保存..."];
陈俊俊's avatar
陈俊俊 committed
149
            }
陈俊俊's avatar
陈俊俊 committed
150 151 152 153
        }
            break;
        case CommitTag:
        {
n22's avatar
n22 committed
154
            if ([self checkSurvey]) {
n22's avatar
n22 committed
155
                _clickState = @"submitted";
n22's avatar
n22 committed
156 157
                [self saveSurvey:@"submitted" message:@"正在提交..."];
            }
陈俊俊's avatar
陈俊俊 committed
158 159 160 161 162 163
        }
            break;
        default:
            break;
    }
}
陈俊俊's avatar
陈俊俊 committed
164
- (BOOL)checkSurvey{
陈俊俊's avatar
陈俊俊 committed
165 166
    self.titleStr = _titleField.text;
    self.remarkStr = _noteTextView.text;
陈俊俊's avatar
陈俊俊 committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180
    if (self.titleStr.length == 0 ) {
        ShowMessage(@"调研标题不能为空");
        return NO;
    }
    if (self.productUuidStr.length == 0 || self.productNameStr.length == 0|| self.productCodeStr.length == 0 ) {
        ShowMessage(@"调研商品不能为空");
        return NO;
    }
    if (self.beginDateStr.length == 0) {
        ShowMessage(@"调研开始日期不能为空");
        return NO;
    }
    if (self.endDateStr.length == 0) {
        ShowMessage(@"调研结束日期不能为空");
陈俊俊's avatar
陈俊俊 committed
181 182
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
183 184 185 186 187 188 189 190 191
    if (self.users.count <=0) {
        ShowMessage(@"调研人员不能为空");
        return NO;
    }
    if ([IBTCommon compareDate:self.beginDateStr withDate:self.endDateStr] < 0) {
        ShowMessage(@"开始日期不能小于结束日期");
        return NO;
    }
    
陈俊俊's avatar
陈俊俊 committed
192 193
    return YES;
}
陈俊俊's avatar
陈俊俊 committed
194 195


陈俊俊's avatar
陈俊俊 committed
196
#pragma mark - 保存
n22's avatar
n22 committed
197
- (void)saveSurvey:(NSString *)state message:(NSString *)msg
陈俊俊's avatar
陈俊俊 committed
198 199 200 201
{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
n22's avatar
n22 committed
202 203 204 205 206
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                //成功
n22's avatar
n22 committed
207
                if ([state isEqualToString:@"initial"]) {//保存成功
n22's avatar
n22 committed
208 209 210 211 212 213
                    NSString *uuidS = data[@"data"][@"uuid"];
                    NSString *billNumberS = data[@"data"][@"billNumber"];
                    NSNumber *versionN = data[@"data"][@"version"];
                    uuidObject = uuidS;
                    billNumberObject = billNumberS;
                    versionObject = versionN;
陈俊俊's avatar
陈俊俊 committed
214
                    [IBTLoadingView showTips:[NSString stringWithFormat:@"当前单据%@已保存成功",billNumberS]];
n22's avatar
n22 committed
215 216 217
                }else{//提交成功
                    SurveyViewController *svc = [SurveyViewController new];
                    [self PushViewController:svc animated:YES];
陈俊俊's avatar
陈俊俊 committed
218
                }
n22's avatar
n22 committed
219 220 221 222
            }else{
                [IBTLoadingView showTips:message];
            }
        }
陈俊俊's avatar
陈俊俊 committed
223 224 225 226 227
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
n22's avatar
n22 committed
228 229
    
    if(self.survey.uuid.length > 0 && uuidObject == [NSNull null]){
陈俊俊's avatar
陈俊俊 committed
230 231
        uuidObject = self.survey.uuid;
    }
n22's avatar
n22 committed
232
    if (self.survey.billNumber > 0 && billNumberObject == [NSNull null]) {
陈俊俊's avatar
陈俊俊 committed
233 234
        billNumberObject = self.survey.billNumber;
    }
n22's avatar
n22 committed
235 236
    if (self.survey && [versionObject integerValue] == 0) {
        versionObject = self.survey.version;
n22's avatar
n22 committed
237
    }
陈俊俊's avatar
陈俊俊 committed
238
    NSDictionary *dict = @{@"uuid":uuidObject,
n22's avatar
n22 committed
239
                           @"version":versionObject,
陈俊俊's avatar
陈俊俊 committed
240 241
                           @"billnumber":billNumberObject,
                           @"title":[IBTCommon checkString:self.titleStr],
n22's avatar
n22 committed
242
                           @"state":state,
陈俊俊's avatar
陈俊俊 committed
243 244 245 246 247 248
                           @"productUuid":[IBTCommon checkString:self.productUuidStr],
                           @"productCode":[IBTCommon checkString:self.productCodeStr],
                           @"productName":[IBTCommon checkString:self.productNameStr],
                           @"beginDate":[IBTCommon checkString:self.beginDateStr],
                           @"endDate":[IBTCommon checkString:self.endDateStr],
                           @"remark":[IBTCommon checkString:self.remarkStr],
n22's avatar
n22 committed
249
                           @"users":self.users};
250
    [IBTLoadingView showProgressLabel:msg];    
陈俊俊's avatar
陈俊俊 committed
251 252 253
    [[ICRHTTPController sharedController] saveSurveyWithAuthenticode:dict success:succ failure:fail];
}

陈俊俊's avatar
陈俊俊 committed
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
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    SurveyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row >0 && indexPath.row < _dataArr.count - 1) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        [self createViewInCell:cell indexPath:indexPath];
    }
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
}

-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
陈俊俊's avatar
陈俊俊 committed
279
        _titleField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableRowHeight)];
陈俊俊's avatar
陈俊俊 committed
280
        _titleField.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
281
        _titleField.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
282
        _titleField.placeholder = @"输入调研标题";
陈俊俊's avatar
陈俊俊 committed
283
        _titleField.font = GXF_FIFTEENTEN_SIZE;
陈俊俊's avatar
陈俊俊 committed
284
        _titleField.returnKeyType = UIReturnKeyDone;
陈俊俊's avatar
陈俊俊 committed
285 286 287
        _titleField.delegate = self;
        [cell.contentView addSubview:_titleField];
    }else if (indexPath.row == _dataArr.count -1){
陈俊俊's avatar
陈俊俊 committed
288
        _noteTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableRowHeight)];
陈俊俊's avatar
陈俊俊 committed
289 290 291
        _noteTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        _noteTextView.minNumberOfLines = 1;
        _noteTextView.maxNumberOfLines = 4;
陈俊俊's avatar
陈俊俊 committed
292
        _noteTextView.font = GXF_FIFTEENTEN_SIZE;
陈俊俊's avatar
陈俊俊 committed
293 294
        _noteTextView.textAlignment = NSTextAlignmentRight;
        _noteTextView.delegate = self;
陈俊俊's avatar
陈俊俊 committed
295
        _noteTextView.returnKeyType = UIReturnKeyDone;
陈俊俊's avatar
陈俊俊 committed
296 297
        _noteTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:_noteTextView];
陈俊俊's avatar
陈俊俊 committed
298
       
陈俊俊's avatar
陈俊俊 committed
299
        CGRect lineFrame =  cell.lineLabel.frame;
陈俊俊's avatar
陈俊俊 committed
300
        lineFrame.origin.y = TableRowHeight*2-1;
陈俊俊's avatar
陈俊俊 committed
301 302
        cell.lineLabel.frame = lineFrame;
    }else{
陈俊俊's avatar
陈俊俊 committed
303
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableRowHeight))];
陈俊俊's avatar
陈俊俊 committed
304
        contentLabel.textAlignment= NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
305 306
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
        contentLabel.font = GXF_FIFTEENTEN_SIZE;
陈俊俊's avatar
陈俊俊 committed
307 308 309 310 311 312 313 314 315 316 317 318 319
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 1) {
            contentLabel.text = @"选择商品";
            _productLabel = contentLabel;
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择日期";
            _startDateLabel = contentLabel;
        }else if(indexPath.row == 3){
            contentLabel.text = @"选择日期";
            _endDateLabel = contentLabel;
        }else if(indexPath.row == 4){
            contentLabel.text = @"选择调研人员";
            _personLabel = contentLabel;
陈俊俊's avatar
陈俊俊 committed
320 321 322 323
        }
    }
}
- (void)preferDataInPersonLabel{
陈俊俊's avatar
陈俊俊 committed
324 325 326 327 328 329 330 331 332 333 334 335
    if (self.survey) {
        _titleField.text = [IBTCommon checkString:self.survey.title];
        self.titleStr = [IBTCommon checkString:self.survey.title];
    }
    if (self.survey) {
        if (self.survey.endDate.length > 9) {
            _endDateLabel.text = [[IBTCommon checkString:self.survey.endDate]substringToIndex:10];
        }
        _endDateLabel.textColor = GXF_CONTENT_COLOR;
        self.endDateStr = [IBTCommon checkString:self.survey.endDate];
    }

陈俊俊's avatar
陈俊俊 committed
336 337 338
    if (self.survey) {
        if (self.survey.users.count > 0) {
            NSString *personStr = @"";
陈俊俊's avatar
陈俊俊 committed
339 340 341 342
            for (NSDictionary * userDict in self.survey.users) {
                
                SurveyUser *surveyUser = [[SurveyUser alloc]init];
                [surveyUser setValuesForKeysWithDictionary:userDict];
陈俊俊's avatar
陈俊俊 committed
343 344
                if (personStr.length == 0) {
                    personStr = [personStr stringByAppendingFormat:@"%@",surveyUser.userName];
陈俊俊's avatar
陈俊俊 committed
345
                }else{
陈俊俊's avatar
陈俊俊 committed
346 347 348 349
                    personStr = [personStr stringByAppendingFormat:@"、%@",surveyUser.userName];
                }
            }
            _personLabel.text = personStr;
陈俊俊's avatar
陈俊俊 committed
350
            _personLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
351 352 353
        }
        if (self.users > 0) {
            [self.users addObjectsFromArray:self.survey.users];
陈俊俊's avatar
陈俊俊 committed
354 355
        }
    }
陈俊俊's avatar
陈俊俊 committed
356 357 358 359 360 361 362 363
    if (self.survey) {
        if (self.survey.beginDate.length > 9) {
            _startDateLabel.text = [[IBTCommon checkString:self.survey.beginDate]substringToIndex:10];
        }
        _startDateLabel.textColor = GXF_CONTENT_COLOR;
        self.beginDateStr =[IBTCommon checkString:self.survey.beginDate];
        
    }
陈俊俊's avatar
陈俊俊 committed
364
    if (self.survey) {
n22's avatar
n22 committed
365
        _productLabel.text = [NSString stringWithFormat:@"%@[%@]",[IBTCommon checkString:self.survey.productName],[IBTCommon checkString:self.survey.productCode]];
陈俊俊's avatar
陈俊俊 committed
366
        _productLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
367 368 369 370
        self.productCodeStr = [IBTCommon checkString:self.survey.productCode];
        self.productNameStr = [IBTCommon checkString:self.survey.productName];
        self.productUuidStr = [IBTCommon checkString:self.survey.productUuid];
    }
陈俊俊's avatar
陈俊俊 committed
371 372 373 374 375

    if (self.survey) {
        _noteTextView.text =  [IBTCommon checkString:self.survey.remark];
        self.remarkStr = [IBTCommon checkString:self.survey.remark];
    }
陈俊俊's avatar
陈俊俊 committed
376 377
}

陈俊俊's avatar
陈俊俊 committed
378

陈俊俊's avatar
陈俊俊 committed
379 380
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 5){
陈俊俊's avatar
陈俊俊 committed
381
        return TableRowHeight*2;
陈俊俊's avatar
陈俊俊 committed
382
    }else{
陈俊俊's avatar
陈俊俊 committed
383
        return TableRowHeight;
陈俊俊's avatar
陈俊俊 committed
384 385 386 387
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2 || indexPath.row == 3) {
陈俊俊's avatar
陈俊俊 committed
388
        [self keyboardHidden];
陈俊俊's avatar
陈俊俊 committed
389 390 391 392 393 394
        if (indexPath.row == 2) {
            _isClickStart = YES;
        }else{
            _isClickStart = NO;
        }
        [self startDatePickView];
n22's avatar
n22 committed
395 396
    }else if(indexPath.row == 4){
        ChosePersonViewController *cvc = [ChosePersonViewController new];
陈俊俊's avatar
陈俊俊 committed
397
        cvc.chosePerson = ^(NSArray *users){
n22's avatar
n22 committed
398 399 400 401 402 403 404 405 406 407 408 409
            if(users.count > 0){
                NSString *textStr = @"";
                if (self.users.count > 0) {
                    [self.users removeAllObjects];
                }
                for (SurveyUser *user in users) {
                    if (textStr.length == 0) {
                        textStr = [textStr stringByAppendingFormat:@"%@",user.userName];
                    }else {
                        textStr = [textStr stringByAppendingFormat:@"、%@",user.userName];
                    }
                    [self.users addObject:[user dictForCommit]];
陈俊俊's avatar
陈俊俊 committed
410
                }
n22's avatar
n22 committed
411
                _personLabel.text = textStr;
陈俊俊's avatar
陈俊俊 committed
412
                _personLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
413
            }
n22's avatar
n22 committed
414 415 416
        };
        cvc.isMoreChose = YES;
        [self PushViewController:cvc animated:YES];
n22's avatar
n22 committed
417 418
    }else  if(indexPath.row == 1){
        ChooseProductViewController *cvc = [ChooseProductViewController new];
陈俊俊's avatar
陈俊俊 committed
419
    
n22's avatar
n22 committed
420 421
        cvc.choseProduct = ^(Product *product){
            _productLabel.text = [NSString stringWithFormat:@"%@[%@]",product.name,product.code];
陈俊俊's avatar
陈俊俊 committed
422
            _productLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
423 424 425
            self.productNameStr = product.name;
            self.productUuidStr = product.uuid;
            self.productCodeStr = product.code;
n22's avatar
n22 committed
426 427 428
        };
        cvc.isMoreChose = NO;
        [self PushViewController:cvc animated:YES];
陈俊俊's avatar
陈俊俊 committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
    }
}

- (void)startDatePickView{
    if (!_startTimeView) {
        _startTimeView = [[StartTimeView alloc] initWithFrame:CGRectMake(0, ScreenSize.height, ScreenSize.width, ScreenSize.height - 64)];
        _startTimeView.delegate = self;
        _startTimeView.backgroundColor        = RGBA(0, 0, 0 ,0.5);
        [self.view addSubview:_startTimeView];
        
        [UIView animateWithDuration:0.15 animations:^{
            CGRect startFrame =  _startTimeView.frame;
            startFrame.origin.y =  0;
            _startTimeView.frame = startFrame;
        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)cancelTimeView{
    [self clearDatePickView];
}
- (void)okTimeView:(NSDate *)time{
    if (_isClickStart) {
陈俊俊's avatar
陈俊俊 committed
454
        _startDateLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
455 456
        _startDateLabel.text = [IBTCommon stringFromDate:time];
        self.beginDateStr = [time httpParameterString];
陈俊俊's avatar
陈俊俊 committed
457
    }else{
陈俊俊's avatar
陈俊俊 committed
458
        _endDateLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
459 460
        _endDateLabel.text = [IBTCommon stringFromDate:time];
        self.endDateStr = [time httpParameterString];
陈俊俊's avatar
陈俊俊 committed
461 462 463 464 465 466 467 468 469 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 499 500 501
    }
    // 关闭选择器
    [self clearDatePickView];
}
#pragma mark - 取消
- (void)clearDatePickView{
    [UIView animateWithDuration:0.15 animations:^{
        CGRect startFrame =  _startTimeView.frame;
        startFrame.origin.y = ScreenSize.height;
        _startTimeView.frame = startFrame;
    } completion:^(BOOL finished) {
        [_startTimeView removeFromSuperview];
        _startTimeView = nil;
    }];
}
#pragma mark delegate
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [_noteTextView resignFirstResponder];
    [self setTableFrame:LeftMargin];
    return YES;
}
- (void)growingTextViewDidBeginEditing:(HPGrowingTextView *)growingTextView{
    CGFloat offset = ScreenSize.height - TotalHeight - KeyboardHeight;
    if (offset < 0) {//上移
        [self setTableFrame:LeftMargin+offset];
    }
}
- (void)setTableFrame:(CGFloat)tabelH{
    [UIView animateWithDuration:0.25 animations:^{
        CGRect tableFrame = _tableView.frame;
        tableFrame.origin.y = tabelH;
        _tableView.frame = tableFrame;
    }];
}

- (void)keyboardHidden{
    [_titleField resignFirstResponder];
    [_noteTextView resignFirstResponder];
    [self setTableFrame:LeftMargin];
}

n22's avatar
n22 committed
502 503
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
n22's avatar
n22 committed
504 505 506
    if(self.survey && [_clickState isEqualToString:@"initial"]){
        [ICRUserUtil sharedInstance].needFresh = YES;
    }
n22's avatar
n22 committed
507 508
}

陈俊俊's avatar
陈俊俊 committed
509 510 511 512 513
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end