OrderRecordViewController.m 6.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//
//  OrderRecordViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/10/25.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "OrderRecordViewController.h"
#import "OrderdetailsViewController.h"
#import "OrderTableViewCell.h"

@interface OrderRecordViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

/**
 *  记录总页数
 */
@property (nonatomic,assign) NSInteger totalPage;

/**
 *  订单记录数据
 */
@property (nonatomic,strong) NSMutableArray *orderRecordArray;

/**
 *  请求订单记录
 */
@property (nonatomic,strong) OrderFilter *orderRecordModel;

@end

@implementation OrderRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self GetdatasAciton];
}

#pragma mark -获取数据
- (void)GetdatasAciton
{
    WS(weakSelf);
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //购物袋
        weakSelf.orderRecordModel.dp.page = 1;
        [weakSelf.orderRecordTableView.mj_footer resetNoMoreData];
        [weakSelf getGuideAllcustomerOrder:weakSelf.orderRecordModel isRemove:YES];
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.orderRecordTableView.mj_header = headerRefresh;
    //进入刷新状态
    [self.orderRecordTableView.mj_header beginRefreshing];
    //上拉加载
    self.orderRecordTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [weakSelf.orderRecordTableView.mj_footer resetNoMoreData];
        //购物袋
        if (++ weakSelf.orderRecordModel.dp.page > weakSelf.totalPage) {
            [weakSelf.orderRecordTableView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
            [weakSelf getGuideAllcustomerOrder:weakSelf.orderRecordModel isRemove:NO];
        }
    }];
    self.orderRecordTableView.mj_footer.automaticallyHidden = YES;
    self.orderRecordTableView.tableFooterView = [UIView new];
}


#pragma mark -获取客户订单数据
- (void)getGuideAllcustomerOrder:(OrderFilter *)allOrder isRemove:(BOOL)remove
{
曹云霄's avatar
曹云霄 committed
76
    [XBLoadingView showHUDViewWithDefault];
77
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
78
    [HTTP networkRequestWithURL:SERVERREQUESTURL(QUERYORDER)  withRequestType:ZERO withParameter:allOrder withReturnValueBlock:^(id returnValue) {
79 80 81
        
        weakSelf.orderRecordTableView.emptyDataSetSource = weakSelf;
        weakSelf.orderRecordTableView.emptyDataSetDelegate = weakSelf;
曹云霄's avatar
曹云霄 committed
82
        [XBLoadingView hideHUDViewWithDefault];
83
        [weakSelf endRefreshingForTableView:weakSelf.orderRecordTableView];
曹云霄's avatar
曹云霄 committed
84
        if (RESULT(returnValue)) {
85 86 87
            if (remove) {
                [weakSelf.orderRecordArray removeAllObjects];
            }
曹云霄's avatar
曹云霄 committed
88 89
            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            weakSelf.totalPage = [RESPONSE(returnValue)[@"totalpages"] intValue];
90 91 92 93 94 95
            for (OrderBill *model in Allorder.orderBillList) {
                [weakSelf.orderRecordArray addObject:model];
            }
            [weakSelf.orderRecordTableView reloadData];
        }else
        {
96
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
97
        }
98
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
99
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    }];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ordercell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.orderRecordArray objectAtIndex_opple:indexPath.row];
    return  cell;
}


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


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


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
127
    OrderdetailsViewController *orderdetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
128 129
    TOOrderEntity *model = (TOOrderEntity *)[[self.orderRecordArray objectAtIndex_opple:indexPath.row] order];
    orderdetails.orderCode = model.orderNumber;
130 131
    if ([model.orderState isEqualToString:COMPLETED] || [model.orderState isEqualToString:PAID] || [model.orderState isEqualToString:SHIPPED]) {
        orderdetails.isShowShareButton = YES;
132 133
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
134
        orderdetails.isUserInteractionEnabled = NO;
135
        
136
    } else if ([model.orderState isEqualToString:UNPAID]) {//未付款
137
        orderdetails.isShowPayButton = YES;
138
        orderdetails.isShowShareButton = YES;
139
        orderdetails.isShowHeaderView = YES;
140
        orderdetails.isUserInteractionEnabled = YES;
141 142 143
        
    }else{
        orderdetails.isShowHeaderView = NO;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    }
    //撤销、支付回调
    WS(weakSelf);
    [orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
        OrderBill *model = [weakSelf.orderRecordArray objectAtIndex_opple:cellindex];
        model.order.orderState = orderSate;
        NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
        [weakSelf.orderRecordTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
    }];
    [self.navigationController pushViewController:orderdetails animated:YES];
}

#pragma mark - lazy
- (NSMutableArray *)orderRecordArray
{
    if (_orderRecordArray == nil) {
        
        _orderRecordArray = [NSMutableArray array];
    }
    return _orderRecordArray;
}

- (OrderFilter *)orderRecordModel
{
    if (!_orderRecordModel) {
        _orderRecordModel = [[OrderFilter alloc]init];
        DataPage *Newpage = [[DataPage alloc]init];
        Newpage.page = 1;
        Newpage.rows = KROWS;
        _orderRecordModel.dp = Newpage;
        _orderRecordModel.consumerIdEquals = self.model.fid;
    }
    return _orderRecordModel;
}

#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}

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


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end