| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // RAHomeViewController.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/6/1.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RAHomeViewController.h"
- #import "RAHomeOrderModel.h"
- #import "RAOrderDetailViewController.h"
- #import "RAProgressHUD.h"
- @interface RAHomeSectionModel : NSObject
- @property (nonatomic,assign) RAOrderStatus type;
- @property (nonatomic,strong) NSArray <RAHomeOrderModel *> *orders;
- @property (nonatomic,copy) NSString *title;
- @property (nonatomic,readonly) NSInteger ordersCount;
- @end
- @implementation RAHomeSectionModel
- - (void)setOrders:(NSArray *)orders {
-
- NSMutableArray *orderArr = [NSMutableArray array];
- for (int i = 0; i < orders.count; i++) {
- NSDictionary *order = [orders objectAtIndex:i];
- RAHomeOrderModel *orderModel = [RAHomeOrderModel new];
- [orderModel setValuesForKeysWithDictionary:order];
- [orderArr addObject:orderModel];
- }
- _orders = orderArr;
- }
- - (RAHomeOrderModel *)orderModelForIndex:(NSInteger)index {
- return [self.orders objectAtIndex:index];
- }
- - (NSInteger)ordersCount {
- return self.orders.count;
- }
- @end
- @interface RAHomeViewController ()
- @property (nonatomic,strong) NSMutableArray <RAHomeSectionModel *> *sectionArray;
- @end
- @implementation RAHomeViewController
- + (instancetype)viewControllerFromStoryboard {
- RAHomeViewController *homeVC = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
- return homeVC;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self configureTable];
- [self loadData];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)configureTable {
-
- self.homeOrderTableView.tableFooterView = [UIView new];
- self.homeOrderTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
- }
- #pragma mark Getter
- - (NSMutableArray *)sectionArray {
- if (!_sectionArray) {
- _sectionArray = [NSMutableArray array];
- }
- return _sectionArray;
- }
- - (NSUInteger)orderSectionCount {
-
- return self.sectionArray.count;
- }
- - (NSUInteger)orderCountForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return [sectionModel ordersCount];
- }
- - (RAHomeOrderModel *)orderModelForIndexPath:(NSIndexPath *)indexPath {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:indexPath.section];
- return [sectionModel orderModelForIndex:indexPath.row];
- }
- - (NSString *)titleForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return sectionModel.title;
- }
- #pragma mark - Data
- - (void)loadData {
-
- // show progress
- // RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
-
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- NSDictionary *json = [RADataProvider requestOrderList];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- // dismiss progress
-
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- int result = [[json objectForKey:@"result"] intValue];
- if (result == RESULT_TRUE) {
-
- NSArray *sectionArray = [json objectForKey:@"sections"];
- [strongSelf.sectionArray removeAllObjects];
- for (int i = 0; i < sectionArray.count; i++) {
- NSDictionary *section = [sectionArray objectAtIndex:i];
- RAHomeSectionModel *sectionModel = [RAHomeSectionModel new];
- [sectionModel setValuesForKeysWithDictionary:section];
- [strongSelf.sectionArray addObject:sectionModel];
- }
- [strongSelf.homeOrderTableView reloadData];
-
- } else {
- // process error
-
- }
- }
-
- });
-
- });
- }
- #pragma mark - Controller Action
- - (void)pushDetailViewControllerForModel:(RAHomeOrderModel *)model {
-
- RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
- detailVC.orderID = model.orderID;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- @end
|