PaymentsViewController.m 3.83 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"


14
@interface PaymentsViewController ()<UITableViewDelegate,UITableViewDataSource>
曹云霄's avatar
曹云霄 committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

/**
 *  上传参数
 */
@property (nonatomic,strong) RsCommissionRequest *model;

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

@end

@implementation PaymentsViewController


#pragma mark - lazy
- (RsCommissionRequest *)model
{
    if (!_model) {
        _model = [[RsCommissionRequest alloc]init];
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _model.page = page;
        _model.emploreeId = [Shoppersmanager manager].shoppers.employee.fid;
    }
    return _model;
}

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


54 55
#pragma mark -获取数据
- (void)loadWebDataSource
曹云霄's avatar
曹云霄 committed
56 57
{
    WS(weakSelf);
58 59 60 61 62 63 64 65 66
    if (self.pullPageIndex == ONE) {
        [self.resultArray removeAllObjects];
    }
    self.model.page.page = self.pullPageIndex;
    [self getDatasActionCompleted:^(RsCommissionResponse *result) {
        if (weakSelf.pullPageIndex >= result.totalpages) {
            [weakSelf endRefresh:EndRefreshNotData];
        }else {
            [weakSelf endRefresh:EndRefreshDefault];
曹云霄's avatar
曹云霄 committed
67 68 69 70
        }
    }];
}

71

曹云霄's avatar
曹云霄 committed
72
#pragma mark - 获取收支明细
73
- (void)getDatasActionCompleted:(void(^)(RsCommissionResponse *result))completed
曹云霄's avatar
曹云霄 committed
74 75 76 77 78
{
    WS(weakSelf);
    [HTTP networkRequestWithURL:SERVERREQUESTURL(PAYMENTS)  withRequestType:ZERO withParameter:self.model withReturnValueBlock:^(id returnValue) {
        if (RESULT(returnValue)) {
            RsCommissionResponse *result = [[RsCommissionResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
79
            completed(result);
曹云霄's avatar
曹云霄 committed
80 81 82
            for (ApplyHist *entity in result.list) {
                [weakSelf.resultArray addObject:entity];
            }
83
            [weakSelf.tableView reloadData];
曹云霄's avatar
曹云霄 committed
84 85 86 87 88 89
        }else
        {
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
        
    }withFailureBlock:^(NSError *error) {
90
        [weakSelf endRefresh:EndRefreshDefault];
曹云霄's avatar
曹云霄 committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PaymentsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PaymentsTableViewCell" forIndexPath:indexPath];
    ApplyHist *entity = self.resultArray[indexPath.row];
    cell.createTimeLabel.text = entity.createDate;
    cell.moneyTypeLabel.text = [[self class] separatePaymentsAndWithfrawal:entity.amount withType:entity.type];
    NSString *string = ([entity.amount floatValue] > 0)?[NSString stringWithFormat:@"+%.2f",[entity.amount floatValue]]:[NSString stringWithFormat:@"%.2f",[entity.amount floatValue]];
    cell.amountLabel.text = string;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.resultArray.count;
}

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
120
    PaymentsDetailsTableViewController *paymentsDetailsVC = [PaymentsDetailsTableViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
曹云霄's avatar
曹云霄 committed
121
    paymentsDetailsVC.model = self.resultArray[indexPath.row];
122
    [self pushViewController:paymentsDetailsVC animated:YES];
曹云霄's avatar
曹云霄 committed
123 124 125
}

@end