|
|
@@ -11,13 +11,13 @@
|
|
|
#import "ExchangeHistoryViewController.h"
|
|
|
#import "StoreItemCell.h"
|
|
|
#import "StoreHeaderView.h"
|
|
|
-#import "ExchangeHistoryViewController.h"
|
|
|
#import "PlaceOrderViewController.h"
|
|
|
#import "ItemDetailViewController.h"
|
|
|
|
|
|
@interface StoreViewController () <UITableViewDelegate, UITableViewDataSource>
|
|
|
@property(weak, nonatomic) IBOutlet UITableView *tableView;
|
|
|
-
|
|
|
+@property(nonatomic, strong) StoreHeaderView *headerView;
|
|
|
+@property(nonatomic, strong) NSMutableArray *tableData;
|
|
|
@end
|
|
|
|
|
|
@implementation StoreViewController
|
|
|
@@ -29,17 +29,20 @@
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
|
|
|
self.title = @"积分商城";
|
|
|
|
|
|
- StoreHeaderView *headerView = [[StoreHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 145)];
|
|
|
- headerView.onTapHistory = ^{
|
|
|
+ self.headerView = [[StoreHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 145)];
|
|
|
+ self.headerView.onTapHistory = ^{
|
|
|
+ AppDelegate *delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
|
|
|
+ if (![delegate isLogin]) {
|
|
|
+ [delegate showLoginAlert];
|
|
|
+ return;
|
|
|
+ }
|
|
|
ExchangeHistoryViewController *vc = [[ExchangeHistoryViewController alloc] init];
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
};
|
|
|
- self.tableView.tableHeaderView = headerView;
|
|
|
+ self.tableView.tableHeaderView = self.headerView;
|
|
|
self.tableView.delegate = self;
|
|
|
self.tableView.dataSource = self;
|
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- (void)backClick {
|
|
|
@@ -55,6 +58,8 @@
|
|
|
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
|
|
|
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
|
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
|
|
|
+ self.navigationController.navigationBar.translucent = NO;
|
|
|
+ [self getInfo];
|
|
|
}
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
@@ -65,6 +70,46 @@
|
|
|
self.navigationController.navigationBar.titleTextAttributes = nil;
|
|
|
}
|
|
|
|
|
|
+- (NSMutableArray *)tableData {
|
|
|
+ if (!_tableData) {
|
|
|
+ _tableData = [NSMutableArray arrayWithCapacity:0];
|
|
|
+ }
|
|
|
+ return _tableData;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)getInfo {
|
|
|
+ [[AHHttpManager sharedManager]
|
|
|
+ POST:[NSString stringWithFormat:@"%@integral?action=getAllMerchandises", webURL]
|
|
|
+ parameters:nil
|
|
|
+ success:^(id responseObject) {
|
|
|
+ if ([responseObject[@"success"] boolValue]) {
|
|
|
+ [self.tableData removeAllObjects];
|
|
|
+ [self.tableData addObjectsFromArray:responseObject[@"data"]];
|
|
|
+ [self.tableView reloadData];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ failure:^(NSError *error) {
|
|
|
+ NSLog(@"error = %@", error);
|
|
|
+ }];
|
|
|
+ AppDelegate *delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
|
|
|
+ if (![delegate isLogin]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSString *str = [NSString stringWithFormat:@"%@memberInfo?action=getuserinfo&PK=%@", webURL, [Helper sharedAccount].accid];
|
|
|
+ [[AHHttpManager sharedManager]
|
|
|
+ POST:str
|
|
|
+ parameters:nil
|
|
|
+ success:^(id responseObject) {
|
|
|
+ NSLog(@"%@", responseObject);
|
|
|
+ if ([[responseObject objectForKey:@"msg"] isEqualToString:@"success"]) {
|
|
|
+ self.headerView.integralLabel.text = responseObject[@"data"][@"integral"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ failure:^(NSError *error) {
|
|
|
+ NSLog(@"error = %@", error);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
|
|
return UIStatusBarStyleLightContent;
|
|
|
}
|
|
|
@@ -74,7 +119,7 @@
|
|
|
}
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
- return 10;
|
|
|
+ return self.tableData.count;
|
|
|
}
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
@@ -87,15 +132,23 @@
|
|
|
cell = [[[UINib nibWithNibName:@"StoreItemCell" bundle:nil] instantiateWithOwner:self options:nil] lastObject];
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
cell.onExchange = ^(NSDictionary *model) {
|
|
|
+ AppDelegate *delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
|
|
|
+ if (![delegate isLogin]) {
|
|
|
+ [delegate showLoginAlert];
|
|
|
+ return;
|
|
|
+ }
|
|
|
PlaceOrderViewController *vc = [[PlaceOrderViewController alloc] init];
|
|
|
+ vc.model = self.tableData[indexPath.row];
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
};
|
|
|
}
|
|
|
+ cell.model = self.tableData[indexPath.row];
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
ItemDetailViewController *vc = [[ItemDetailViewController alloc] init];
|
|
|
+ vc.model = self.tableData[indexPath.row];
|
|
|
[self.navigationController presentViewController:vc animated:YES completion:nil];
|
|
|
}
|
|
|
|