NewPurchaseNoticeViewController.m 27.8 KB
Newer Older
朱朝吉's avatar
朱朝吉 committed
1 2 3 4 5 6 7 8 9
//
//  NewPurchaseNoticeViewController.m
//  XFFruit
//
//  Created by mac on 15/8/16.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "NewPurchaseNoticeViewController.h"
zhu's avatar
zhu committed
10
#import "PurchaseNoticeViewController.h"
朱朝吉's avatar
朱朝吉 committed
11 12
#import "SurveyCell.h"
#import "HPGrowingTextView.h"
zhu's avatar
zhu committed
13
#import "SeePurchaseNoticeViewController.h"
朱朝吉's avatar
朱朝吉 committed
14 15 16
#import "ChosePersonViewController.h"
#import "SurveyUser.h"
#import "PurchaseNoticeCell.h"
陈俊俊's avatar
陈俊俊 committed
17 18
#import "NoticeProductViewController.h"
#import "NoticeProduct.h"
陈俊俊's avatar
陈俊俊 committed
19
#import "FinishTimeView.h"
zhu's avatar
zhu committed
20
#import "PurchaseBillProduct.h"
朱朝吉's avatar
朱朝吉 committed
21
#define LeftMargin 15
zhu's avatar
zhu committed
22 23 24
#define LeftWidth 40
#define RightWidth 30
#define SpaceMargin 1
朱朝吉's avatar
朱朝吉 committed
25 26 27 28 29 30 31 32
#define BtnHeight 44
#define TableHeight 46
#define CornerRadius 5
#define TitleSize 15
#define BtnSize 19
#define TotalHeight 432
#define KeyboardHeight 258
#define DateViewHeight 300
zhu's avatar
zhu committed
33
#define FootOfsetHeight 140
zhu's avatar
zhu committed
34 35
#define BottomViewHeight 60

zhu's avatar
zhu committed
36

zhu's avatar
zhu committed
37 38 39 40
typedef enum : NSUInteger {
    SaveTag = 8000,
    CommitTag,
} BtnTag;
陈俊俊's avatar
陈俊俊 committed
41
@interface NewPurchaseNoticeViewController()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,HPGrowingTextViewDelegate,UIAlertViewDelegate,FinishTimeViewDelegate>
朱朝吉's avatar
朱朝吉 committed
42
{
陈俊俊's avatar
陈俊俊 committed
43
    NSString *_clickState;
朱朝吉's avatar
朱朝吉 committed
44 45
    UITableView *_tableView;
    NSMutableArray *_dataArr;
zhu's avatar
zhu committed
46
    NSMutableArray *_shopeArr;
朱朝吉's avatar
朱朝吉 committed
47 48
    UITextField *_titleField;
    UILabel *_personLabel;
陈俊俊's avatar
陈俊俊 committed
49
    UILabel *_finishDateLabel;
朱朝吉's avatar
朱朝吉 committed
50
    HPGrowingTextView *_noteTextView;
zhu's avatar
zhu committed
51
    NSIndexPath *selectedCellIndexPath;
zhu's avatar
zhu committed
52
    NSMutableArray *selectCellAry;
朱朝吉's avatar
朱朝吉 committed
53
    UITableView *mingXiTableView;
zhu's avatar
zhu committed
54 55 56 57
    id uuidObject;
    id billNumberObject;
    NSNumber *versionObject;
    NSString *title;
陈俊俊's avatar
陈俊俊 committed
58
    FinishTimeView *_startTimeView;
zhu's avatar
zhu committed
59
    
朱朝吉's avatar
朱朝吉 committed
60 61
}
@property (nonatomic,strong)NSString *titleStr;
陈俊俊's avatar
陈俊俊 committed
62 63 64
@property (nonatomic,strong)NSString *purchaseCodeStr;
@property (nonatomic,strong)NSString *purchaseNameStr;
@property (nonatomic,strong)NSString *purchaseUuidStr;
朱朝吉's avatar
朱朝吉 committed
65
@property (nonatomic,strong)NSString *remarkStr;
陈俊俊's avatar
陈俊俊 committed
66
@property (nonatomic,strong)NSString *finishDateStr;
zhu's avatar
zhu committed
67

zhu's avatar
zhu committed
68 69 70
@property (nonatomic,strong)UILabel *HeardLabel;
@property (nonatomic,strong)UILabel *FootLabel;
@property (nonatomic,strong)UIButton *addDetailedButton;
陈俊俊's avatar
陈俊俊 committed
71
@property (nonatomic,strong)NSMutableArray *selectUsers;
陈俊俊's avatar
陈俊俊 committed
72
@property (nonatomic,strong)NSMutableArray *users;
zhu's avatar
zhu committed
73

陈俊俊's avatar
陈俊俊 committed
74
@property (nonatomic,strong)NSString *purchaseNoticeUuid;
朱朝吉's avatar
朱朝吉 committed
75

朱朝吉's avatar
朱朝吉 committed
76 77 78 79 80 81 82

@end

@implementation NewPurchaseNoticeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
83
    [self setupSubviews];
zhu's avatar
zhu committed
84 85 86 87
    //数据默认值
    uuidObject = [NSNull null];
    billNumberObject = [NSNull null];
    versionObject = [NSNumber numberWithInteger:0];
陈俊俊's avatar
陈俊俊 committed
88
    if (self.purchaseNotice) {
陈俊俊's avatar
陈俊俊 committed
89
        self.purchaseNoticeUuid = self.purchaseNotice.uuid;
陈俊俊's avatar
陈俊俊 committed
90 91
        [self getDataFromServer];
    }
朱朝吉's avatar
朱朝吉 committed
92
}
陈俊俊's avatar
陈俊俊 committed
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
- (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"];
                PurchaseNotice *purchaseNotice = [[PurchaseNotice alloc]init];
                [purchaseNotice setValuesForKeysWithDictionary:dictData];
                 strongSelf.purchaseNotice = purchaseNotice;
                [strongSelf prepareDataInCell];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
陈俊俊's avatar
陈俊俊 committed
119
    [[ICRHTTPController sharedController] getPurchaseNoticeDetailedWithPurchaseUuid:self.purchaseNoticeUuid success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
120 121 122 123 124 125 126
}
- (void)prepareDataInCell{
    if (self.purchaseNotice) {
        if (self.purchaseNotice.title.length > 0) {
            _titleField.text = self.purchaseNotice.title;
            self.titleStr = self.purchaseNotice.title;
        }
陈俊俊's avatar
陈俊俊 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        
        if (self.purchaseNotice.purchasers.count > 0) {
            NSString *personStr = @"";
            for (NSDictionary * userDict in self.purchaseNotice.purchasers) {
                
                SurveyUser *surveyUser = [[SurveyUser alloc]init];
                [surveyUser setValuesForKeysWithDictionary:userDict];
                [self.selectUsers addObject:surveyUser.userUuid];
                if (personStr.length == 0) {
                    personStr = [personStr stringByAppendingFormat:@"%@",surveyUser.userName];
                }else{
                    personStr = [personStr stringByAppendingFormat:@"、%@",surveyUser.userName];
                }
            }
            _personLabel.text = personStr;
陈俊俊's avatar
陈俊俊 committed
142
            _personLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
143 144 145 146 147 148
        }
        if (self.users) {
            if (self.users.count > 0) {
                [self.users removeAllObjects];
            }
            [self.users addObjectsFromArray:self.purchaseNotice.purchasers];
陈俊俊's avatar
陈俊俊 committed
149
        }
陈俊俊's avatar
陈俊俊 committed
150
        if (self.purchaseNotice.finishDate) {
陈俊俊's avatar
陈俊俊 committed
151 152
            if (self.purchaseNotice.finishDate.length > 15) {
                _finishDateLabel.text = [[IBTCommon checkString:self.purchaseNotice.finishDate]substringToIndex:16];
陈俊俊's avatar
陈俊俊 committed
153 154 155 156
            }
            _finishDateLabel.textColor = GXF_CONTENT_COLOR;
            self.finishDateStr = [IBTCommon checkString:self.purchaseNotice.finishDate];
        }
陈俊俊's avatar
陈俊俊 committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        if (self.purchaseNotice.remark) {
            _noteTextView.text = self.purchaseNotice.remark;
            self.remarkStr = self.purchaseNotice.remark;
        }
    }
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *productDict in self.purchaseNotice.products) {
        NoticeProduct *billProduct = [[NoticeProduct alloc]init];
        [billProduct setValuesForKeysWithDictionary:productDict];
        [arr addObject:billProduct];
    }
    _shopeArr = arr;
    [mingXiTableView reloadData];
}



朱朝吉's avatar
朱朝吉 committed
174 175
-(void)setupSubviews
{
zhu's avatar
zhu committed
176
    selectCellAry=[[NSMutableArray alloc]initWithCapacity:1000];
陈俊俊's avatar
陈俊俊 committed
177
    self.selectUsers = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
178
    self.users = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
179

陈俊俊's avatar
陈俊俊 committed
180 181
    _dataArr=[[NSMutableArray alloc]initWithObjects:@"标题:",@"采购员:",@"要求采购完成时间:",@"备注:", nil];
    _shopeArr=[[NSMutableArray alloc]init];
朱朝吉's avatar
朱朝吉 committed
182 183
    self.view.backgroundColor  = XXFBgColor;
    
陈俊俊's avatar
陈俊俊 committed
184
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, LeftMargin,ScreenSize.width, ScreenSize.height/3)) style:(UITableViewStylePlain)];
朱朝吉's avatar
朱朝吉 committed
185 186 187 188
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.tag=1001;
    _tableView.delegate = self;
    _tableView.dataSource = self;
zhu's avatar
zhu committed
189
    
陈俊俊's avatar
陈俊俊 committed
190
    mingXiTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 2*LeftMargin+_tableView.frame.size.height, ScreenSize.width, ScreenSize.height-_tableView.height-ScreenSize.height/6 - 50)];
zhu's avatar
zhu committed
191
    mingXiTableView.backgroundColor = [UIColor whiteColor];
朱朝吉's avatar
朱朝吉 committed
192 193 194 195
    mingXiTableView.tag=1002;
    mingXiTableView.delegate=self;
    mingXiTableView.dataSource=self;
    
zhu's avatar
zhu committed
196 197
    UIView *footView2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    footView2.backgroundColor=[UIColor clearColor];
zhu's avatar
zhu committed
198
    NSArray *ary=[NSArray arrayWithObjects:@"商品",@"包装规格",@"包装数量", nil];
zhu's avatar
zhu committed
199
    //    NSArray *ary=[NSArray arrayWithObjects: nil];
zhu's avatar
zhu committed
200
    CGFloat gipWidth = (ScreenSize.width-LeftWidth-RightWidth)/3;
zhu's avatar
zhu committed
201 202 203 204
    
    for (int i=0; i< ary.count;i++ ) {
        UILabel *lable=[[UILabel alloc]init];
        if (i==0) {
zhu's avatar
zhu committed
205
            lable.frame=CGRectMake(LeftWidth, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
206 207
        }
        if (i==1) {
zhu's avatar
zhu committed
208
            lable.frame=CGRectMake(LeftWidth+gipWidth+1, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
209 210
        }
        if (i==2) {
zhu's avatar
zhu committed
211
            lable.frame=CGRectMake(LeftWidth+2*gipWidth+2, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
212
        }
zhu's avatar
zhu committed
213
        
zhu's avatar
zhu committed
214
        //        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(LeftWidth + (SpaceMargin + headWidth)*i,0, headWidth, 50)];
zhu's avatar
zhu committed
215
        lable.text=[ary objectAtIndex:i];
陈俊俊's avatar
陈俊俊 committed
216 217
        lable.textColor=GXF_PLACEHOLDER_COLOR;
        lable.font = GXF_FIFTEENTEN_SIZE;
zhu's avatar
zhu committed
218 219
        [footView2 addSubview:lable];
    }
zhu's avatar
zhu committed
220
    
陈俊俊's avatar
陈俊俊 committed
221 222 223 224 225 226 227 228
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addBtn.frame = CGRectMake(ScreenSize.width - LeftWidth - SpaceMargin, 0, LeftWidth, 40);
    [addBtn setImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
    [addBtn setTitleColor:GXF_PLACEHOLDER_COLOR forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addShopeDetailed) forControlEvents:UIControlEventTouchUpInside];
    addBtn.titleLabel.font = GXF_FIFTEENTEN_SIZE;
    [footView2 addSubview:addBtn];
    
zhu's avatar
zhu committed
229 230 231
    UIView *footView3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    footView3.backgroundColor=[UIColor clearColor];
    self.addDetailedButton=[UIButton  buttonWithType: UIButtonTypeCustom];
zhu's avatar
zhu committed
232
    [self.addDetailedButton  setFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
zhu's avatar
zhu committed
233
    [self.addDetailedButton setTitle:@"+ 点击添加商品明细" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
234
    self.addDetailedButton.titleLabel.font = GXF_FIFTEENTEN_SIZE;
zhu's avatar
zhu committed
235
    [self.addDetailedButton addTarget:self action:@selector(addShopeDetailed) forControlEvents:UIControlEventTouchUpInside];
陈俊俊's avatar
陈俊俊 committed
236
    [self.addDetailedButton setTitleColor:GXF_PLACEHOLDER_COLOR forState:UIControlStateNormal];
zhu's avatar
zhu committed
237 238 239 240 241 242 243
    self.FootLabel=[[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, footView3.size.height-1, footView3.size.width-2*LeftMargin, 1))];
    self.FootLabel.backgroundColor = HexColor(@"e5e5e5");
    self.FootLabel.font = FontSize(TitleSize);
    self.HeardLabel=[[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, 0, footView3.size.width-2*LeftMargin, 1))];
    self.HeardLabel.backgroundColor = HexColor(@"e5e5e5");
    self.HeardLabel.font = FontSize(TitleSize);
    //HexColor(@"e5e5e5")
zhu's avatar
zhu committed
244
    
zhu's avatar
zhu committed
245 246 247 248 249 250 251 252 253
    
    UIView *footView4 = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenSize.height - BottomViewHeight - 64, ScreenSize.width, BottomViewHeight)];
    UIButton *saveBtn =  [IBTCustomButtom creatButtonWithFrame:CGRectMake(15, 8, (ScreenSize.width - 15*3)/2, 44) target:self sel:@selector(btnClick:) tag:SaveTag image:nil title:@"保存" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:HexColor(@"50bd62")];
    [footView4 addSubview:saveBtn];
    
    UIButton *commitBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetMaxX(saveBtn.frame) + 15, 8, (ScreenSize.width - 15*3)/2, 44) target:self sel:@selector(btnClick:) tag:CommitTag image:nil title:@"提交" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:HexColor(@"f69100")];
    [footView4 addSubview:commitBtn];
    
    [self.view addSubview:footView4];
zhu's avatar
zhu committed
254 255 256 257 258 259 260
    [footView3 addSubview:self.addDetailedButton];
    [footView3 addSubview:self.HeardLabel];
    [footView3 addSubview:self.FootLabel];
    
    mingXiTableView.tableFooterView = footView3;
    mingXiTableView.tableHeaderView=footView2;
    [self.view addSubview:_tableView];
朱朝吉's avatar
朱朝吉 committed
261
    [self.view addSubview:mingXiTableView];
zhu's avatar
zhu committed
262
    [self.view addSubview:footView4];
zhu's avatar
zhu committed
263
    
朱朝吉's avatar
朱朝吉 committed
264 265 266 267 268 269 270 271
}

#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([tableView isEqual:_tableView]) {
        return 1;
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
272
        return 1;
朱朝吉's avatar
朱朝吉 committed
273 274 275 276 277 278
    }
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:_tableView]) {
zhu's avatar
zhu committed
279
        return _dataArr.count;
朱朝吉's avatar
朱朝吉 committed
280 281
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
282
        return _shopeArr.count;
朱朝吉's avatar
朱朝吉 committed
283 284 285 286 287
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([tableView isEqual:_tableView]) {
zhu's avatar
zhu committed
288
        
陈俊俊's avatar
陈俊俊 committed
289
        static NSString *cellID = @"SurveyCell";
zhu's avatar
zhu committed
290 291 292 293 294 295 296 297 298
        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;
            }
陈俊俊's avatar
陈俊俊 committed
299
            cell.titleLabel.width = 130;
zhu's avatar
zhu committed
300
            [self createViewInCell:cell indexPath:indexPath];
朱朝吉's avatar
朱朝吉 committed
301
        }
zhu's avatar
zhu committed
302 303
        [cell setTitleStr:_dataArr[indexPath.row]];
        return cell;
朱朝吉's avatar
朱朝吉 committed
304 305 306
    }else if ([tableView isEqual:mingXiTableView])
    {
        
陈俊俊's avatar
陈俊俊 committed
307
        static NSString *CellID = @"PurchaseNoticeCell";
朱朝吉's avatar
朱朝吉 committed
308 309 310 311 312
        PurchaseNoticeCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (Cell == nil) {
            Cell = [[PurchaseNoticeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            Cell.selectionStyle = UITableViewCellSelectionStyleNone;
zhu's avatar
zhu committed
313
        }
zhu's avatar
zhu committed
314
        [self  showShopDetail:Cell indexPath:indexPath];
陈俊俊's avatar
陈俊俊 committed
315
        if ([self comperIndexpath:indexPath]) {
zhu's avatar
zhu committed
316 317 318 319 320 321 322 323 324 325 326 327
            Cell.arrowView.image = [UIImage imageNamed:@"arrowdown"];
            Cell.backgroundColor=XXFBgColor;
            Cell.subSview.hidden=NO;
        }else
        {
            Cell.arrowView.image = [UIImage imageNamed:@"arrowright"];
            Cell.backgroundColor=[UIColor whiteColor];
            Cell.subSview.hidden=YES;
            
        }
        Cell.button.tag=indexPath.row;
        [Cell.button addTarget:self action:@selector(didtoucher:) forControlEvents:UIControlEventTouchUpInside];
朱朝吉's avatar
朱朝吉 committed
328
        return Cell;
zhu's avatar
zhu committed
329
        
朱朝吉's avatar
朱朝吉 committed
330 331 332 333 334
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_tableView]) {
陈俊俊's avatar
陈俊俊 committed
335
        return TableHeight;
朱朝吉's avatar
朱朝吉 committed
336 337
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
338 339 340 341 342 343 344
        if ([self  comperIndexpath:indexPath]) {
            return TableHeight*3;
        }else
        {
            return TableHeight;
        }
        
朱朝吉's avatar
朱朝吉 committed
345 346 347 348 349 350
    }
    return TableHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_tableView]) {
        
陈俊俊's avatar
陈俊俊 committed
351
        if(indexPath.row == 1){
zhu's avatar
zhu committed
352
            ChosePersonViewController *cvc = [ChosePersonViewController new];
陈俊俊's avatar
陈俊俊 committed
353 354 355
            if (self.selectUsers.count > 0) {
                cvc.selectArr = self.selectUsers;
            }
zhu's avatar
zhu committed
356
            cvc.choseBaseInfo = ^(NSArray *users){
陈俊俊's avatar
陈俊俊 committed
357 358 359 360 361
                if(users.count > 0){
                    NSString *textStr = @"";
                    if (self.users.count > 0) {
                        [self.users removeAllObjects];
                    }
陈俊俊's avatar
陈俊俊 committed
362 363 364
                    if (self.selectUsers.count > 0) {
                        [self.selectUsers removeAllObjects];
                    }
陈俊俊's avatar
陈俊俊 committed
365 366 367 368 369 370 371 372 373 374
                    for (SurveyUser *user in users) {
                        if (textStr.length == 0) {
                            textStr = [textStr stringByAppendingFormat:@"%@",user.userName];
                        }else {
                            textStr = [textStr stringByAppendingFormat:@"、%@",user.userName];
                        }
                        [self.selectUsers addObject:user.userUuid];
                        [self.users addObject:[user dictForCommit]];
                    }
                    _personLabel.text = textStr;
陈俊俊's avatar
陈俊俊 committed
375
                    _personLabel.textColor = GXF_CONTENT_COLOR;
zhu's avatar
zhu committed
376 377
                }
            };
陈俊俊's avatar
陈俊俊 committed
378
            cvc.isMoreChose = YES;
zhu's avatar
zhu committed
379
            [self PushViewController:cvc animated:YES];
陈俊俊's avatar
陈俊俊 committed
380 381
        }else if(indexPath.row == 2){
            [self startDatePickView];
zhu's avatar
zhu committed
382
        }
zhu's avatar
zhu committed
383 384 385
    }else if ([tableView isEqual:mingXiTableView])
    {
        PurchaseNoticeCell *Cell=(PurchaseNoticeCell*)[mingXiTableView cellForRowAtIndexPath:indexPath ];
陈俊俊's avatar
陈俊俊 committed
386
        if (![self comperIndexpath:indexPath]) {
zhu's avatar
zhu committed
387
            Cell.isSelected=YES;
陈俊俊's avatar
陈俊俊 committed
388
            Cell.subSview.hidden = NO;
zhu's avatar
zhu committed
389 390 391
            [selectCellAry addObject:indexPath];
        }else{
            Cell.isSelected=NO;
陈俊俊's avatar
陈俊俊 committed
392
            Cell.subSview.hidden = YES;
zhu's avatar
zhu committed
393 394
            [selectCellAry removeObject:indexPath];
        }
zhu's avatar
zhu committed
395
        selectedCellIndexPath = indexPath;
zhu's avatar
zhu committed
396
        [mingXiTableView reloadData];
朱朝吉's avatar
朱朝吉 committed
397 398 399 400 401 402
    }
}


-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
陈俊俊's avatar
陈俊俊 committed
403
        _titleField = [[UITextField alloc] initWithFrame:CGRectMake(cell.titleLabel.right, 0, ScreenSize.width - cell.titleLabel.width - LeftMargin*2-15, TableHeight)];
朱朝吉's avatar
朱朝吉 committed
404
        _titleField.textAlignment = NSTextAlignmentRight;
zhu's avatar
zhu committed
405
        _titleField.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
406
        _titleField.placeholder = @"输入采购通知单标题";
朱朝吉's avatar
朱朝吉 committed
407 408 409
        _titleField.font = FontSize(15);
        _titleField.returnKeyType = UIReturnKeyDone;
        _titleField.delegate = self;
zhu's avatar
zhu committed
410
        title=_titleField.text;
朱朝吉's avatar
朱朝吉 committed
411
        [cell.contentView addSubview:_titleField];
zhu's avatar
zhu committed
412
        
朱朝吉's avatar
朱朝吉 committed
413
    }else if (indexPath.row == _dataArr.count -1){
陈俊俊's avatar
陈俊俊 committed
414
        _noteTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(cell.titleLabel.right, 0, ScreenSize.width - cell.titleLabel.width - LeftMargin*2-15, TableHeight)];
朱朝吉's avatar
朱朝吉 committed
415 416
        _noteTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        _noteTextView.minNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
417 418
        _noteTextView.maxNumberOfLines = 1;
        _noteTextView.isScrollable = YES;
朱朝吉's avatar
朱朝吉 committed
419 420 421 422 423 424
        _noteTextView.font = FontSize(15);
        _noteTextView.textAlignment = NSTextAlignmentRight;
        _noteTextView.delegate = self;
        _noteTextView.returnKeyType = UIReturnKeyDone;
        _noteTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:_noteTextView];
陈俊俊's avatar
陈俊俊 committed
425 426 427
//        CGRect lineFrame =  cell.lineLabel.frame;
//        lineFrame.origin.y = TableHeight*2-1;
//        cell.lineLabel.frame = lineFrame;
朱朝吉's avatar
朱朝吉 committed
428
    }else{
陈俊俊's avatar
陈俊俊 committed
429
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(cell.titleLabel.right, 0, ScreenSize.width - cell.titleLabel.width - LeftMargin*2-15, TableHeight))];
朱朝吉's avatar
朱朝吉 committed
430
        contentLabel.textAlignment= NSTextAlignmentRight;
zhu's avatar
zhu committed
431
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
朱朝吉's avatar
朱朝吉 committed
432 433 434 435 436
        contentLabel.font = FontSize(TitleSize);
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 1) {
            contentLabel.text = @"选择采购员";
            _personLabel = contentLabel;
陈俊俊's avatar
陈俊俊 committed
437 438 439
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择要求完成日期";
            _finishDateLabel = contentLabel;
朱朝吉's avatar
朱朝吉 committed
440 441
        }
    }
zhu's avatar
zhu committed
442
}
zhu's avatar
zhu committed
443 444 445 446 447 448 449 450 451
-(BOOL)comperIndexpath:(NSIndexPath *)indexPath
{
    for (NSIndexPath *path in selectCellAry) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
陈俊俊's avatar
陈俊俊 committed
452

zhu's avatar
zhu committed
453 454 455
//添加商品明细
-(void)addShopeDetailed
{
陈俊俊's avatar
陈俊俊 committed
456
    NoticeProductViewController *nvc = [NoticeProductViewController new];
陈俊俊's avatar
陈俊俊 committed
457
    nvc.navTitle = @"添加商品明细";
陈俊俊's avatar
陈俊俊 committed
458 459 460 461 462
    nvc.choseNoticeProduct = ^(NoticeProduct *product,NSIndexPath *indexPath){
        if (product) {
            [_shopeArr addObject:product];
            [mingXiTableView reloadData];
        }
zhu's avatar
zhu committed
463
    };
zhu's avatar
zhu committed
464
    
陈俊俊's avatar
陈俊俊 committed
465
    [self PushViewController:nvc animated:YES];
zhu's avatar
zhu committed
466 467 468
}
-(void)showShopDetail:(PurchaseNoticeCell*)Cell indexPath:(NSIndexPath *)indexPath
{
陈俊俊's avatar
陈俊俊 committed
469 470
    NoticeProduct *noticeProduct=[_shopeArr objectAtIndex:indexPath.row];
    Cell.SpLabel.text=noticeProduct.productName;//商品
zhu's avatar
zhu committed
471
    Cell.shopeName.text=[NSString stringWithFormat:@"%@[%@]",noticeProduct.productName,noticeProduct.productCode];
陈俊俊's avatar
陈俊俊 committed
472
    Cell.BzggLabel.text= [NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
zhu's avatar
zhu committed
473
    Cell.packageUnit.text=noticeProduct.packUnit;//包装单位
陈俊俊's avatar
陈俊俊 committed
474 475
    Cell.BzslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
    Cell.packageQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];
陈俊俊's avatar
陈俊俊 committed
476 477
    Cell.packageSpecification.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
    Cell.foundationQuantity.text= [NSString stringWithFormat:@"%@%@",noticeProduct.quantity,noticeProduct.baseUnit];//基础数量
陈俊俊's avatar
陈俊俊 committed
478
    Cell.remark.text=noticeProduct.remark;//备注
zhu's avatar
zhu committed
479
    
zhu's avatar
zhu committed
480 481
}
//编辑
zhu's avatar
zhu committed
482
- (void)didtoucher:(UIButton*)button
zhu's avatar
zhu committed
483
{
陈俊俊's avatar
陈俊俊 committed
484
    NoticeProductViewController *nvc = [NoticeProductViewController new];
陈俊俊's avatar
陈俊俊 committed
485
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
陈俊俊's avatar
陈俊俊 committed
486 487 488
    NoticeProduct *shopDetail=[_shopeArr objectAtIndex:button.tag];

    if (indexPath) {
陈俊俊's avatar
陈俊俊 committed
489
        nvc.navTitle = @"编辑商品明细";
陈俊俊's avatar
陈俊俊 committed
490 491 492 493 494 495 496 497
        nvc.indexPath = indexPath;
        nvc.noticeProduct = shopDetail;
    }
    nvc.choseNoticeProduct = ^(NoticeProduct *fee,NSIndexPath *indexPath){
        if (fee) {
            [_shopeArr replaceObjectAtIndex:indexPath.row withObject:fee];
            [mingXiTableView reloadData];

zhu's avatar
zhu committed
498 499
        }
    };
陈俊俊's avatar
陈俊俊 committed
500 501 502 503 504 505 506 507 508
    nvc.deleteNoticeProduct = ^(NoticeProduct *fee,NSIndexPath *indexPath){
        if (fee) {
            [_shopeArr removeObjectAtIndex:indexPath.row];
            [mingXiTableView reloadData];

        }
    };

    [self PushViewController:nvc animated:YES];
zhu's avatar
zhu committed
509
}
朱朝吉's avatar
朱朝吉 committed
510 511 512 513 514 515 516 517 518
#pragma mark delegate
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [_noteTextView resignFirstResponder];
    return YES;
}
- (void)keyboardHidden{
    [_titleField resignFirstResponder];
    [_noteTextView resignFirstResponder];
}
zhu's avatar
zhu committed
519 520 521 522
- (void)btnClick:(UIButton *)btn{
    switch (btn.tag) {
        case SaveTag:
        {
陈俊俊's avatar
陈俊俊 committed
523
            if ([self checkSurvey]) {
陈俊俊's avatar
陈俊俊 committed
524
                _clickState = PURCHASENOTICE_STATE_INITIAL;
陈俊俊's avatar
陈俊俊 committed
525
                [self saveSurvey:PURCHASENOTICE_STATE_INITIAL message:@"正在保存..."];
陈俊俊's avatar
陈俊俊 committed
526
            }
zhu's avatar
zhu committed
527 528 529 530
        }
            break;
        case CommitTag:
        {
陈俊俊's avatar
陈俊俊 committed
531
            if ([self checkSurvey]) {
陈俊俊's avatar
陈俊俊 committed
532 533 534
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认提交" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
                alertView.delegate = self;
                [alertView show];
陈俊俊's avatar
陈俊俊 committed
535
            }
zhu's avatar
zhu committed
536 537 538 539 540 541
        }
            break;
        default:
            break;
    }
}
zhu's avatar
zhu committed
542 543 544 545 546 547 548
- (BOOL)checkSurvey{
    self.titleStr = _titleField.text;
    self.remarkStr = _noteTextView.text;
    if ( self.titleStr.length==0) {
        ShowMessage(@"采购通知单标题不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
549
    if (self.users.count <=0) {
zhu's avatar
zhu committed
550 551 552 553 554 555 556
        ShowMessage(@"采购员不能为空");
        return NO;
    }
    if (_shopeArr.count==0) {
        ShowMessage(@"商品明细不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
557 558 559 560 561 562
    for (NoticeProduct *billProduct in _shopeArr) {
        if ([billProduct.quantity integerValue] <= 0 || [billProduct.qpcQuantity integerValue] <= 0) {
            ShowMessage(@"有数量等于0的商品明细,请编辑后保存");
            return NO;
        }
    }
zhu's avatar
zhu committed
563 564
    return YES;
}
陈俊俊's avatar
陈俊俊 committed
565 566
- (void)startDatePickView{
    if (!_startTimeView) {
陈俊俊's avatar
陈俊俊 committed
567 568
        NSString *currentStr  = @"";
        if ([_finishDateLabel.text isEqualToString:@"选择要求完成日期"] || _finishDateLabel.text.length < 1) {
陈俊俊's avatar
陈俊俊 committed
569
            currentStr = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd HH:mm:ss"];
陈俊俊's avatar
陈俊俊 committed
570 571 572 573 574
        }else{
            currentStr = _finishDateLabel.text;
        }
        
        _startTimeView = [[FinishTimeView alloc] initWithFrame:CGRectMake(0, ScreenSize.height, ScreenSize.width, ScreenSize.height - 64) withDate:currentStr];
陈俊俊's avatar
陈俊俊 committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
        _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];
}
陈俊俊's avatar
陈俊俊 committed
591
- (void)okTimeView:(NSString *)time{
陈俊俊's avatar
陈俊俊 committed
592 593
    
    _finishDateLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
594 595 596
    if (time.length > 15) {
        _finishDateLabel.text = [time substringToIndex:16];
    }
陈俊俊's avatar
陈俊俊 committed
597
    self.finishDateStr = time;
陈俊俊's avatar
陈俊俊 committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
    // 关闭选择器
    [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;
    }];
}


zhu's avatar
zhu committed
614 615 616 617 618 619 620 621 622 623 624
- (void)saveSurvey:(NSString *)state message:(NSString *)msg
{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                //成功
                if ([state isEqualToString:@"initial"]) {//保存成功
陈俊俊's avatar
陈俊俊 committed
625 626 627 628 629 630 631
                    NSString *uuidS = data[@"data"][@"uuid"];
                    NSString *billNumberS = data[@"data"][@"billNumber"];
                    NSNumber *versionN = data[@"data"][@"version"];
                    uuidObject = uuidS;
                    billNumberObject = billNumberS;
                    versionObject = versionN;
                    [IBTLoadingView showTips:[NSString stringWithFormat:@"当前单据%@已保存成功",billNumberS]];
陈俊俊's avatar
陈俊俊 committed
632 633 634 635
                    //成功之后在次请求详情数据
                    self.purchaseNoticeUuid = uuidS;
                    [self getDataFromServer];
                    
zhu's avatar
zhu committed
636 637
                }else{//提交成功
                    PurchaseNoticeViewController *svc = [PurchaseNoticeViewController new];
陈俊俊's avatar
陈俊俊 committed
638
                    svc.title = @"查看采购通知单";
zhu's avatar
zhu committed
639 640 641 642 643 644 645 646 647 648 649 650
                    [self PushViewController:svc animated:YES];
                }
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    
陈俊俊's avatar
陈俊俊 committed
651 652 653 654 655 656 657 658 659
    if(self.purchaseNotice.uuid.length > 0 && uuidObject == [NSNull null]){
        uuidObject = self.purchaseNotice.uuid;
    }
    if (self.purchaseNotice.billnumber > 0 && billNumberObject == [NSNull null]) {
        billNumberObject = self.purchaseNotice.billnumber;
    }
    if (self.purchaseNotice && [versionObject integerValue] == 0) {
        versionObject = self.purchaseNotice.version;
    }
zhu's avatar
zhu committed
660
    NSMutableArray *billProducts = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
661 662
    for (NoticeProduct *product in _shopeArr) {
        [billProducts  addObject:[product dictForCommit]];
zhu's avatar
zhu committed
663 664 665 666 667
        }

    NSDictionary *dict = @{@"uuid":uuidObject,//唯一标识
                           @"billnumber":billNumberObject,
                           @"version":versionObject,
陈俊俊's avatar
陈俊俊 committed
668 669
                           @"title":[IBTCommon checkString:self.titleStr],
                           @"state":[IBTCommon checkString:state],
陈俊俊's avatar
陈俊俊 committed
670
                           @"purchasers":self.users,
陈俊俊's avatar
陈俊俊 committed
671
                           @"finishDate":[IBTCommon checkString:self.finishDateStr],
陈俊俊's avatar
陈俊俊 committed
672
                           @"remark":[IBTCommon checkString:self.remarkStr],
陈俊俊's avatar
陈俊俊 committed
673 674
                           @"products":billProducts};
    [IBTLoadingView showProgressLabel:msg];
zhu's avatar
zhu committed
675
    [[ICRHTTPController sharedController] savePurchaseNoticeWithData:dict success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
676
   
zhu's avatar
zhu committed
677
}
陈俊俊's avatar
陈俊俊 committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        _clickState = PURCHASENOTICE_STATE_NOTACCEPTED;
         [self saveSurvey:PURCHASENOTICE_STATE_NOTACCEPTED message:@"正在提交..."];
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if(self.purchaseNotice && [_clickState isEqualToString:PURCHASENOTICE_STATE_INITIAL]){
        [ICRUserUtil sharedInstance].needFresh = YES;
    }
}

朱朝吉's avatar
朱朝吉 committed
692 693 694 695 696 697 698

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

/*
zhu's avatar
zhu committed
699 700 701 702 703 704 705 706
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
朱朝吉's avatar
朱朝吉 committed
707 708

@end