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

#import "PaymentsViewController.h"
#import "PaymentsTableViewCell.h"
#import "PaymentsDetailsTableViewController.h"


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

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

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

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

@end

@implementation PaymentsViewController

曹云霄's avatar
曹云霄 committed
36 37 38 39 40 41 42

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

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

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

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

曹云霄's avatar
曹云霄 committed
72 73
#pragma mark - 设置刷新
- (void)setupRefreshing
曹云霄's avatar
曹云霄 committed
74
{
曹云霄's avatar
曹云霄 committed
75 76
    WS(weakSelf);
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
77
        weakSelf.model.page.page = ONE;
曹云霄's avatar
曹云霄 committed
78 79 80 81 82 83
        [weakSelf.paymentsTableView.mj_footer resetNoMoreData];
        [weakSelf getDatasAction:YES];
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.paymentsTableView.mj_header = headerRefresh;
曹云霄'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.paymentsTableView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
            [weakSelf getDatasAction:NO];
        }
    }];
曹云霄's avatar
曹云霄 committed
92 93
    footer.automaticallyHidden = YES;
    self.paymentsTableView.mj_footer = footer;
曹云霄's avatar
曹云霄 committed
94 95 96 97 98 99
}

#pragma mark - 获取收支明细
- (void)getDatasAction:(BOOL)isRemoveAll
{
    WS(weakSelf);
100
    [XBLoadingView showHUDViewWithDefaultWithView:self.view];
101
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(PAYMENTS)  WithRequestType:ZERO WithParameter:self.model WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
102
        
103 104
        weakSelf.paymentsTableView.emptyDataSetSource = weakSelf;
        weakSelf.paymentsTableView.emptyDataSetDelegate = weakSelf;
曹云霄's avatar
曹云霄 committed
105
        [weakSelf endRefreshingForTableView:weakSelf.paymentsTableView];
106
        [XBLoadingView hideHUDViewWithDefaultWithView:weakSelf.view];
曹云霄's avatar
曹云霄 committed
107 108 109 110 111 112 113 114 115 116 117 118
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            if (isRemoveAll) {
                [weakSelf.resultArray removeAllObjects];
            }
            RsCommissionResponse *result = [[RsCommissionResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            weakSelf.totalPage = result.totalpages;
            for (TOCommissionHistEntity *entity in result.list) {
                [weakSelf.resultArray addObject:entity];
            }
            [weakSelf.paymentsTableView reloadData];
        }else
        {
曹云霄's avatar
曹云霄 committed
119
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
120 121
        }
        
122
    }WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
123
        [weakSelf endRefreshingForTableView:weakSelf.paymentsTableView];
124
        [XBLoadingView hideHUDViewWithDefaultWithView:weakSelf.view];
曹云霄's avatar
曹云霄 committed
125
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
126
    }];
曹云霄's avatar
曹云霄 committed
127 128 129 130 131 132
}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PaymentsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PaymentsTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
133 134 135 136 137
    TOCommissionHistEntity *entity = self.resultArray[indexPath.row];
    cell.createTimeLabel.text = entity.createDate;
    cell.moneyTypeLabel.text = [self separatePaymentsAndWithfrawal:entity.state];
    NSString *string = ([entity.amount floatValue] > 0)?[NSString stringWithFormat:@"+%.2f",[entity.amount floatValue]]:[NSString stringWithFormat:@"%.2f",[entity.amount floatValue]];
    cell.amountLabel.text = string;
曹云霄's avatar
曹云霄 committed
138 139 140 141 142
    return cell;
}

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

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

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

曹云霄's avatar
曹云霄 committed
159 160 161 162 163 164 165 166 167 168 169
#pragma mark - 区分提现还是返佣
- (NSString *)separatePaymentsAndWithfrawal:(NSString *)state
{
    if ([state isEqualToString:@"0"]) {
        return @"返佣";
    }
    if ([state isEqualToString:@"1"]) {
        return @"提现";
    }
    return nil;
}
曹云霄's avatar
曹云霄 committed
170

曹云霄's avatar
曹云霄 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
#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
186

187 188 189 190 191
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    return 64;
}

曹云霄's avatar
曹云霄 committed
192 193

@end