123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // FKPriceWarnListController.m
- // FirstLink
- //
- // Created by jack on 16/5/27.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKPriceWarnListController.h"
- #import "FKPriceWarnListCell.h"
- #import "FKPriceWarnListRequest.h"
- #import "FKPriceWarnListReform.h"
- #import "FKPriceWarnListViewModel.h"
- #import "FKPriceWarnEditController.h"
- #import "FKProDetailController.h"
- static NSString *PRICE_WARN_LIST_CELL_IDENTIFY = @"PRICE_WARN_LIST_CELL_IDENTIFY";
- static const int REQ_WARN_LIST_FIRST = 821;
- static const int REQ_WARN_LIST_MORE = 822;
- static const int REQ_DELETE_REMIND = 823;
- @interface FKPriceWarnListController () <UITableViewDataSource, UITableViewDelegate, FLNetworkDelegate>
- @property (nonatomic, strong) FKPriceWarnListViewModel *viewModel;
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation FKPriceWarnListController
- - (void)viewDidLoad{
- [super viewDidLoad];
- self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
- [self addAllSubviews];
- [self addRefreshControl];
- }
- - (void)addAllSubviews{
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
- }
- - (void)addRefreshControl{
- [self initRefreshControlWithTableView:self.tableView];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self requestDataList];
-
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- self.navigationItem.title = @"降价提醒";
- }
- - (void)resetBottomRefresh{
- [self.refreshControl setBottomEnabled:[self.viewModel bottomRefreshEnable]];
- }
- - (void)requestDataList{
- [self.hudView show:YES];
- [FKPriceWarnListRequest reqWarnListWithIdentify:REQ_WARN_LIST_FIRST
- startRow:0
- delegate:self];
- }
- #pragma mark - refresh delegate
- - (void)refreshControl:(FKRefreshControl *)refreshControl didEngageRefreshDirection:(RefreshDirection)direction{
- if (direction == RefreshDirectionTop) {
- [FKPriceWarnListRequest reqWarnListWithIdentify:REQ_WARN_LIST_FIRST
- startRow:0
- delegate:self];
- }else if (direction == RefreshDirectionBottom){
- [FKPriceWarnListRequest reqWarnListWithIdentify:REQ_WARN_LIST_MORE
- startRow:self.viewModel.dataArray.count
- delegate:self];
- }
- }
- #pragma mark - response
- - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header{
- [self.hudView hide:NO];
- [self.refreshControl finishRefreshingDirection:RefreshDirectionTop];
-
- [self.statusView removeFromSuperview];
- if (header.code.integerValue == RESPONSE_MSG_NORMAL){
- if (identify == REQ_WARN_LIST_FIRST){
- self.viewModel.dataArray = [FKPriceWarnListReform parserWarnListWithResponse:response];
- }else if (identify == REQ_WARN_LIST_MORE){
- [self.viewModel appendMoreArray:[FKPriceWarnListReform parserWarnListWithResponse:response]];
- }else if (identify == REQ_DELETE_REMIND){
- [self.viewModel deleteRemindItemAtIndex:self.viewModel.targetToDelete];
- [self.tableView reloadData];
- }
-
- if (self.viewModel.dataArray.count == 0) {
- [self showStatusTipInView:self.view image:[UIImage imageNamed:@"StatusNoMessageIcon"] title:@"没有发现商品哦"];
- }
-
- self.viewModel.totalCount = [FKPriceWarnListReform parserListTotlaWithResponse:response];
- [self resetBottomRefresh];
- [self.tableView reloadData];
- }else{
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header{
- [self.hudView hide:NO];
- [self.refreshControl finishRefreshingDirection:RefreshDirectionTop];
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- #pragma mark - tableView dataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return self.viewModel.dataArray.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- FKPriceWarnListCell *cell = [tableView dequeueReusableCellWithIdentifier:PRICE_WARN_LIST_CELL_IDENTIFY];
- FKRemindProductItem *item = [self.viewModel remindItemAtIndex:indexPath.section];
-
- cell.bookPirceBtn.tag = indexPath.section;
- [cell.bookPirceBtn addTarget:self action:@selector(clickEditBtn:) forControlEvents:UIControlEventTouchUpInside];
- [cell configWithRemindItem:item];
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- return 105.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 10.0f;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *view = [[UIView alloc]init];
- view.backgroundColor = [UIColor clearColor];
- return view;
- }
- #define TableView Edit
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
- return YES;
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
- return UITableViewCellEditingStyleDelete;
- }
- - (nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath;{
- return @"删除";
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if (editingStyle == UITableViewCellEditingStyleDelete){
- FKRemindProductItem *item = [self.viewModel remindItemAtIndex:indexPath.section];
- if (item && [FLStringHelper isValidString:item.goodsID]){
-
- self.viewModel.targetToDelete = indexPath.section;
-
- [self.hudView show:YES];
- [FKPriceWarnListRequest reqRemoveWarnWithIdentify:REQ_DELETE_REMIND
- goodsID:item.itemID
- delegate:self];
- }
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- FKRemindProductItem *item = [self.viewModel remindItemAtIndex:indexPath.section];
-
- if (item && [FLStringHelper isValidString:item.productID]){
-
- FKProDetailController *detail = [[FKProDetailController alloc]initWithProductID:item.productID selectSpecId:item.goodsID];
- [self.navigationController pushViewController:detail animated:YES];
- }
- }
- #pragma mark - action
- - (void)clickEditBtn:(UIButton *)sender{
- FKRemindProductItem *item = [self.viewModel remindItemAtIndex:sender.tag];
- FKPriceWarnItem *warnItem = [item createPriceWarnItem];
-
- if (warnItem){
- FKPriceWarnEditController *controller = [[FKPriceWarnEditController alloc]initWithPriceWarnItem:warnItem];
- [controller setHidesBottomBarWhenPushed:YES];
- [self.navigationController pushViewController:controller animated:YES];
- }
- }
- #pragma mark - property
- - (UITableView *)tableView {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.backgroundView = nil;
- [_tableView registerClass:[FKPriceWarnListCell class] forCellReuseIdentifier:PRICE_WARN_LIST_CELL_IDENTIFY];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- - (FKPriceWarnListViewModel *)viewModel{
- if (_viewModel == nil) {
- _viewModel = [[FKPriceWarnListViewModel alloc]init];
- }
- return _viewModel;
- }
- @end
|