WithdrawalViewController.m 5.46 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
        if (++ weakSelf.model.page.page > weakSelf.totalPage) {
曹云霄's avatar
曹云霄 committed
86 87 88 89 90 91
            [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
- (void)getDatasAction:(BOOL)isRemoveAll
{
    WS(weakSelf);
100
    [XBLoadingView showHUDViewWithDefaultWithView:self.view];
曹云霄's avatar
曹云霄 committed
101
    [HTTP networkRequestWithURL:SERVERREQUESTURL(WITHDRAWALPROGRESS)  withRequestType:ZERO withParameter:self.model withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
102
        
103 104
        weakSelf.withdrawalTableView.emptyDataSetSource = weakSelf;
        weakSelf.withdrawalTableView.emptyDataSetDelegate = weakSelf;
曹云霄's avatar
曹云霄 committed
105
        [weakSelf endRefreshingForTableView:weakSelf.withdrawalTableView];
106
        [XBLoadingView hideHUDViewWithDefaultWithView:weakSelf.view];
曹云霄's avatar
曹云霄 committed
107
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
108 109 110
            if (isRemoveAll) {
                [weakSelf.resultArray removeAllObjects];
            }
曹云霄's avatar
曹云霄 committed
111
            RsApplyBillResponse *result = [[RsApplyBillResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
曹云霄's avatar
曹云霄 committed
112 113 114 115 116 117 118
            weakSelf.totalPage = result.totalpages;
            for (TOApplyBillEntity *entity in result.list) {
                [weakSelf.resultArray addObject:entity];
            }
            [weakSelf.withdrawalTableView reloadData];
        }else
        {
曹云霄's avatar
曹云霄 committed
119
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
120
        }
121
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
122
        [weakSelf endRefreshingForTableView:weakSelf.withdrawalTableView];
123
        [XBLoadingView hideHUDViewWithDefaultWithView:weakSelf.view];
曹云霄's avatar
曹云霄 committed
124
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
125
    }];
曹云霄's avatar
曹云霄 committed
126 127 128 129 130 131
}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WithdrawalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WithdrawalTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
132
    TOApplyBillEntity *entity = self.resultArray[indexPath.row];
133
    cell.entity = entity;
曹云霄's avatar
曹云霄 committed
134 135 136 137 138
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
曹云霄's avatar
曹云霄 committed
139
    return self.resultArray.count;
曹云霄's avatar
曹云霄 committed
140 141 142 143 144 145 146 147 148 149
}

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

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

曹云霄's avatar
曹云霄 committed
155 156 157
#pragma mark - 释放
- (void)dealloc
{
158
    [Notification removeObserver:self];
曹云霄's avatar
曹云霄 committed
159
}
曹云霄's avatar
曹云霄 committed
160 161


曹云霄's avatar
曹云霄 committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
#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
177

178 179 180 181
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    return 64;
}
曹云霄's avatar
曹云霄 committed
182

曹云霄's avatar
曹云霄 committed
183 184 185


@end