123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- //
- // FKCircleProductController.m
- // FirstLink
- //
- // Created by ascii on 16/6/14.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCircleProductController.h"
- #import "FKCircleProductCell.h"
- #import "FKCircleProductRequest.h"
- #import "FKCircleProductReform.h"
- #import "FKCircleChoiceProductItem.h"
- @interface FKCircleProductController ()
- <UITableViewDelegate, UITableViewDataSource, FLNetworkDelegate>
- @property (nonatomic, assign) FKCircleProductType productType;
- @property (nonatomic, weak ) FKCircleProductViewModel *viewModel;
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation FKCircleProductController
- - (instancetype)initWithType:(FKCircleProductType)productType viewModel:(FKCircleProductViewModel *)viewModel {
- self = [super init];
- if (self) {
- _productType = productType;
- _viewModel = viewModel;
-
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.equalTo(self.view);
- }];
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self requestProductData:FKCircleProductRequestNew startRow:0];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Request
- - (void)requestProductData:(int)identify startRow:(NSInteger)startRow {
- [self.hudView show:YES];
- [FKCircleProductRequest requestItems:identify
- startRow:[NSString stringWithFormat:@"%ld", (long)startRow]
- pageSize:[NSString stringWithFormat:@"%d", PAGE_RECORD_COUNT]
- productType:self.productType
- deleagate:self];
- }
- - (void)refreshControl:(FKRefreshControl *)refreshControl didEngageRefreshDirection:(RefreshDirection)direction {
- // [self.hudView show:YES];
- if (direction==RefreshDirectionTop) {
- [self requestProductData:FKCircleProductRequestNew startRow:0];
- } else if (direction==RefreshDirectionBottom) {
- [self requestProductData:FKCircleProductRequestNextPage startRow:[self.viewModel countOfItems:self.productType]];
- }
- }
- #pragma mark - Response
- - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
- [self finishLoadingData];
- [self.hudView hide:YES];
-
- if ([header.code intValue] == RESPONSE_MSG_NORMAL) {
- NSArray *items = [FKCircleProductReform parseItems:response];
- if (identify == FKCircleProductRequestNew) {
- [self.viewModel removeAllObjects:self.productType];
- [self.viewModel saveItems:items productType:self.productType];
- } else if (identify == FKCircleProductRequestNextPage) {
- [self.viewModel saveItems:items productType:self.productType];
- }
- [self.tableView reloadData];
-
- // 显示无内容提示
- if ([self.viewModel countOfItems:self.productType] == 0) {
- [self showStatusTipInView:self.tableView image:[UIImage imageNamed:@"StatusNoOrderIcon"] title:@"没有内容哦"];
- } else {
- [self.statusView removeFromSuperview];
- }
-
- self.refreshControl.bottomEnabled = items.count > 0 ? YES : NO;
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header {
- [self finishLoadingData];
- [self.hudView hide:YES];
-
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- #pragma mark - UITableViewDelegate, UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return [self.viewModel countOfItems:self.productType];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 105;
- }
- - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- FKCircleProductCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKCircleProductCell class])];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
- id item = [self.viewModel itemAtIndex:indexPath.section productType:self.productType];
- [cell configWithItem:item];
- cell.choiceButton.tag = indexPath.section;
- [cell.choiceButton addTarget:self action:@selector(clickSelectButton:) forControlEvents:UIControlEventTouchUpInside];
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // FKOrderPaymentItem *item = [self.viewModel paymentItemAtIndex:indexPath.section classify:_classify];
- // if (item&& self.delegate && [self.delegate respondsToSelector:@selector(orderController:didClickOrderDetailAction:orderType:)]) {
- // [self.delegate orderController:self didClickOrderDetailAction:item.paymentID orderType:kOrderTypeProduct];
- // }
- }
- #pragma mark - Action
- - (IBAction)clickSelectButton:(UIButton *)sender {
- sender.selected = !sender.selected;
- FKCircleChoiceProductItem *item = [self.viewModel itemAtIndex:sender.tag productType:self.productType];
- if ([item isKindOfClass:[FKCircleChoiceProductItem class]]) {
- item.isSelected = sender.selected;
- }
- }
- #pragma mark - Method
- #pragma mark - Layout
- #pragma mark - Property
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- [self initRefreshControlWithTableView:self.tableView];
-
- [self.tableView registerClass:[FKCircleProductCell class] forCellReuseIdentifier:NSStringFromClass([FKCircleProductCell class])];
-
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- }
- return _tableView;
- }
- @end
|