|
|
@@ -18,11 +18,20 @@
|
|
|
@property (nonatomic,strong) NSArray <RAHomeOrderModel *> *orders;
|
|
|
@property (nonatomic,copy) NSString *title;
|
|
|
@property (nonatomic,readonly) NSInteger ordersCount;
|
|
|
+@property (nonatomic,assign) BOOL expand;
|
|
|
+@property (nonatomic,assign) NSInteger section;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation RAHomeSectionModel
|
|
|
|
|
|
+- (instancetype)init {
|
|
|
+ if (self = [super init]) {
|
|
|
+ self.expand = YES;
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
- (void)setOrders:(NSArray *)orders {
|
|
|
|
|
|
NSMutableArray *orderArr = [NSMutableArray array];
|
|
|
@@ -40,6 +49,9 @@
|
|
|
}
|
|
|
|
|
|
- (NSInteger)ordersCount {
|
|
|
+ if (!self.expand) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
return self.orders.count;
|
|
|
}
|
|
|
|
|
|
@@ -118,8 +130,17 @@
|
|
|
}
|
|
|
|
|
|
- (void)configureNavigationBar {
|
|
|
- UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithTitle:@"Upload List" style:UIBarButtonItemStylePlain target:self action:@selector(uploadListItemClick:)];
|
|
|
- self.navigationItem.rightBarButtonItem = uploadListItem;
|
|
|
+ UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"list"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
|
|
|
+ style:UIBarButtonItemStylePlain
|
|
|
+ target:self
|
|
|
+ action:@selector(uploadListItemClick:)];
|
|
|
+
|
|
|
+ UIBarButtonItem *logoutItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"logout"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
|
|
|
+ style:UIBarButtonItemStylePlain
|
|
|
+ target:self
|
|
|
+ action:@selector(logoutItemClick:)];
|
|
|
+
|
|
|
+ self.navigationItem.rightBarButtonItems = @[logoutItem,uploadListItem];
|
|
|
}
|
|
|
|
|
|
- (void)registNotification {
|
|
|
@@ -135,6 +156,10 @@
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
}
|
|
|
|
|
|
+- (void)logoutItemClick:(UIBarButtonItem *)sender {
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationLogout object:nil];
|
|
|
+}
|
|
|
+
|
|
|
- (void)refreshControlValueChanged:(UIRefreshControl *)refresh {
|
|
|
[self loadData];
|
|
|
}
|
|
|
@@ -168,6 +193,11 @@
|
|
|
return sectionModel.title;
|
|
|
}
|
|
|
|
|
|
+- (BOOL)isExpandAtSection:(NSInteger)section {
|
|
|
+ RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
|
|
|
+ return sectionModel.expand;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Data
|
|
|
|
|
|
- (void)loadData {
|
|
|
@@ -197,21 +227,24 @@
|
|
|
|
|
|
NSArray *sectionArray = [json objectForKey:@"sections"];
|
|
|
[strongSelf.sectionArray removeAllObjects];
|
|
|
+ strongSelf.currentIndexPath = nil;
|
|
|
+
|
|
|
for (int i = 0; i < sectionArray.count; i++) {
|
|
|
NSDictionary *section = [sectionArray objectAtIndex:i];
|
|
|
RAHomeSectionModel *sectionModel = [RAHomeSectionModel new];
|
|
|
+ sectionModel.section = i;
|
|
|
[sectionModel setValuesForKeysWithDictionary:section];
|
|
|
[strongSelf.sectionArray addObject:sectionModel];
|
|
|
- if (self.currentOrderID.length > 0) {
|
|
|
+ if (strongSelf.currentOrderID.length > 0) {
|
|
|
NSInteger idx = [sectionModel orderModelIndexForID:self.currentOrderID];
|
|
|
if (idx > -1) {
|
|
|
- self.currentIndexPath = [NSIndexPath indexPathForRow:idx inSection:i];
|
|
|
+ strongSelf.currentIndexPath = [NSIndexPath indexPathForRow:idx inSection:i];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[strongSelf.homeOrderTableView reloadData];
|
|
|
- if (self.currentIndexPath) {
|
|
|
+ if (strongSelf.currentIndexPath) {
|
|
|
// [strongSelf.homeOrderTableView scrollToRowAtIndexPath:self.currentIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
|
|
|
[strongSelf.homeOrderTableView selectRowAtIndexPath:self.currentIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
|
|
|
} else {
|
|
|
@@ -238,6 +271,13 @@
|
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
|
}
|
|
|
|
|
|
+- (void)setExpand:(BOOL)expand forSection:(NSInteger)section {
|
|
|
+ RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
|
|
|
+ sectionModel.expand = expand;
|
|
|
+
|
|
|
+ [self.homeOrderTableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Nofitication Selector
|
|
|
|
|
|
- (void)receiveNewOrderNotification:(NSNotification *)notification {
|