NewPurchaseNoticeViewController.m 21.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"
zhu's avatar
zhu committed
19
#import "PurchaseBillProduct.h"
朱朝吉's avatar
朱朝吉 committed
20
#define LeftMargin 15
zhu's avatar
zhu committed
21 22 23
#define LeftWidth 40
#define RightWidth 30
#define SpaceMargin 1
朱朝吉's avatar
朱朝吉 committed
24 25 26 27 28 29 30 31
#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
32
#define FootOfsetHeight 140
zhu's avatar
zhu committed
33 34
#define BottomViewHeight 60

zhu's avatar
zhu committed
35

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

zhu's avatar
zhu committed
65 66 67 68
@property (nonatomic,strong)UILabel *HeardLabel;
@property (nonatomic,strong)UILabel *FootLabel;
@property (nonatomic,strong)UIButton *addDetailedButton;

朱朝吉's avatar
朱朝吉 committed
69

朱朝吉's avatar
朱朝吉 committed
70 71 72 73 74 75 76

@end

@implementation NewPurchaseNoticeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
77
    [self setupSubviews];
zhu's avatar
zhu committed
78 79 80 81
    //数据默认值
    uuidObject = [NSNull null];
    billNumberObject = [NSNull null];
    versionObject = [NSNumber numberWithInteger:0];
陈俊俊's avatar
陈俊俊 committed
82 83 84
    if (self.purchaseNotice) {
        [self getDataFromServer];
    }
朱朝吉's avatar
朱朝吉 committed
85
}
陈俊俊's avatar
陈俊俊 committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
- (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:@"正在加载..."];
    [[ICRHTTPController sharedController] getPurchaseNoticeDetailedWithPurchaseUuid:self.purchaseNotice.uuid success:succ failure:fail];
}
- (void)prepareDataInCell{
    if (self.purchaseNotice) {
        if (self.purchaseNotice.title.length > 0) {
            _titleField.text = self.purchaseNotice.title;
            self.titleStr = self.purchaseNotice.title;
        }
        if (self.purchaseNotice.purchaserName.length > 0) {
            _personLabel.text = self.purchaseNotice.purchaserName;
            _personLabel.textColor = GXF_CONTENT_COLOR;
            self.purchaseUuidStr = self.purchaseNotice.purchaserUuid;
            self.purchaseCodeStr = self.purchaseNotice.purchaserCode;
            self.purchaseNameStr = self.purchaseNotice.purchaserName;
        }
        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
144 145
-(void)setupSubviews
{
zhu's avatar
zhu committed
146
    selectCellAry=[[NSMutableArray alloc]initWithCapacity:1000];
朱朝吉's avatar
朱朝吉 committed
147
    _dataArr=[[NSMutableArray alloc]initWithObjects:@"标题:",@"采购员:",@"备注:", nil];
zhu's avatar
zhu committed
148
    _shopeArr=[[NSMutableArray alloc]initWithObjects: nil];
朱朝吉's avatar
朱朝吉 committed
149 150
    self.view.backgroundColor  = XXFBgColor;
    
zhu's avatar
zhu committed
151
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, LeftMargin,ScreenSize.width, ScreenSize.height/3-LeftMargin)) style:(UITableViewStylePlain)];
朱朝吉's avatar
朱朝吉 committed
152 153 154 155 156
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.tag=1001;
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
zhu's avatar
zhu committed
157
    
zhu's avatar
zhu committed
158
    mingXiTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 2*LeftMargin+_tableView.frame.size.height, ScreenSize.width, ScreenSize.height-_tableView.height-ScreenSize.height/5)];
zhu's avatar
zhu committed
159
    mingXiTableView.backgroundColor = [UIColor whiteColor];
朱朝吉's avatar
朱朝吉 committed
160
    mingXiTableView.tag=1002;
zhu's avatar
zhu committed
161
    mingXiTableView.bounces=NO;
朱朝吉's avatar
朱朝吉 committed
162 163 164
    mingXiTableView.delegate=self;
    mingXiTableView.dataSource=self;
    
zhu's avatar
zhu committed
165 166
    UIView *footView2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    footView2.backgroundColor=[UIColor clearColor];
zhu's avatar
zhu committed
167
    NSArray *ary=[NSArray arrayWithObjects:@"商品",@"包装规格",@"包装数量", nil];
zhu's avatar
zhu committed
168
    //    NSArray *ary=[NSArray arrayWithObjects: nil];
zhu's avatar
zhu committed
169
    CGFloat gipWidth = (ScreenSize.width-LeftWidth-RightWidth)/3;
zhu's avatar
zhu committed
170 171 172 173
    
    for (int i=0; i< ary.count;i++ ) {
        UILabel *lable=[[UILabel alloc]init];
        if (i==0) {
zhu's avatar
zhu committed
174
            lable.frame=CGRectMake(LeftWidth, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
175 176
        }
        if (i==1) {
zhu's avatar
zhu committed
177
            lable.frame=CGRectMake(LeftWidth+gipWidth+1, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
178 179
        }
        if (i==2) {
zhu's avatar
zhu committed
180
            lable.frame=CGRectMake(LeftWidth+2*gipWidth+2, 0, gipWidth,TableHeight);
zhu's avatar
zhu committed
181
        }
zhu's avatar
zhu committed
182
        
zhu's avatar
zhu committed
183
        //        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(LeftWidth + (SpaceMargin + headWidth)*i,0, headWidth, 50)];
zhu's avatar
zhu committed
184
        lable.text=[ary objectAtIndex:i];
陈俊俊's avatar
陈俊俊 committed
185 186
        lable.textColor=GXF_PLACEHOLDER_COLOR;
        lable.font = GXF_FIFTEENTEN_SIZE;
zhu's avatar
zhu committed
187 188
        [footView2 addSubview:lable];
    }
zhu's avatar
zhu committed
189 190 191 192
    
    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
193
    [self.addDetailedButton  setFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
zhu's avatar
zhu committed
194
    [self.addDetailedButton setTitle:@"+ 点击添加商品明细" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
195
    self.addDetailedButton.titleLabel.font = GXF_FIFTEENTEN_SIZE;
zhu's avatar
zhu committed
196
    [self.addDetailedButton addTarget:self action:@selector(addShopeDetailed) forControlEvents:UIControlEventTouchUpInside];
陈俊俊's avatar
陈俊俊 committed
197
    [self.addDetailedButton setTitleColor:GXF_PLACEHOLDER_COLOR forState:UIControlStateNormal];
zhu's avatar
zhu committed
198 199 200 201 202 203 204
    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
205
    
zhu's avatar
zhu committed
206 207 208 209 210 211 212 213 214
    
    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
215 216 217 218
    [footView3 addSubview:self.addDetailedButton];
    [footView3 addSubview:self.HeardLabel];
    [footView3 addSubview:self.FootLabel];
    
朱朝吉's avatar
朱朝吉 committed
219
    
zhu's avatar
zhu committed
220
    
zhu's avatar
zhu committed
221 222 223
    mingXiTableView.tableFooterView = footView3;
    mingXiTableView.tableHeaderView=footView2;
    [self.view addSubview:_tableView];
朱朝吉's avatar
朱朝吉 committed
224
    [self.view addSubview:mingXiTableView];
zhu's avatar
zhu committed
225
    [self.view addSubview:footView4];
zhu's avatar
zhu committed
226
    
朱朝吉's avatar
朱朝吉 committed
227 228 229 230 231 232 233 234
}

#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([tableView isEqual:_tableView]) {
        return 1;
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
235
        return 1;
朱朝吉's avatar
朱朝吉 committed
236 237 238 239 240 241
    }
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:_tableView]) {
zhu's avatar
zhu committed
242
        return _dataArr.count;
朱朝吉's avatar
朱朝吉 committed
243 244
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
245
        return _shopeArr.count;
朱朝吉's avatar
朱朝吉 committed
246 247 248 249 250
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([tableView isEqual:_tableView]) {
zhu's avatar
zhu committed
251
        
zhu's avatar
zhu committed
252 253 254 255 256 257 258 259 260 261 262
        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];
朱朝吉's avatar
朱朝吉 committed
263
        }
zhu's avatar
zhu committed
264 265
        [cell setTitleStr:_dataArr[indexPath.row]];
        return cell;
朱朝吉's avatar
朱朝吉 committed
266 267 268 269 270 271 272 273 274
    }else if ([tableView isEqual:mingXiTableView])
    {
        
        static NSString *CellID = @"CellID";
        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
275 276 277
            
            //            Cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;向左箭头
            //            [self  showShopDetail:Cell indexPath:indexPath];
zhu's avatar
zhu committed
278
        }
zhu's avatar
zhu committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292
        [self  showShopDetail:Cell indexPath:indexPath];
        if (Cell.isSelected==YES) {
            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
293
        return Cell;
zhu's avatar
zhu committed
294
        
朱朝吉's avatar
朱朝吉 committed
295 296 297 298 299 300 301 302 303 304 305 306 307
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_tableView]) {
        if (indexPath.row == 2){
            return TableHeight*2;
        }else{
            return TableHeight;
        }
        
    }else if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
308 309 310 311 312 313 314
        if ([self  comperIndexpath:indexPath]) {
            return TableHeight*3;
        }else
        {
            return TableHeight;
        }
        
朱朝吉's avatar
朱朝吉 committed
315 316 317 318 319 320
    }
    return TableHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_tableView]) {
        
陈俊俊's avatar
陈俊俊 committed
321
        if(indexPath.row == 1){
zhu's avatar
zhu committed
322 323
            ChosePersonViewController *cvc = [ChosePersonViewController new];
            cvc.choseBaseInfo = ^(NSArray *users){
陈俊俊's avatar
陈俊俊 committed
324 325 326 327 328 329 330 331
                if (users.count > 0) {
                    SurveyUser *user = users[0];
                    _personLabel.text = user.userName;
                    _personLabel.textColor = GXF_CONTENT_COLOR;
                    self.purchaseNameStr = user.userName;
                    self.purchaseCodeStr = user.userCode;
                    self.purchaseUuidStr = user.userUuid;

zhu's avatar
zhu committed
332 333 334 335 336
                }
            };
            cvc.isMoreChose = NO;
            [self PushViewController:cvc animated:YES];
        }
zhu's avatar
zhu committed
337 338 339
    }else if ([tableView isEqual:mingXiTableView])
    {
        PurchaseNoticeCell *Cell=(PurchaseNoticeCell*)[mingXiTableView cellForRowAtIndexPath:indexPath ];
zhu's avatar
zhu committed
340 341 342 343 344 345 346 347
        if (Cell.isSelected==NO) {
            Cell.isSelected=YES;
            [selectCellAry addObject:indexPath];
        }else{
            Cell.isSelected=NO;
            [selectCellAry removeObject:indexPath];
        }
        
zhu's avatar
zhu committed
348 349
        selectedCellIndexPath = indexPath;
        
zhu's avatar
zhu committed
350
        
zhu's avatar
zhu committed
351
        [mingXiTableView reloadData];
朱朝吉's avatar
朱朝吉 committed
352 353 354 355 356 357
    }
}


-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
陈俊俊's avatar
陈俊俊 committed
358
        _titleField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
朱朝吉's avatar
朱朝吉 committed
359
        _titleField.textAlignment = NSTextAlignmentRight;
zhu's avatar
zhu committed
360
        _titleField.textColor = GXF_CONTENT_COLOR;
朱朝吉's avatar
朱朝吉 committed
361 362 363 364
        _titleField.placeholder = @"输入采购通知标题";
        _titleField.font = FontSize(15);
        _titleField.returnKeyType = UIReturnKeyDone;
        _titleField.delegate = self;
zhu's avatar
zhu committed
365
        title=_titleField.text;
朱朝吉's avatar
朱朝吉 committed
366
        [cell.contentView addSubview:_titleField];
zhu's avatar
zhu committed
367
        
朱朝吉's avatar
朱朝吉 committed
368
    }else if (indexPath.row == _dataArr.count -1){
陈俊俊's avatar
陈俊俊 committed
369
        _noteTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
朱朝吉's avatar
朱朝吉 committed
370 371 372 373 374 375 376 377 378 379 380 381 382
        _noteTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        _noteTextView.minNumberOfLines = 1;
        _noteTextView.maxNumberOfLines = 4;
        _noteTextView.font = FontSize(15);
        _noteTextView.textAlignment = NSTextAlignmentRight;
        _noteTextView.delegate = self;
        _noteTextView.returnKeyType = UIReturnKeyDone;
        _noteTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:_noteTextView];
        CGRect lineFrame =  cell.lineLabel.frame;
        lineFrame.origin.y = TableHeight*2-1;
        cell.lineLabel.frame = lineFrame;
    }else{
陈俊俊's avatar
陈俊俊 committed
383
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
朱朝吉's avatar
朱朝吉 committed
384
        contentLabel.textAlignment= NSTextAlignmentRight;
zhu's avatar
zhu committed
385
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
朱朝吉's avatar
朱朝吉 committed
386 387 388 389 390 391 392
        contentLabel.font = FontSize(TitleSize);
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 1) {
            contentLabel.text = @"选择采购员";
            _personLabel = contentLabel;
        }
    }
zhu's avatar
zhu committed
393
}
zhu's avatar
zhu committed
394 395 396 397 398 399 400 401 402
-(BOOL)comperIndexpath:(NSIndexPath *)indexPath
{
    for (NSIndexPath *path in selectCellAry) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
陈俊俊's avatar
陈俊俊 committed
403

zhu's avatar
zhu committed
404 405 406
//添加商品明细
-(void)addShopeDetailed
{
陈俊俊's avatar
陈俊俊 committed
407 408 409 410 411 412 413
    NoticeProductViewController *nvc = [NoticeProductViewController new];
    nvc.navTitle = @"添加商品";
    nvc.choseNoticeProduct = ^(NoticeProduct *product,NSIndexPath *indexPath){
        if (product) {
            [_shopeArr addObject:product];
            [mingXiTableView reloadData];
        }
zhu's avatar
zhu committed
414
    };
zhu's avatar
zhu committed
415
    
陈俊俊's avatar
陈俊俊 committed
416
    [self PushViewController:nvc animated:YES];
zhu's avatar
zhu committed
417 418 419
}
-(void)showShopDetail:(PurchaseNoticeCell*)Cell indexPath:(NSIndexPath *)indexPath
{
陈俊俊's avatar
陈俊俊 committed
420 421 422 423 424 425 426 427
    NoticeProduct *noticeProduct=[_shopeArr objectAtIndex:indexPath.row];
    Cell.SpLabel.text=noticeProduct.productName;//商品
    Cell.DjLabel.text=noticeProduct.packUnit;//包装单价
    Cell.BzggLabel.text=[noticeProduct.qpc stringValue];//包装规格
    Cell.BzslLabel.text=[noticeProduct.qpcQuantity stringValue];//包装数量
    Cell.packageSpecification.text=[noticeProduct.qpc stringValue];//包装规格
    Cell.foundationQuantity.text=[noticeProduct.quantity stringValue];//基础数量
    Cell.remark.text=noticeProduct.remark;//备注
zhu's avatar
zhu committed
428
    
zhu's avatar
zhu committed
429 430
}
//编辑
zhu's avatar
zhu committed
431
- (void)didtoucher:(UIButton*)button
zhu's avatar
zhu committed
432
{
陈俊俊's avatar
陈俊俊 committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446
    NoticeProductViewController *nvc = [NoticeProductViewController new];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:button.tag];
    NoticeProduct *shopDetail=[_shopeArr objectAtIndex:button.tag];

    if (indexPath) {
        nvc.navTitle = @"编辑费用";
        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
447 448
        }
    };
陈俊俊's avatar
陈俊俊 committed
449 450 451 452 453 454 455 456 457
    nvc.deleteNoticeProduct = ^(NoticeProduct *fee,NSIndexPath *indexPath){
        if (fee) {
            [_shopeArr removeObjectAtIndex:indexPath.row];
            [mingXiTableView reloadData];

        }
    };

    [self PushViewController:nvc animated:YES];
zhu's avatar
zhu committed
458
}
朱朝吉's avatar
朱朝吉 committed
459 460 461 462 463 464 465 466 467
#pragma mark delegate
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [_noteTextView resignFirstResponder];
    return YES;
}
- (void)keyboardHidden{
    [_titleField resignFirstResponder];
    [_noteTextView resignFirstResponder];
}
zhu's avatar
zhu committed
468 469 470 471
- (void)btnClick:(UIButton *)btn{
    switch (btn.tag) {
        case SaveTag:
        {
陈俊俊's avatar
陈俊俊 committed
472
            if ([self checkSurvey]) {
陈俊俊's avatar
陈俊俊 committed
473
                [self saveSurvey:PURCHASENOTICE_STATE_INITIAL message:@"正在保存..."];
陈俊俊's avatar
陈俊俊 committed
474
            }
zhu's avatar
zhu committed
475 476 477 478
        }
            break;
        case CommitTag:
        {
陈俊俊's avatar
陈俊俊 committed
479
            if ([self checkSurvey]) {
陈俊俊's avatar
陈俊俊 committed
480
                [self saveSurvey:PURCHASENOTICE_STATE_NOTACCEPTED message:@"正在提交..."];
陈俊俊's avatar
陈俊俊 committed
481
            }
zhu's avatar
zhu committed
482 483 484 485 486 487
        }
            break;
        default:
            break;
    }
}
zhu's avatar
zhu committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
- (BOOL)checkSurvey{
    self.titleStr = _titleField.text;
    self.remarkStr = _noteTextView.text;
    if ( self.titleStr.length==0) {
        ShowMessage(@"采购通知单标题不能为空");
        return NO;
    }
    if (_personLabel.text.length == 0 ) {
        ShowMessage(@"采购员不能为空");
        return NO;
    }
    if (_shopeArr.count==0) {
        ShowMessage(@"商品明细不能为空");
        return NO;

    }
    return YES;
}
- (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
517 518 519 520 521 522 523
                    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]];
zhu's avatar
zhu committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537
                }else{//提交成功
                    PurchaseNoticeViewController *svc = [PurchaseNoticeViewController new];
                    [self PushViewController:svc animated:YES];
                }
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    
陈俊俊's avatar
陈俊俊 committed
538 539 540 541 542 543 544 545 546
    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
547
    NSMutableArray *billProducts = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
548 549
    for (NoticeProduct *product in _shopeArr) {
        [billProducts  addObject:[product dictForCommit]];
zhu's avatar
zhu committed
550 551 552 553 554
        }

    NSDictionary *dict = @{@"uuid":uuidObject,//唯一标识
                           @"billnumber":billNumberObject,
                           @"version":versionObject,
陈俊俊's avatar
陈俊俊 committed
555
                           @"title":self.titleStr,
zhu's avatar
zhu committed
556
                           @"state":state,
陈俊俊's avatar
陈俊俊 committed
557 558 559 560 561 562
                           @"purchaserUuid":self.purchaseUuidStr,
                           @"purchaserCode":self.purchaseCodeStr,
                           @"purchaserName":self.purchaseNameStr,
                           @"remark":self.remarkStr,
                           @"products":billProducts};
    [IBTLoadingView showProgressLabel:msg];
zhu's avatar
zhu committed
563 564
    [[ICRHTTPController sharedController] savePurchaseNoticeWithData:dict success:succ failure:fail];
}
朱朝吉's avatar
朱朝吉 committed
565 566 567 568 569 570 571

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

/*
zhu's avatar
zhu committed
572 573 574 575 576 577 578 579
 #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
580 581

@end