WithdrawalViewController.m 6.2 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10
//
//  WithdrawalViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/8/26.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "WithdrawalViewController.h"
#import "WithdrawalTableViewCell.h"
曹云霄's avatar
曹云霄 committed
11
#import "WithdrawalTableViewController.h"
曹云霄's avatar
曹云霄 committed
12

曹云霄's avatar
曹云霄 committed
13
@interface WithdrawalViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
曹云霄's avatar
曹云霄 committed
14 15 16

@property (weak, nonatomic) IBOutlet UITableView *withdrawalTableView;

曹云霄's avatar
曹云霄 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 *  上传参数
 */
@property (nonatomic,strong) RsApplyBillRequest *model;

/**
 *  数据源
 */
@property (nonatomic,strong) NSMutableArray *resultArray;

/**
 *  总页数
 */
@property (nonatomic,assign) NSInteger totalPage;
曹云霄's avatar
曹云霄 committed
31 32 33 34 35

@end

@implementation WithdrawalViewController

曹云霄's avatar
曹云霄 committed
36 37 38 39 40 41
#pragma mark - lazy
- (RsApplyBillRequest *)model
{
    if (!_model) {
        _model = [[RsApplyBillRequest alloc]init];
        DataPage *page = [[DataPage alloc]init];
42
        page.page = ONE;
曹云霄's avatar
曹云霄 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        page.rows = KROWS;
        _model.page = page;
        _model.employeeId = [Shoppersmanager manager].Shoppers.employee.fid;
    }
    return _model;
}

- (NSMutableArray *)resultArray
{
    if (!_resultArray) {
        _resultArray = [NSMutableArray array];
    }
    return _resultArray;
}

曹云霄's avatar
曹云霄 committed
58 59 60
- (void)viewDidLoad {
    [super viewDidLoad];
    
61
    self.withdrawalTableView.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
62
    [self setupRefreshing];
曹云霄's avatar
曹云霄 committed
63 64
}

曹云霄's avatar
曹云霄 committed
65
- (void)viewDidAppear:(BOOL)animated
曹云霄's avatar
曹云霄 committed
66
{
曹云霄's avatar
曹云霄 committed
67
    [super viewDidAppear:animated];
曹云霄's avatar
曹云霄 committed
68
    [self.withdrawalTableView.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
69 70
}

曹云霄's avatar
曹云霄 committed
71 72
#pragma mark - 设置刷新
- (void)setupRefreshing
曹云霄's avatar
曹云霄 committed
73
{
曹云霄's avatar
曹云霄 committed
74 75
    WS(weakSelf);
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
76
        weakSelf.model.page.page = ONE;
曹云霄's avatar
曹云霄 committed
77 78 79 80 81 82
        [weakSelf.withdrawalTableView.mj_footer resetNoMoreData];
        [weakSelf getDatasAction:YES];
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.withdrawalTableView.mj_header = headerRefresh;
曹云霄's avatar
曹云霄 committed
83
    
曹云霄's avatar
曹云霄 committed
84
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
曹云霄's avatar
曹云霄 committed
85 86 87 88 89 90 91
        if (++ weakSelf.model.page.page >= weakSelf.totalPage) {
            [weakSelf.withdrawalTableView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
            [weakSelf getDatasAction:NO];
        }
    }];
曹云霄's avatar
曹云霄 committed
92 93
    footer.automaticallyHidden = YES;
    self.withdrawalTableView.mj_footer = footer;
曹云霄's avatar
曹云霄 committed
94 95
}

曹云霄's avatar
曹云霄 committed
96
#pragma mark - 获取提现进度
曹云霄's avatar
曹云霄 committed
97 98 99 100
- (void)getDatasAction:(BOOL)isRemoveAll
{
    WS(weakSelf);
    [self CreateMBProgressHUDLoding];
101
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(WITHDRAWALPROGRESS) WithCallClass:weakSelf WithRequestType:0 WithParameter:self.model WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
102 103 104
        
        weakSelf.withdrawalTableView.emptyDataSetSource = self;
        weakSelf.withdrawalTableView.emptyDataSetDelegate = self;
曹云霄's avatar
曹云霄 committed
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
        [weakSelf endRefreshingForTableView:weakSelf.withdrawalTableView];
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            if (isRemoveAll) {
                [weakSelf.resultArray removeAllObjects];
            }
            RsApplyBillResponse *result = [[RsApplyBillResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            weakSelf.totalPage = result.totalpages;
            for (TOApplyBillEntity *entity in result.list) {
                [weakSelf.resultArray addObject:entity];
            }
            [weakSelf.withdrawalTableView reloadData];
        }else
        {
            [weakSelf SHOWPrompttext:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [weakSelf endRefreshingForTableView:weakSelf.withdrawalTableView];
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf SHOWPrompttext:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        [weakSelf endRefreshingForTableView:weakSelf.withdrawalTableView];
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf SHOWPrompttext:error.localizedDescription];
    }];
曹云霄's avatar
曹云霄 committed
131 132 133 134 135 136
}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WithdrawalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WithdrawalTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
137
    TOApplyBillEntity *entity = self.resultArray[indexPath.row];
曹云霄's avatar
曹云霄 committed
138
    cell.amountLabel.text = [NSString stringWithFormat:@"%.2f",[entity.applyMoney floatValue]];
曹云霄's avatar
曹云霄 committed
139 140 141
    cell.createTimeLabel.text = entity.createDate;
    cell.progressLabel.textColor = [self setupLabelColor:entity.billStates];
    cell.progressLabel.text = entity.billStates;
曹云霄's avatar
曹云霄 committed
142 143 144 145 146
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
曹云霄's avatar
曹云霄 committed
147
    return self.resultArray.count;
曹云霄's avatar
曹云霄 committed
148 149 150 151 152 153 154 155 156 157
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
曹云霄's avatar
曹云霄 committed
158
    WithdrawalTableViewController *paymentsDetailsVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"WithdrawalTableViewController"];
曹云霄's avatar
曹云霄 committed
159 160
    paymentsDetailsVC.model = self.resultArray[indexPath.row];
    [self.navigationController pushViewController:paymentsDetailsVC animated:YES];
曹云霄's avatar
曹云霄 committed
161 162
}

曹云霄's avatar
曹云霄 committed
163 164 165 166 167 168 169 170 171 172 173 174
#pragma mark - 设置字体颜色
- (UIColor *)setupLabelColor:(NSString *)text
{
    if ([text isEqualToString:@"到账成功"]) {
        return RGB(89, 172, 220, 1);
    }
    if ([text isEqualToString:@"申请已提交"]) {
        return RGB(128, 189, 51, 1);
    }
    return nil;
}

曹云霄's avatar
曹云霄 committed
175 176 177 178 179
#pragma mark - 释放
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
曹云霄's avatar
曹云霄 committed
180 181


曹云霄's avatar
曹云霄 committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
曹云霄's avatar
曹云霄 committed
197

198 199 200 201
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    return 64;
}
曹云霄's avatar
曹云霄 committed
202

曹云霄's avatar
曹云霄 committed
203 204 205


@end