ChooseWarehouseViewController.m 6.28 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4
//
//  ChooseStoreViewController.m
//  XFFruit
//
n22's avatar
n22 committed
5
//  Created by 陈俊俊 on 15/8/26.
n22's avatar
n22 committed
6 7 8 9 10 11
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "ChooseWarehouseViewController.h"
#define TopMargin 50
#define TableHeight 50
陈俊俊's avatar
陈俊俊 committed
12
@interface ChooseWarehouseViewController ()
陈俊俊's avatar
陈俊俊 committed
13

n22's avatar
n22 committed
14 15 16 17 18 19
@end

@implementation ChooseWarehouseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
20 21
    self.currentPage = 0;
    self.tableStr = GXF_BASECLASS_WAREHOUSE;
陈俊俊's avatar
陈俊俊 committed
22 23 24
    //记录更新时间
    self.tableView.header.lastUpdatedTimeKey = ChooseWarehouseUpdateDate;
    self.title = @"选择仓库";
25
    [self fetchDataList:@"" tableStr:GXF_BASECLASS_UserWAREHOUSE];
n22's avatar
n22 committed
26
}
陈俊俊's avatar
陈俊俊 committed
27

陈俊俊's avatar
陈俊俊 committed
28
-(void)getBaseDataFromServerWithStartDate:(NSString *)startDate{
n22's avatar
n22 committed
29 30
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
陈俊俊's avatar
陈俊俊 committed
31 32 33 34 35 36
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //请求成功之后
        strongSelf.startDate = startDate;
        [strongSelf getLastDateFromServer:data];
    };
    void(^fail)(id) = ^(id data) {
n22's avatar
n22 committed
37
        [IBTLoadingView hideHUDWithText:nil];
陈俊俊's avatar
陈俊俊 committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51
        [IBTLoadingView showTips:data];
        [self endRefreshing];
    };
    if (self.currentPage == 0) {
        [IBTLoadingView showProgressLabel:@"正在加载..."];
    }
    [[ICRHTTPController sharedController] getWarehouseWithStartDate:startDate  Page_number:self.currentPage page_size:100 success:succ failure:fail];
}
- (void)getLastDateFromServer:(id)data
{
    if (data) {
        NSDictionary *pageDict = data[ @"data" ][ @"paging" ];
        NSInteger pageCount = [pageDict[@"pageCount"] integerValue];
        if (pageCount <= self.currentPage) {
陈俊俊's avatar
陈俊俊 committed
52
            [self endRefreshing];
陈俊俊's avatar
陈俊俊 committed
53
            [IBTLoadingView hideHUDWithText:nil];
54 55 56
//            [self fetchDataList:@"" tableStr:GXF_BASECLASS_WAREHOUSE];
            self.currentPage = 0;
            [self getUserWareHouseFromServer:self.startDate];
n22's avatar
n22 committed
57
        }else{
陈俊俊's avatar
陈俊俊 committed
58 59
            self.currentPage++;
            [self getBaseDataFromServerWithStartDate:self.startDate];
n22's avatar
n22 committed
60
        }
陈俊俊's avatar
陈俊俊 committed
61
    }else{
n22's avatar
n22 committed
62 63
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
陈俊俊's avatar
陈俊俊 committed
64
    }
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
}

- (void)getUserWareHouseFromServer:(NSString *)startDate{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //请求成功之后
        strongSelf.startDate = startDate;
        [strongSelf getLastUWDataFromServer:data];
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
        [self endRefreshing];
    };
    [[ICRHTTPController sharedController] downloadUserWarehouseWithStartDate:startDate  Page_number:self.currentPage page_size:100 success:succ failure:fail];
}

- (void)getLastUWDataFromServer:(id)data
{
    if (data) {
        NSDictionary *pageDict = data[ @"data" ][ @"paging" ];
        NSInteger pageCount = [pageDict[@"pageCount"] integerValue];
        if (pageCount <= self.currentPage) {
            [self endRefreshing];
            [IBTLoadingView hideHUDWithText:nil];
            [self fetchDataList:@"" tableStr:GXF_BASECLASS_UserWAREHOUSE];
        }else{
            self.currentPage++;
            [self getUserWareHouseFromServer:self.startDate];
        }
    }else{
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    }
n22's avatar
n22 committed
100 101 102 103 104 105 106 107 108 109 110 111
}
#pragma mark - 协议方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"MaskCell";
    MaskCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID totalWidth:ScreenSize.width totalHeight:TableHeight];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.Commitbtn.hidden = YES;
    }
    
陈俊俊's avatar
陈俊俊 committed
112 113
    if (self.currentIndexPath) {
        if (indexPath.row == self.currentIndexPath.row) {
n22's avatar
n22 committed
114
            cell.Commitbtn.hidden = NO;
陈俊俊's avatar
陈俊俊 committed
115 116
            cell.titleLabel.textColor = BASESELECT_COLOR;

n22's avatar
n22 committed
117 118
        }else{
            cell.Commitbtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
119 120
            cell.titleLabel.textColor = [UIColor blackColor];

n22's avatar
n22 committed
121 122 123
        }
    }else{
        cell.Commitbtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
124 125
        cell.titleLabel.textColor = [UIColor blackColor];

n22's avatar
n22 committed
126 127
    }
    if (self.dataArr.count > 0) {
陈俊俊's avatar
陈俊俊 committed
128 129 130 131 132 133 134 135 136 137
        if (indexPath.row == 0) {
            NSString *dateStr = [self.dataArr[indexPath.row] httpParameterString];
            cell.titleLabel.textColor = GXF_CONTENT_COLOR;
            [cell setTitleStr:[NSString stringWithFormat:@"上次更新时间:%@",dateStr]];
        }else{
            Warehouse *warehouse = self.dataArr[indexPath.row];
            NSString *proStr = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
            
            [cell setTitleStr:proStr];
        }
n22's avatar
n22 committed
138 139 140 141
    }
    return cell;
}

陈俊俊's avatar
陈俊俊 committed
142 143
- (void)boxValueChanged:(NSNotification *)fication{
    NSString *tilkeStr = [IBTCommon trimmingCharacters:self.selectTextFiled.text];
陈俊俊's avatar
陈俊俊 committed
144
    [self fetchDataList:tilkeStr tableStr:GXF_BASECLASS_WAREHOUSE];
n22's avatar
n22 committed
145
}
陈俊俊's avatar
陈俊俊 committed
146

陈俊俊's avatar
陈俊俊 committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
- (void)tableViewRefresh:(NSString *)titltstr{
    if (titltstr.length > 0) {
        [super tableViewRefresh:titltstr];
    }else{
        if (self.selectStr.length>0) {
            if (!self.isMoreChose) {
                for (NSInteger i = 1;i< self.dataArr.count; i++) {
                    Warehouse *type = self.dataArr[i];
                    if ([type.uuid isEqualToString:self.selectStr]) {
                        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
                        self.currentIndexPath = indexPath;
                        break;
                    }
                }
                [self.tableView reloadData];
            }
        }else{
            [super tableViewRefresh:titltstr];
        }
    }
}
n22's avatar
n22 committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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