//
//  SeePurchaseNoticeViewController.m
//  XFFruit
//
//  Created by mac on 15/8/16.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "SeePurchaseNoticeViewController.h"
#import "NewPurchaseViewController.h"
#import "NoticeProduct.h"
#import "NoticeDetailCell.h"
#import "SurveyCell.h"
#import "SurveyUser.h"
#import "HPGrowingTextView.h"
#import "NoticeProductViewController.h"
#import "FollowUpRecordViewController.h"
#define BottomHeight 50
#define LeftMargin 15
#define LeftWidth 100
#define leftWidth 40
#define LeftHeight 30
#define TopMargin 15
#define TableHeight 46
#define RightWidth 30
#define TitleSize 15

typedef enum : NSUInteger {
    EndTag = 3500,//结束
    NewTag,//新建
    AcceptTag,//接受
} BtnTag;


@interface SeePurchaseNoticeViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIAlertViewDelegate>

{
    UIScrollView *_scrollView;
    UIView *_purchaseView;
    UIView *_bottomView;
    NSArray *_leftArr;
    UIButton *_endBtn;
    UIButton *_rejectBtn;
    UITableView *mingXiTableView;
     NSMutableArray *_shopeArr;
     NSIndexPath *selectedCellIndexPath;
    UITextField *_titleField;
    UILabel *_productLabel;
    UILabel *_personLabel;
     NSString *title;
    HPGrowingTextView *_noteTextView;
    NSMutableArray *selectCellAry;
}
@property (nonatomic,strong)UILabel *billNumberLabel;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *createOperNameLabel;
@property (nonatomic,strong)UILabel *userLabel;
@property (nonatomic,strong)UILabel *stateLabel;
@property (nonatomic,strong)UILabel *countLabel;
@property (nonatomic,strong)UILabel *finishLabel;

@property (nonatomic,strong)UILabel *noteLabel;
@property (nonatomic,strong)UILabel *HeardLabel;
@property (nonatomic,strong)UILabel *FootLabel;
@property (nonatomic,strong)UIButton *addDetailedButton;
@end

@implementation SeePurchaseNoticeViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self bulidLayout];
    [self getDataFromServer];
}
- (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];
                NSMutableArray *productArr = [NSMutableArray array];
                for (NSDictionary *billDict in self.purchaseNotice.products) {
                    NoticeProduct *billProbuct = [NoticeProduct new];
                    [billProbuct setValuesForKeysWithDictionary:billDict];
                    [productArr addObject:billProbuct];
                }
                purchaseNotice.products = productArr;
                NSMutableArray *users = [NSMutableArray array];
                for (NSDictionary *userDict in purchaseNotice.purchasers) {
                    SurveyUser *user = [SurveyUser new];
                    [user setValuesForKeysWithDictionary:userDict];
                    [users addObject:user];
                }
                purchaseNotice.purchasers = users;
                self.purchaseNotice = purchaseNotice;
                [strongSelf fetchtNoticeDetail];
            }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)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];
    NSString *textStr = @"";
    for (SurveyUser *user in self.purchaseNotice.purchasers) {
        if (textStr.length == 0) {
            textStr = [textStr stringByAppendingFormat:@"%@",user.userName];
        }else {
            textStr = [textStr stringByAppendingFormat:@"、%@",user.userName];
        }
    }
    self.userLabel.text = [IBTCommon checkString:textStr];
    self.countLabel.text = [NSString stringWithFormat:@"%@",[self calutionTotalCount]];
    self.finishLabel.text =  [NSString stringWithFormat:@"%@",self.purchaseNotice.finishDate?[[IBTCommon checkString:self.purchaseNotice.finishDate] substringToIndex:10]:@"无"];
    self.noteLabel.text = [IBTCommon checkString:self.purchaseNotice.remark];
    [_shopeArr addObjectsFromArray:self.purchaseNotice.products];
    [mingXiTableView  reloadData];

    [self setNoteHeight];
}
- (NSString *)calutionTotalCount{
    NSString *str = @"";
    NSInteger baseCount = 0;
    NSInteger purshaseCount = 0;

    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;
}

#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];
    [self  createMingXiTableView];//自定义
}
- (void)hiddenBottomBtn{
        CGRect scrollViewFrame = _scrollView.frame;
        scrollViewFrame.size.height = ScreenSize.height - 64;
        _scrollView.frame = scrollViewFrame;
}

- (void)createBtnWithArr:(NSArray *)arr{
    CGFloat btnWidth = (ScreenSize.width - LeftMargin * (arr.count+1))/arr.count;
    for (NSInteger i = 0; i < arr.count; i++) {
        NSInteger btnTag = 0;
        if ([arr[i] isEqualToString:@"结束"]) {
            btnTag = EndTag;
        }else if ([arr[i] isEqualToString:@"接受任务"]) {
            btnTag = AcceptTag;
        }else if ([arr[i] isEqualToString:@"新建采购单"]) {
            btnTag = NewTag;
        }
        CGRect btnFrame = CGRectMake(LeftMargin + (LeftMargin + btnWidth)*i,  ScreenSize.height  - 64 - BottomHeight +5, btnWidth, 40);
        UIButton *perBtn = [IBTCustomButtom creatButtonWithFrame:btnFrame target:self sel:@selector(btnClick:) tag:btnTag image:nil title:arr[i] titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
        [self.view addSubview:perBtn];
    }
}


- (void)createBtn{
    if ([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_NOTACCEPTED]) {
        NSMutableArray *arr = [NSMutableArray array];
        if([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_FINISH]){
            [arr addObject:@"结束"];
        }
        if ([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_ACCEPTTASK]) {
            [arr addObject:@"接受任务"];
        }
        if (arr.count == 0) {
            [self hiddenBottomBtn];
        }else{
            [self createBtnWithArr:arr];
        }
    }else if([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_PURCHASEING]){
        NSMutableArray *arr = [NSMutableArray array];
        if([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_FINISH]){
            [arr addObject:@"结束"];
        }
        if([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_CREATEBILL]){
            [arr addObject:@"新建采购单"];
        }
        if (arr.count == 0) {
            [self hiddenBottomBtn];
            
        }else{
            [self createBtnWithArr:arr];
        }
    }else if([self.purchaseNotice.state isEqualToString:PURCHASENOTICE_STATE_FINISHED]) {
        [self hiddenBottomBtn];
    }
}
- (void)btnClick:(UIButton *)btn{
    NSLog(@"%ld",(long)btn.tag);
    switch (btn.tag) {
        
        case EndTag:
        {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            [alertView show];
        }
            break;
        case NewTag:
        {
            NewPurchaseViewController *nvc = [NewPurchaseViewController new];
            nvc.title = @"新建采购单";
            nvc.purchaseNotice = self.purchaseNotice;
            [self PushViewController:nvc animated:YES];
        }
            break;
        case AcceptTag:
        {
            [self dealByAction:@"accept"];
        }
            break;
        default:
            break;
    }
}
- (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"]) {
                    [ICRUserUtil sharedInstance].needFresh = YES;
                    if ([IBTCommon checkIsPermission:NOTICE_PERMISSIONS_CREATEBILL]) {
                        _stateLabel.text = @"采购中";
                        for (UIView *subView in self.view.subviews) {
                            if ([subView isKindOfClass:[UIButton class]]) {
                                [subView removeFromSuperview];
                            }
                        }
                        [self createBtnWithArr:@[@"新建采购单"]];
                    }else{
                        [self PopViewControllerAnimated:YES];
                    }
                   
                }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];
    }
}
- (void)createMingXiTableView
{
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width, 300)];
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
    
    _shopeArr=[[NSMutableArray alloc]init];
    selectCellAry=[[NSMutableArray alloc]initWithCapacity:1000];
    mingXiTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, _bottomView.height)];
    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];
    NSArray *ary=[NSArray arrayWithObjects:@"商品",@"包装规格",@"包装数量",@"已购数量", nil];
    CGFloat gipWidth = (ScreenSize.width-leftWidth-RightWidth)/4;
    
    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);
        }
        
        if (i==3) {
            lable.frame=CGRectMake(leftWidth+3*gipWidth+3, 0, gipWidth,TableHeight);
        }
        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;
    [_bottomView addSubview:mingXiTableView];
}
- (void)createPurchaseView{
    
    _leftArr = @[@"单号:",@"创建人:",@"标题:",@"状态:",@"采购员:",@"合计基础数量:",@"要求采购完成时间:",@"备注:"];
    _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;
        }else if(i == 2){
            self.titleLabel = rightLabel;
        }else if(i == 3){
            self.stateLabel = rightLabel;
        }else if(i == 4){
            self.userLabel = rightLabel;
        }else if(i == 5){
            leftLabel.width = 110;
            rightLabel.x = leftLabel.right;
            self.countLabel = rightLabel;
        }else if(i == 6){
            leftLabel.width = 145;
            rightLabel.left = leftLabel.right;
            self.finishLabel = rightLabel;
        }
        else if(i == _leftArr.count - 1){
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
        }
        [_purchaseView addSubview:rightLabel];
    }
}
- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
    self.noteLabel.height = height;
    
    CGFloat totalHeight = height + LeftHeight *_leftArr.count;
    _purchaseView.height = totalHeight;
    
    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);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#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";
        NoticeDetailCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        
        if (Cell == nil) {
            Cell = [[NoticeDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            Cell.isButtonhidden=YES;
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            Cell.selectionStyle = UITableViewCellSelectionStyleNone;

        }
        [self  showShopDetail:Cell indexPath:indexPath];
        if ([self comperIndexpath:indexPath]) {
            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])
    {
        NoticeDetailCell *Cell=(NoticeDetailCell*)[mingXiTableView cellForRowAtIndexPath:indexPath ];
        if (![self comperIndexpath:indexPath]) {
            Cell.isSelected=YES;
            Cell.subSview.hidden = NO;
            [selectCellAry addObject:indexPath];
        }else{
            Cell.isSelected=NO;
            Cell.subSview.hidden = YES;
            [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];
}
-(void)showShopDetail:(NoticeDetailCell*)Cell indexPath:(NSIndexPath *)indexPath
{
    NoticeProduct *noticeProduct=[_shopeArr objectAtIndex:indexPath.row];
    Cell.SpLabel.text=noticeProduct.productName;//商品
    Cell.shopeName.text=[NSString stringWithFormat:@"%@[%@]",noticeProduct.productName,noticeProduct.productCode];
    Cell.BzggLabel.text= [NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
    Cell.packageUnit.text=noticeProduct.packUnit;//包装单位
    Cell.BzslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
    Cell.packageQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];
    Cell.packageSpecification.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
    Cell.foundationQuantity.text= [NSString stringWithFormat:@"%@%@",noticeProduct.quantity,noticeProduct.baseUnit];//基础数量

    
    Cell.BzggLabel.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
    Cell.BzslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
    Cell.packageSpecification.text=[NSString stringWithFormat:@"1*%@%@",noticeProduct.qpc,noticeProduct.baseUnit];//包装规格
     Cell.YcgslLabel.text=[noticeProduct.purchasedQuantity stringValue];//已采购数量
    Cell.packageUnit.text=noticeProduct.packUnit;//包装单位
    Cell.packageQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.qpcQuantity,noticeProduct.packUnit];//包装数量
    Cell.YcgslLabel.text=[NSString stringWithFormat:@"%@%@",noticeProduct.purchasedQuantity,noticeProduct.packUnit];//已采购数量
    Cell.foundationQuantity.text=[NSString stringWithFormat:@"%@%@",noticeProduct.quantity,noticeProduct.baseUnit];//基础数量
    Cell.remark.text= [NSString stringWithFormat:@"%@",noticeProduct.remark?noticeProduct.remark:@"无"];//备注
    if (!noticeProduct.purchasedQuantity) {
        Cell.YcgslLabel.text= [NSString stringWithFormat:@"0%@",noticeProduct.packUnit];//已采购数量
    }
}
//编辑
- (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];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [self dealByAction:@"end"];//结束
    }
}


/*
#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
