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

#import "SeePurchaseNoticeViewController.h"
陈俊俊's avatar
陈俊俊 committed
10 11
#import "NewPurchaseViewController.h"
#import "NoticeProduct.h"
zhu's avatar
zhu committed
12
#import "NoticeDetailCell.h"
zhu's avatar
zhu committed
13
#import "SurveyCell.h"
zhu's avatar
zhu committed
14

zhu's avatar
zhu committed
15 16 17
#import "HPGrowingTextView.h"
#import "NoticeProductViewController.h"
#import "FollowUpRecordViewController.h"
zhu's avatar
zhu committed
18 19 20
#define BottomHeight 50
#define LeftMargin 15
#define LeftWidth 100
zhu's avatar
zhu committed
21
#define leftWidth 40
zhu's avatar
zhu committed
22 23
#define LeftHeight 30
#define TopMargin 15
zhu's avatar
zhu committed
24 25 26
#define TableHeight 46
#define RightWidth 30
#define TitleSize 15
zhu's avatar
zhu committed
27 28

typedef enum : NSUInteger {
陈俊俊's avatar
陈俊俊 committed
29 30 31
    EndTag = 3500,//结束
    NewTag,//新建
    AcceptTag,//接受
zhu's avatar
zhu committed
32 33
} BtnTag;

朱朝吉's avatar
朱朝吉 committed
34

陈俊俊's avatar
陈俊俊 committed
35
@interface SeePurchaseNoticeViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIAlertViewDelegate>
朱朝吉's avatar
朱朝吉 committed
36

zhu's avatar
zhu committed
37 38 39 40 41 42 43
{
    UIScrollView *_scrollView;
    UIView *_purchaseView;
    UIView *_bottomView;
    NSArray *_leftArr;
    UIButton *_endBtn;
    UIButton *_rejectBtn;
zhu's avatar
zhu committed
44 45 46 47 48 49 50 51 52
    UITableView *mingXiTableView;
     NSMutableArray *_shopeArr;
     NSIndexPath *selectedCellIndexPath;
    UITextField *_titleField;
    UILabel *_productLabel;
    UILabel *_personLabel;
     NSString *title;
    HPGrowingTextView *_noteTextView;
    NSMutableArray *selectCellAry;
zhu's avatar
zhu committed
53 54
}
@property (nonatomic,strong)UILabel *billNumberLabel;
陈俊俊's avatar
陈俊俊 committed
55
@property (nonatomic,strong)UILabel *titleLabel;
zhu's avatar
zhu committed
56
@property (nonatomic,strong)UILabel *createOperNameLabel;
陈俊俊's avatar
陈俊俊 committed
57
@property (nonatomic,strong)UILabel *userLabel;
zhu's avatar
zhu committed
58
@property (nonatomic,strong)UILabel *stateLabel;
陈俊俊's avatar
陈俊俊 committed
59
@property (nonatomic,strong)UILabel *countLabel;
陈俊俊's avatar
陈俊俊 committed
60 61
@property (nonatomic,strong)UILabel *finishLabel;

zhu's avatar
zhu committed
62
@property (nonatomic,strong)UILabel *noteLabel;
zhu's avatar
zhu committed
63 64 65
@property (nonatomic,strong)UILabel *HeardLabel;
@property (nonatomic,strong)UILabel *FootLabel;
@property (nonatomic,strong)UIButton *addDetailedButton;
朱朝吉's avatar
朱朝吉 committed
66 67 68 69 70
@end

@implementation SeePurchaseNoticeViewController

- (void)viewDidLoad {
朱朝吉's avatar
朱朝吉 committed
71
    
朱朝吉's avatar
朱朝吉 committed
72
    [super viewDidLoad];
zhu's avatar
zhu committed
73 74
    [self bulidLayout];
    [self getDataFromServer];
朱朝吉's avatar
朱朝吉 committed
75
}
zhu's avatar
zhu committed
76 77 78 79 80 81 82 83 84 85
- (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"];
陈俊俊's avatar
陈俊俊 committed
86 87
                PurchaseNotice *purchaseNotice = [[PurchaseNotice alloc]init];
                [purchaseNotice setValuesForKeysWithDictionary:dictData];
陈俊俊's avatar
陈俊俊 committed
88 89 90 91 92 93 94
                NSMutableArray *productArr = [NSMutableArray array];
                for (NSDictionary *billDict in self.purchaseNotice.products) {
                    NoticeProduct *billProbuct = [NoticeProduct new];
                    [billProbuct setValuesForKeysWithDictionary:billDict];
                    [productArr addObject:billProbuct];
                }
                purchaseNotice.products = productArr;
zhu's avatar
zhu committed
95
                self.purchaseNotice = purchaseNotice;
陈俊俊's avatar
陈俊俊 committed
96
                [strongSelf fetchtNoticeDetail];
zhu's avatar
zhu committed
97 98 99 100 101 102 103 104 105 106 107 108
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
陈俊俊's avatar
陈俊俊 committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    [[ICRHTTPController sharedController] getPurchaseNoticeDetailedWithPurchaseUuid:self.purchaseNotice.uuid success:succ failure:fail];
}
- (void)fetchtNoticeDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.purchaseNotice.billnumber];
    if ([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_NOTACCEPTED]) {
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未接受";
    }else if ([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_PURCHASEING]) {
        self.stateLabel.textColor = [UIColor greenColor];
        self.stateLabel.text = @"采购中";
    }else if ([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_FINISHED]) {
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已完成";
    }
    self.createOperNameLabel.text = [NSString stringWithFormat:@"%@%@",[IBTCommon checkString:self.purchaseNotice.create_operName],self.purchaseNotice.create_time.length > 10 ? [self.purchaseNotice.create_time substringToIndex:10] : self.purchaseNotice.create_time];

    self.titleLabel.text = [IBTCommon checkString:self.purchaseNotice.title];
    self.userLabel.text = [IBTCommon checkString:self.purchaseNotice.purchaserName];
陈俊俊's avatar
陈俊俊 committed
127 128
    self.countLabel.text = [NSString stringWithFormat:@"%@",[self calutionTotalCount]];
    self.finishLabel.text =  [NSString stringWithFormat:@"%@",self.purchaseNotice.finishDate?[[IBTCommon checkString:self.purchaseNotice.finishDate] substringToIndex:10]:@"无"];
陈俊俊's avatar
陈俊俊 committed
129
    self.noteLabel.text = [IBTCommon checkString:self.purchaseNotice.remark];
陈俊俊's avatar
陈俊俊 committed
130
    [_shopeArr addObjectsFromArray:self.purchaseNotice.products];
zhu's avatar
zhu committed
131 132
    [mingXiTableView  reloadData];

陈俊俊's avatar
陈俊俊 committed
133
    [self setNoteHeight];
zhu's avatar
zhu committed
134
}
陈俊俊's avatar
陈俊俊 committed
135 136 137 138
- (NSString *)calutionTotalCount{
    NSString *str = @"";
    NSInteger baseCount = 0;
    NSInteger purshaseCount = 0;
zhu's avatar
zhu committed
139

陈俊俊's avatar
陈俊俊 committed
140 141 142 143 144 145 146 147
    for (NoticeProduct *noticeProduct in self.purchaseNotice.products) {
        baseCount +=  [noticeProduct.quantity integerValue];
        purshaseCount += [noticeProduct.purchasedQuantity integerValue];
    }
    str = [NSString stringWithFormat:@"%@ 已采(%@)",[NSNumber numberWithInteger:baseCount],[NSNumber numberWithInteger:purshaseCount]];
    
    return str;
}
zhu's avatar
zhu committed
148 149 150 151 152 153 154 155 156 157

#pragma mark - 视图初始化
- (void)bulidLayout{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.backgroundColor = XXFBgColor;
    [self.view addSubview:_scrollView];
    [self createBtn];
    [self createPurchaseView];
zhu's avatar
zhu committed
158
    [self  createMingXiTableView];//自定义
陈俊俊's avatar
陈俊俊 committed
159 160
}
- (void)hiddenBottomBtn{
zhu's avatar
zhu committed
161 162 163 164 165 166 167
        _endBtn.hidden = YES;
        _rejectBtn.hidden = YES;
        CGRect scrollViewFrame = _scrollView.frame;
        scrollViewFrame.size.height = ScreenSize.height - 64;
        _scrollView.frame = scrollViewFrame;
}
- (void)createBtn{
陈俊俊's avatar
陈俊俊 committed
168
    _rejectBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:0 image:nil title:@"" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_SAVE_COLOR];
zhu's avatar
zhu committed
169 170 171 172
    [self.view addSubview:_rejectBtn];
    
    _endBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetMaxX(_rejectBtn.frame)+ LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:0 image:nil title:@"" titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
    [self.view addSubview:_endBtn];
陈俊俊's avatar
陈俊俊 committed
173 174
    
    if ([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_NOTACCEPTED]) {
陈俊俊's avatar
陈俊俊 committed
175 176 177
            if ([self checkIsPermission:NOTICE_PERMISSIONS_ACCEPTTASK]&& [self checkIsPermission:NOTICE_PERMISSIONS_FINISH]) {
                _rejectBtn.tag = EndTag;
                [_rejectBtn setTitle:@"结束" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
178 179
                _endBtn.tag = AcceptTag;
                [_endBtn setTitle:@"接受任务" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193
            }else{
                if ([self checkIsPermission:NOTICE_PERMISSIONS_ACCEPTTASK]) {
                    _rejectBtn.hidden = YES;
                    _endBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
                    _endBtn.tag = AcceptTag;
                    [_endBtn setTitle:@"接受任务" forState:UIControlStateNormal];
                }else if([self checkIsPermission:NOTICE_PERMISSIONS_FINISH]){
                    _rejectBtn.hidden = YES;
                    _endBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
                    _endBtn.tag = EndTag;
                    [_endBtn setTitle:@"结束" forState:UIControlStateNormal];
                }else{
                    [self hiddenBottomBtn];
                }
陈俊俊's avatar
陈俊俊 committed
194
            }
陈俊俊's avatar
陈俊俊 committed
195
    }else if([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_PURCHASEING]){
陈俊俊's avatar
陈俊俊 committed
196 197 198
        if ([self checkIsPermission:NOTICE_PERMISSIONS_FINISH] && [self checkIsPermission:NOTICE_PERMISSIONS_CREATEBILL]) {
            _rejectBtn.tag = EndTag;
            [_rejectBtn setTitle:@"结束" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
199 200
            _endBtn.tag = NewTag;
            [_endBtn setTitle:@"新建采购单" forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
201
        }else{
陈俊俊's avatar
陈俊俊 committed
202 203 204 205 206 207 208 209 210 211 212 213 214
            if([self checkIsPermission:NOTICE_PERMISSIONS_FINISH]){
                _rejectBtn.hidden = YES;
                _endBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
                _endBtn.tag = EndTag;
                [_endBtn setTitle:@"结束" forState:UIControlStateNormal];
            }else if([self checkIsPermission:NOTICE_PERMISSIONS_CREATEBILL]){
                _rejectBtn.hidden = YES;
                _endBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
                _endBtn.tag = NewTag;
                [_endBtn setTitle:@"新建采购单" forState:UIControlStateNormal];
            }else{
                [self hiddenBottomBtn];
            }
陈俊俊's avatar
陈俊俊 committed
215 216 217
        }
    }else if([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_FINISHED]) {
        [self hiddenBottomBtn];
zhu's avatar
zhu committed
218 219
    }
}
陈俊俊's avatar
陈俊俊 committed
220 221 222 223 224 225 226 227
- (BOOL)checkIsPermission:(NSString *)permission{
    for (NSString *per in [ICRUserUtil sharedInstance].permissions) {
        if ([per isEqualToString:permission]) {
            return YES;
        }
    }
    return NO;
}
zhu's avatar
zhu committed
228 229 230
- (void)btnClick:(UIButton *)btn{
    NSLog(@"%ld",(long)btn.tag);
    switch (btn.tag) {
陈俊俊's avatar
陈俊俊 committed
231
        
zhu's avatar
zhu committed
232 233
        case EndTag:
        {
陈俊俊's avatar
陈俊俊 committed
234 235 236
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            [alertView show];
zhu's avatar
zhu committed
237 238
        }
            break;
陈俊俊's avatar
陈俊俊 committed
239
        case NewTag:
zhu's avatar
zhu committed
240
        {
陈俊俊's avatar
陈俊俊 committed
241 242 243 244
            NewPurchaseViewController *nvc = [NewPurchaseViewController new];
            nvc.title = @"新建采购单";
            nvc.purchaseNotice = self.purchaseNotice;
            [self PushViewController:nvc animated:YES];
zhu's avatar
zhu committed
245 246
        }
            break;
陈俊俊's avatar
陈俊俊 committed
247
        case AcceptTag:
zhu's avatar
zhu committed
248
        {
陈俊俊's avatar
陈俊俊 committed
249
            [self dealByAction:@"accept"];
zhu's avatar
zhu committed
250 251 252 253 254 255
        }
            break;
        default:
            break;
    }
}
陈俊俊's avatar
陈俊俊 committed
256 257 258 259 260 261 262 263 264
- (void)dealByAction:(NSString *)action{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                if ([action isEqualToString:@"accept"]) {
陈俊俊's avatar
陈俊俊 committed
265
#warning 有点问
陈俊俊's avatar
陈俊俊 committed
266
                    [ICRUserUtil sharedInstance].needFresh = YES;
陈俊俊's avatar
陈俊俊 committed
267 268 269 270 271 272 273 274 275 276 277
                    if ([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_CREATEBILL]) {
                        _stateLabel.text = @"发运中";
                        _endBtn.hidden = YES;
                        _rejectBtn.hidden = NO;
                        [_rejectBtn setTitle:@"新建采购单" forState:UIControlStateNormal];
                        _rejectBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
                        _rejectBtn.tag = NewTag;
                    }else{
                        [self PopViewControllerAnimated:YES];
                    }
                   
陈俊俊's avatar
陈俊俊 committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                }else{
                    [ICRUserUtil sharedInstance].needFresh = YES;
                    [self PopViewControllerAnimated:YES];
                }
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"操作异常"];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    if ([action isEqualToString:@"accept"]) {
        [[ICRHTTPController sharedController] acceptPurchaseNoticeWithUuid:self.purchaseNotice.uuid version:self.purchaseNotice.version success:succ failure:fail];
    }else{
        [[ICRHTTPController sharedController] finishPurchaseNoticeWithUuid:self.purchaseNotice.uuid version:self.purchaseNotice.version success:succ failure:fail];
    }
}
zhu's avatar
zhu committed
300 301
- (void)createMingXiTableView
{
陈俊俊's avatar
陈俊俊 committed
302
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width, 300)];
陈俊俊's avatar
陈俊俊 committed
303 304 305
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
    
陈俊俊's avatar
陈俊俊 committed
306
    _shopeArr=[[NSMutableArray alloc]init];
zhu's avatar
zhu committed
307
    selectCellAry=[[NSMutableArray alloc]initWithCapacity:1000];
陈俊俊's avatar
陈俊俊 committed
308
    mingXiTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, _bottomView.height)];
zhu's avatar
zhu committed
309 310 311 312 313 314
    mingXiTableView.backgroundColor = [UIColor whiteColor];
    mingXiTableView.tag=1002;
    mingXiTableView.delegate=self;
    mingXiTableView.dataSource=self;
    UIView *footView2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    footView2.backgroundColor=[UIColor clearColor];
zhu's avatar
zhu committed
315 316
    NSArray *ary=[NSArray arrayWithObjects:@"商品",@"包装规格",@"包装数量",@"已购数量", nil];
    CGFloat gipWidth = (ScreenSize.width-leftWidth-RightWidth)/4;
zhu's avatar
zhu committed
317 318 319 320 321 322 323 324 325 326 327 328
    
    for (int i=0; i< ary.count;i++ ) {
        UILabel *lable=[[UILabel alloc]init];
        if (i==0) {
            lable.frame=CGRectMake(leftWidth, 0, gipWidth,TableHeight);
        }
        if (i==1) {
            lable.frame=CGRectMake(leftWidth+gipWidth+1, 0, gipWidth,TableHeight);
        }
        if (i==2) {
            lable.frame=CGRectMake(leftWidth+2*gipWidth+2, 0, gipWidth,TableHeight);
        }
zhu's avatar
zhu committed
329 330 331 332
        
        if (i==3) {
            lable.frame=CGRectMake(leftWidth+3*gipWidth+3, 0, gipWidth,TableHeight);
        }
zhu's avatar
zhu committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
        lable.text=[ary objectAtIndex:i];
        lable.textColor=GXF_PLACEHOLDER_COLOR;
        lable.font = GXF_FIFTEENTEN_SIZE;
        [footView2 addSubview:lable];
    }
    
    UIView *footView3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    footView3.backgroundColor=[UIColor clearColor];
    self.addDetailedButton=[UIButton  buttonWithType: UIButtonTypeCustom];
    [self.addDetailedButton  setFrame:CGRectMake(0, 0, ScreenSize.width, TableHeight)];
    [self.addDetailedButton setTitle:@">>查看跟进记录" forState:UIControlStateNormal];
    self.addDetailedButton.titleLabel.font = GXF_FIFTEENTEN_SIZE;
    [self.addDetailedButton addTarget:self action:@selector(addShopeDetailed) forControlEvents:UIControlEventTouchUpInside];
    [self.addDetailedButton setTitleColor:GXF_PLACEHOLDER_COLOR forState:UIControlStateNormal];
    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);
    [footView3 addSubview:self.addDetailedButton];
    [footView3 addSubview:self.HeardLabel];
    [footView3 addSubview:self.FootLabel];
    mingXiTableView.tableFooterView = footView3;
    mingXiTableView.tableHeaderView=footView2;
陈俊俊's avatar
陈俊俊 committed
358
    [_bottomView addSubview:mingXiTableView];
zhu's avatar
zhu committed
359
}
zhu's avatar
zhu committed
360
- (void)createPurchaseView{
陈俊俊's avatar
陈俊俊 committed
361
    
陈俊俊's avatar
陈俊俊 committed
362
    _leftArr = @[@"单号:",@"创建人:",@"标题:",@"状态:",@"采购员:",@"合计基础数量:",@"要求采购完成时间:",@"备注:"];
zhu's avatar
zhu committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    _purchaseView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight*_leftArr.count +LeftMargin)];
    _purchaseView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_purchaseView];
    
    for (NSInteger i = 0 ; i < _leftArr.count; i++) {
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, 10 + LeftHeight *i, LeftWidth, LeftHeight)];
        leftLabel.font = GXF_SEVENTEENTH_SIZE;
        leftLabel.text = _leftArr[i];
        leftLabel.textColor = GXF_DETAIL_COLOR;
        [_purchaseView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), 10 + LeftHeight *i, _purchaseView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
        rightLabel.font = GXF_SEVENTEENTH_SIZE;
        rightLabel.textColor = GXF_DETAIL_COLOR;
        
        if (i == 0) {
            self.billNumberLabel = rightLabel;
        }else if (i == 1) {
            self.createOperNameLabel = rightLabel;
陈俊俊's avatar
陈俊俊 committed
382 383 384 385 386 387
        }else if(i == 2){
            self.titleLabel = rightLabel;
        }else if(i == 3){
            self.stateLabel = rightLabel;
        }else if(i == 4){
            self.userLabel = rightLabel;
陈俊俊's avatar
陈俊俊 committed
388
        }else if(i == 5){
陈俊俊's avatar
陈俊俊 committed
389 390
            leftLabel.width = 110;
            rightLabel.x = leftLabel.right;
陈俊俊's avatar
陈俊俊 committed
391
            self.countLabel = rightLabel;
陈俊俊's avatar
陈俊俊 committed
392 393 394 395 396 397
        }else if(i == 6){
            leftLabel.width = 145;
            rightLabel.left = leftLabel.right;
            self.finishLabel = rightLabel;
        }
        else if(i == _leftArr.count - 1){
zhu's avatar
zhu committed
398 399 400 401 402 403 404 405 406
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
        }
        [_purchaseView addSubview:rightLabel];
    }
}
- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
陈俊俊's avatar
陈俊俊 committed
407
    self.noteLabel.height = height;
zhu's avatar
zhu committed
408
    
陈俊俊's avatar
陈俊俊 committed
409 410
    CGFloat totalHeight = height + LeftHeight *_leftArr.count;
    _purchaseView.height = totalHeight;
zhu's avatar
zhu committed
411 412 413 414 415 416 417
    
    CGRect bottomFrame = _bottomView.frame;
    bottomFrame.origin.y = CGRectGetMaxY(_purchaseView.frame) + TopMargin;
    _bottomView.frame = bottomFrame;
    
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
}
朱朝吉's avatar
朱朝吉 committed
418 419 420 421 422

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
zhu's avatar
zhu committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([tableView isEqual:mingXiTableView])
    {
        return 1;
    }
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:mingXiTableView])
    {
        return _shopeArr.count;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    if ([tableView isEqual:mingXiTableView])
    {
        
        static NSString *CellID = @"CellID";
zhu's avatar
zhu committed
445
        NoticeDetailCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellID];
zhu's avatar
zhu committed
446 447
        
        if (Cell == nil) {
zhu's avatar
zhu committed
448
            Cell = [[NoticeDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
zhu's avatar
zhu committed
449 450 451
            Cell.isButtonhidden=YES;
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            Cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
452

zhu's avatar
zhu committed
453 454
        }
        [self  showShopDetail:Cell indexPath:indexPath];
陈俊俊's avatar
陈俊俊 committed
455
        if ([self comperIndexpath:indexPath]) {
zhu's avatar
zhu committed
456 457 458 459 460 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
            Cell.arrowView.image = [UIImage imageNamed:@"arrowdown"];
            Cell.button.hidden=YES;
            Cell.backgroundColor=XXFBgColor;
            Cell.subSview.hidden=NO;
        }else
        {
            Cell.arrowView.image = [UIImage imageNamed:@"arrowright"];
            Cell.backgroundColor=[UIColor whiteColor];
            Cell.subSview.hidden=YES;
            
        }
         Cell.button.hidden=YES;
        Cell.button.tag=indexPath.row;
        [Cell.button addTarget:self action:@selector(didtoucher:) forControlEvents:UIControlEventTouchUpInside];
       
        return Cell;
        
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:mingXiTableView])
    {
        if ([self  comperIndexpath:indexPath]) {
            return TableHeight*3;
        }else
        {
            return TableHeight;
        }
        
    }
    return TableHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:mingXiTableView])
    {
zhu's avatar
zhu committed
492
        NoticeDetailCell *Cell=(NoticeDetailCell*)[mingXiTableView cellForRowAtIndexPath:indexPath ];
陈俊俊's avatar
陈俊俊 committed
493
        if (![self comperIndexpath:indexPath]) {
zhu's avatar
zhu committed
494
            Cell.isSelected=YES;
陈俊俊's avatar
陈俊俊 committed
495
            Cell.subSview.hidden = NO;
zhu's avatar
zhu committed
496 497 498
            [selectCellAry addObject:indexPath];
        }else{
            Cell.isSelected=NO;
陈俊俊's avatar
陈俊俊 committed
499
            Cell.subSview.hidden = YES;
zhu's avatar
zhu committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
            [selectCellAry removeObject:indexPath];
        }
        selectedCellIndexPath = indexPath;
        [mingXiTableView reloadData];
    }
}


-(BOOL)comperIndexpath:(NSIndexPath *)indexPath
{
    for (NSIndexPath *path in selectCellAry) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}

//查看跟进记录
-(void)addShopeDetailed
{
    FollowUpRecordViewController *nvc = [FollowUpRecordViewController new];
    nvc.title = @"查看跟进记录";
    nvc.purchaseNotice=self.purchaseNotice;
    [self PushViewController:nvc animated:YES];
}
zhu's avatar
zhu committed
526
-(void)showShopDetail:(NoticeDetailCell*)Cell indexPath:(NSIndexPath *)indexPath
zhu's avatar
zhu committed
527 528 529
{
    NoticeProduct *noticeProduct=[_shopeArr objectAtIndex:indexPath.row];
    Cell.SpLabel.text=noticeProduct.productName;//商品
zhu's avatar
zhu committed
530
    Cell.shopeName.text=[NSString stringWithFormat:@"%@[%@]",noticeProduct.productName,noticeProduct.productCode];
陈俊俊's avatar
陈俊俊 committed
531
    Cell.BzggLabel.text= [NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
陈俊俊's avatar
陈俊俊 committed
532 533 534
    Cell.packageUnit.text=noticeProduct.packUnit;//包装单位
    Cell.BzslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
    Cell.packageQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];
陈俊俊's avatar
陈俊俊 committed
535 536
    Cell.packageSpecification.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
    Cell.foundationQuantity.text= [NSString stringWithFormat:@"%@%@",noticeProduct.quantity,noticeProduct.baseUnit];//基础数量
陈俊俊's avatar
陈俊俊 committed
537 538

    
陈俊俊's avatar
陈俊俊 committed
539
    Cell.BzggLabel.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
陈俊俊's avatar
陈俊俊 committed
540
    Cell.BzslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
陈俊俊's avatar
陈俊俊 committed
541
    Cell.packageSpecification.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
zhu's avatar
zhu committed
542 543
     Cell.YcgslLabel.text=[noticeProduct.purchasedQuantity stringValue];//已采购数量
    Cell.packageUnit.text=noticeProduct.packUnit;//包装单位
陈俊俊's avatar
陈俊俊 committed
544
    Cell.packageQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
陈俊俊's avatar
陈俊俊 committed
545
    Cell.YcgslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.purchasedQuantity,noticeProduct.packUnit];//已采购数量
陈俊俊's avatar
陈俊俊 committed
546
    Cell.foundationQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.quantity,noticeProduct.baseUnit];//基础数量
陈俊俊's avatar
陈俊俊 committed
547
    Cell.remark.text= [NSString stringWithFormat:@"%@",noticeProduct.remark?noticeProduct.remark:@"无"];//备注
陈俊俊's avatar
陈俊俊 committed
548 549
    if (!noticeProduct.purchasedQuantity) {
        Cell.YcgslLabel.text= [NSString stringWithFormat:@"0%@",noticeProduct.packUnit];//已采购数量
zhu's avatar
zhu committed
550
    }
zhu's avatar
zhu committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
}
//编辑
- (void)didtoucher:(UIButton*)button
{
    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];
            
        }
    };
    nvc.deleteNoticeProduct = ^(NoticeProduct *fee,NSIndexPath *indexPath){
        if (fee) {
            [_shopeArr removeObjectAtIndex:indexPath.row];
            [mingXiTableView reloadData];
            
        }
    };
    
    [self PushViewController:nvc animated:YES];
}
朱朝吉's avatar
朱朝吉 committed
581

陈俊俊's avatar
陈俊俊 committed
582 583 584 585 586 587 588
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [self dealByAction:@"end"];//结束
    }
}


朱朝吉's avatar
朱朝吉 committed
589 590 591 592 593 594 595 596 597 598 599
/*
#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.
}
*/

@end