ClientShoppingCarViewController.m 6.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//
//  ClientShoppingCarViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/10/25.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ClientShoppingCarViewController.h"
#import "ShopcarModel.h"
#import "ProductDetailsViewController.h"
#import "ClientDetailsTableViewCell.h"

@interface ClientShoppingCarViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

/**
 *  记录总页数
 */
@property (nonatomic,assign) NSInteger totalPage;

/**
 *  购物车数据源
 */
@property (nonatomic,strong) NSMutableArray *shopResponseArray;

/**
 *  购物袋请求
 */
@property (nonatomic,strong) ShopCartFilter *shoppingCarModel;

@end

@implementation ClientShoppingCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self GetdatasAciton];
}

#pragma mark -获取数据
- (void)GetdatasAciton
{
    WS(weakSelf);
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //购物袋
        weakSelf.shoppingCarModel.dp.page = 1;
        [weakSelf.clientShoppingCarTableView.mj_footer resetNoMoreData];
        [weakSelf getShoppingCardata:weakSelf.shoppingCarModel isRemove:YES];
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.clientShoppingCarTableView.mj_header = headerRefresh;
    //进入刷新状态
    [self.clientShoppingCarTableView.mj_header beginRefreshing];
    //上拉加载
    self.clientShoppingCarTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [weakSelf.clientShoppingCarTableView.mj_footer resetNoMoreData];
        //购物袋
        if (++ weakSelf.shoppingCarModel.dp.page > weakSelf.totalPage) {
            [weakSelf.clientShoppingCarTableView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
            [weakSelf getShoppingCardata:weakSelf.shoppingCarModel isRemove:NO];
        }
    }];
    self.clientShoppingCarTableView.mj_footer.automaticallyHidden = YES;
    self.clientShoppingCarTableView.tableFooterView = [UIView new];
}

#pragma mark -获取购物车商品
- (void)getShoppingCardata:(ShopCartFilter *)shopCar isRemove:(BOOL)remove
{
曹云霄's avatar
曹云霄 committed
76
    [XBLoadingView showHUDViewWithDefault];
77
    WS(weakSelf);
78
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(SHOPPINGBAG)  WithRequestType:ZERO WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
79 80 81 82
        
        weakSelf.clientShoppingCarTableView.emptyDataSetSource = weakSelf;
        weakSelf.clientShoppingCarTableView.emptyDataSetDelegate = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.clientShoppingCarTableView];
曹云霄's avatar
曹云霄 committed
83
        [XBLoadingView hideHUDViewWithDefault];
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            if (remove) {
                [weakSelf.shopResponseArray removeAllObjects];
            }
            ShopCartResponse *shopcar = [[ShopCartResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            weakSelf.totalPage = [returnValue[@"data"][@"totalpages"] intValue];
            //自定义属性
            for (TOShopcartEntity *objc in shopcar.shopcart) {
                ShopcarModel *model = [[ShopcarModel alloc]init];
                model.goods = objc.goods;
                model.fid = objc.fid;
                model.createName = objc.createName;
                model.createBy = objc.createBy;
                model.createDate = objc.createDate;
                model.updateName = objc.updateName;
                model.updateBy = objc.updateBy;
                model.updateDate = objc.updateDate;
                model.goodsId = objc.goodsId;
                model.goodsNum = objc.goodsNum;
                model.consumerId = objc.consumerId;
                [weakSelf.shopResponseArray addObject:model];
            }
            [weakSelf.clientShoppingCarTableView reloadData];
            
        }else
        {
曹云霄's avatar
曹云霄 committed
110
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
111
        }
112
    }WithFailureBlock:^(NSError *error) {
113
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
114
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    }];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClientDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClientDetails" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.shopResponseArray objectAtIndex_opple:indexPath.row];
    return cell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.shopResponseArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
140
    ProductDetailsViewController *productDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"productdetails"];
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    ShopcarModel *model = [self.shopResponseArray objectAtIndex_opple:indexPath.row];
    productDetails.goodsID = model.goods.fid;
    [self.navigationController pushViewController:productDetails animated:YES];
}

#pragma mark - lazy
- (NSMutableArray *)shopResponseArray
{
    if (_shopResponseArray == nil) {
        
        _shopResponseArray = [NSMutableArray array];
    }
    return _shopResponseArray;
}

- (ShopCartFilter *)shoppingCarModel
{
    if (!_shoppingCarModel) {
        _shoppingCarModel = [[ShopCartFilter alloc]init];
        DataPage *Newpage = [[DataPage alloc]init];
        Newpage.page = 1;
        Newpage.rows = KROWS;
        _shoppingCarModel.dp = Newpage;
        _shoppingCarModel.consumerId = self.model.fid;
    }
    return _shoppingCarModel;
}

#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    return 100;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end