ShoppingViewController.m 15.7 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  ShoppingViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShoppingViewController.h"
曹云霄's avatar
曹云霄 committed
10 11
#import "ShoppingTableViewCell.h"
#import "AppDelegate.h"
曹云霄's avatar
曹云霄 committed
12
#import "GenerateOrdersViewController.h"
勾芒's avatar
勾芒 committed
13
#import "ShopcarModel.h"
勾芒's avatar
勾芒 committed
14
#import "AddressModel.h"
曹云霄's avatar
曹云霄 committed
15
#import "ProductDetailsViewController.h"
曹云霄's avatar
曹云霄 committed
16

曹云霄's avatar
曹云霄 committed
17
@interface ShoppingViewController ()<UITableViewDelegate,UITableViewDataSource,ChangeGoodsNumberDelegate,DZNEmptyDataSetSource>
曹云霄's avatar
曹云霄 committed
18

曹云霄's avatar
曹云霄 committed
19 20

@property (weak, nonatomic) IBOutlet UITableView *shoppingTableview;
曹云霄's avatar
曹云霄 committed
21

勾芒's avatar
勾芒 committed
22 23 24 25 26 27 28



/**
 *  购物车数据源
 */
@property (nonatomic,strong) NSMutableArray *shopResponseArray;
勾芒's avatar
勾芒 committed
29 30 31



曹云霄's avatar
曹云霄 committed
32 33 34 35
@end

@implementation ShoppingViewController

曹云霄's avatar
曹云霄 committed
36 37 38 39

/**
 *  数据源
 */
勾芒's avatar
勾芒 committed
40
- (NSMutableArray *)shopResponseArray
曹云霄's avatar
曹云霄 committed
41
{
勾芒's avatar
勾芒 committed
42
    if (_shopResponseArray == nil) {
曹云霄's avatar
曹云霄 committed
43
        
勾芒's avatar
勾芒 committed
44
        _shopResponseArray = [NSMutableArray array];
曹云霄's avatar
曹云霄 committed
45
    }
勾芒's avatar
勾芒 committed
46
    return _shopResponseArray;
曹云霄's avatar
曹云霄 committed
47 48 49
}


曹云霄's avatar
曹云霄 committed
50 51 52
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
53
    
曹云霄's avatar
曹云霄 committed
54 55 56
    [self uiConfigAction];
}

勾芒's avatar
勾芒 committed
57
#pragma mark -渲染完成
58 59 60
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
曹云霄's avatar
曹云霄 committed
61
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
勾芒's avatar
勾芒 committed
62 63 64
    [self.shopResponseArray removeAllObjects];
    [self InitializeState];
    [self getShoppingCardata];
65 66
}

勾芒's avatar
勾芒 committed
67
#pragma mark -视图即将消失
68 69 70
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
曹云霄's avatar
曹云霄 committed
71
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
72 73
}

勾芒's avatar
勾芒 committed
74 75 76 77 78 79 80 81
#pragma mark -初始化状态
- (void)InitializeState
{
    [self.settlementButton setTitle:@"去结算(0)" forState:UIControlStateNormal];
    self.allSelectedButton.selected = NO;
    self.totalpriceLabe.text = nil;
}

曹云霄's avatar
曹云霄 committed
82

曹云霄's avatar
曹云霄 committed
83 84 85
#pragma mark - UI
- (void)uiConfigAction
{
勾芒's avatar
勾芒 committed
86 87
    self.settlementButton.layer.masksToBounds = YES;
    self.settlementButton.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
88
    self.view.backgroundColor = kTCColor(238, 238, 238);
曹云霄's avatar
曹云霄 committed
89 90
    self.shoppingTableview.dataSource = self;
    self.shoppingTableview.delegate = self;
勾芒's avatar
勾芒 committed
91
    self.shoppingTableview.backgroundColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
92 93 94
    self.shoppingTableview.tableFooterView = [UIView new];
}

勾芒's avatar
勾芒 committed
95 96


勾芒's avatar
勾芒 committed
97 98 99 100 101 102 103 104 105
#pragma mark -获取购物车商品
- (void)getShoppingCardata
{
    //判断是否需要请求数据-通过当前客户ID
    if (![Shoppersmanager manager].currentCustomer) {
        
        return;
    }
    ShopCartFilter *shopcarNumber = [[ShopCartFilter alloc]init];
勾芒's avatar
勾芒 committed
106
    shopcarNumber.consumerId = [Customermanager manager].model.fid;
勾芒's avatar
勾芒 committed
107
    DataPage *Newpage = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
108 109
    Newpage.page = 1;
    Newpage.rows = 99999;
勾芒's avatar
勾芒 committed
110 111
    shopcarNumber.dp = Newpage;
    [self CreateMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
112
    WS(weakSelf);
113
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(SHOPPINGBAG) WithRequestType:0 WithParameter:shopcarNumber WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
114
        
曹云霄's avatar
曹云霄 committed
115 116 117
        weakSelf.shoppingTableview.emptyDataSetSource = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.shoppingTableview];
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
118
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
119
  
勾芒's avatar
勾芒 committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            ShopCartResponse *shopcar = [[ShopCartResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //自定义属性
            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;
勾芒's avatar
勾芒 committed
136
                model.costPrice = objc.costPrice;
曹云霄's avatar
曹云霄 committed
137
                [weakSelf.shopResponseArray addObject:model];
勾芒's avatar
勾芒 committed
138
            }
曹云霄's avatar
曹云霄 committed
139
            [weakSelf.shoppingTableview reloadData];
勾芒's avatar
勾芒 committed
140 141
        }else
        {
曹云霄's avatar
曹云霄 committed
142
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
143 144
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
145 146
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:@"无网络"];
勾芒's avatar
勾芒 committed
147 148
    } WithFailureBlock:^(id error) {
        
曹云霄's avatar
曹云霄 committed
149 150
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf endRefreshingForTableView:weakSelf.shoppingTableview];
勾芒's avatar
勾芒 committed
151 152 153 154
    }];
}


曹云霄's avatar
曹云霄 committed
155 156 157
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShoppingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Shopping" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
158 159
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.shopResponseArray objectAtIndex_opple:indexPath.row];
勾芒's avatar
勾芒 committed
160
    cell.delegate = self;
勾芒's avatar
勾芒 committed
161 162
    cell.cellindex = indexPath.row;
    //cell选中回调
勾芒's avatar
勾芒 committed
163
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
164 165
    [cell setReturnCellblock:^(NSInteger index) {
        
勾芒's avatar
勾芒 committed
166
        [weakSelf setSelectedButton:index];
勾芒's avatar
勾芒 committed
167
    }];
勾芒's avatar
勾芒 committed
168 169
    //提示框回调
    [cell setPromptStringBlock:^(NSString *string) {
曹云霄's avatar
曹云霄 committed
170
        [weakSelf ErrorMBProgressView:string];
勾芒's avatar
勾芒 committed
171
    }];
曹云霄's avatar
曹云霄 committed
172 173 174 175 176
    return  cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
177
    return self.shopResponseArray.count;
曹云霄's avatar
曹云霄 committed
178 179 180 181 182 183 184 185
}


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

曹云霄's avatar
曹云霄 committed
186 187 188 189 190 191
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductDetailsViewController *productDetails = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"productdetails"];
    productDetails.goodsID = [[self.shopResponseArray objectAtIndex_opple:indexPath.row] goodsId];
    [self.navigationController pushViewController:productDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
192 193 194 195 196 197

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.shoppingTableview deselectRowAtIndexPath:indexPath animated:YES];
}

勾芒's avatar
勾芒 committed
198
#pragma mark -选中商品回调
勾芒's avatar
勾芒 committed
199 200 201
- (void)setSelectedButton:(NSInteger)index;
{
    ShopcarModel *model = [self.shopResponseArray objectAtIndex_opple:index];
勾芒's avatar
勾芒 committed
202
    model.isSelected = !model.isSelected;
勾芒's avatar
勾芒 committed
203 204 205 206 207 208
    
    NSInteger goodsNumber = 0;
    for (ShopcarModel *model in self.shopResponseArray) {
        if (model.isSelected) {
            goodsNumber ++;
        }
勾芒's avatar
勾芒 committed
209 210 211 212 213 214
    }
    if (goodsNumber == self.shopResponseArray.count) {
        self.allSelectedButton.selected = YES;
    }else
    {
        self.allSelectedButton.selected = NO;
勾芒's avatar
勾芒 committed
215
    }
勾芒's avatar
勾芒 committed
216
    [self CalculateSelectedGoodsAllprice];
勾芒's avatar
勾芒 committed
217
    [self.settlementButton setTitle:[NSString stringWithFormat:@"去结算(%ld)",goodsNumber] forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
218 219 220
}


曹云霄's avatar
曹云霄 committed
221 222 223
#pragma mark -结算
- (IBAction)settlementButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
224 225 226 227 228 229 230 231 232 233 234
    NSMutableArray *array = [NSMutableArray array];
    for (ShopcarModel *model in self.shopResponseArray) {
        if (model.isSelected) {
            [array addObject:model];
        }
    }
    if (array.count == 0) {
        
        [self ErrorMBProgressView:@"没有选中任何商品"];
        return;
    }
勾芒's avatar
勾芒 committed
235 236
    //商品总信息占位
     ShopcarModel*ZhanweiModel = [[ShopcarModel alloc]init];
勾芒's avatar
勾芒 committed
237
    [array addObject:ZhanweiModel];
勾芒's avatar
勾芒 committed
238
    
曹云霄's avatar
曹云霄 committed
239
    GenerateOrdersViewController *generateOrder = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"generateorders"];
勾芒's avatar
勾芒 committed
240
    generateOrder.settlementGoodsdatas = array;
勾芒's avatar
勾芒 committed
241 242 243 244 245
    //清除已经生成订单的商品
    [generateOrder setDelecteSelectedGoods:^(NSArray *goodsCode) {
        
        DeleteCartRequest *delecteGoods = [[DeleteCartRequest alloc]init];
        delecteGoods.cartIds = goodsCode;
曹云霄's avatar
曹云霄 committed
246
        WS(weakSelf);
247
        [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(REMOVESHOPPINGBAG) WithRequestType:0 WithParameter:delecteGoods WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
248
            
曹云霄's avatar
曹云霄 committed
249
            [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
250 251
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
                
曹云霄's avatar
曹云霄 committed
252
                [weakSelf QueryShoppingCarNumber];
勾芒's avatar
勾芒 committed
253 254 255
                //商品cell
                NSMutableArray *cellArray = [NSMutableArray array];
                //删除商品
曹云霄's avatar
曹云霄 committed
256 257
                for (int i=0; i<weakSelf.shopResponseArray.count; i++) {
                    ShopcarModel *model = [weakSelf.shopResponseArray objectAtIndex_opple:i];
勾芒's avatar
勾芒 committed
258
                    if ([goodsCode containsObject:model.fid]) {
曹云霄's avatar
曹云霄 committed
259
                        [weakSelf.shopResponseArray removeObject:model];
勾芒's avatar
勾芒 committed
260 261 262 263 264
                        NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:0];
                        [cellArray addObject:indexpath];
                    }
                }
                //删除cell
曹云霄's avatar
曹云霄 committed
265
                [weakSelf.shoppingTableview deleteRowsAtIndexPaths:cellArray withRowAnimation:UITableViewRowAnimationTop];
勾芒's avatar
勾芒 committed
266 267
            }else
            {
曹云霄's avatar
曹云霄 committed
268
                [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
269 270 271
            }
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
272 273
            [weakSelf RemoveMBProgressHUDLoding];
            [weakSelf ErrorMBProgressView:@"无网络"];
勾芒's avatar
勾芒 committed
274 275 276
            
        } WithFailureBlock:^(id error) {
            
曹云霄's avatar
曹云霄 committed
277
            [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
278 279 280
        }];
    }];
    
曹云霄's avatar
曹云霄 committed
281
    [self.navigationController pushViewController:generateOrder animated:YES];
曹云霄's avatar
曹云霄 committed
282
}
曹云霄's avatar
曹云霄 committed
283

曹云霄's avatar
曹云霄 committed
284
#pragma mark -全选
勾芒's avatar
勾芒 committed
285
- (IBAction)allSelectedButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
286
    
勾芒's avatar
勾芒 committed
287 288 289 290 291 292 293 294 295 296 297 298
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        //全部选中
        for (ShoppingTableViewCell *cell in self.shoppingTableview.visibleCells) {
            
            cell.selectedButton.selected = YES;
        }
        for (ShopcarModel *model in self.shopResponseArray) {
            
            model.isSelected = YES;
        }
勾芒's avatar
勾芒 committed
299
        [self.settlementButton setTitle:[NSString stringWithFormat:@"去结算(%ld)",self.shopResponseArray.count] forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
300

勾芒's avatar
勾芒 committed
301 302 303 304 305 306 307 308 309 310 311
    }else
    {
        //取消全部选中
        for (ShoppingTableViewCell *cell in self.shoppingTableview.visibleCells) {
            
            cell.selectedButton.selected = NO;
        }
        for (ShopcarModel *model in self.shopResponseArray) {
            
            model.isSelected = NO;
        }
勾芒's avatar
勾芒 committed
312
        [self.settlementButton setTitle:@"去结算(0)" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
313
    }
勾芒's avatar
勾芒 committed
314 315
    //计算总金额
    [self CalculateSelectedGoodsAllprice];
曹云霄's avatar
曹云霄 committed
316 317
}

勾芒's avatar
勾芒 committed
318 319 320
#pragma mark -计算选中后的商品总金额
- (void)CalculateSelectedGoodsAllprice
{
勾芒's avatar
勾芒 committed
321
    CGFloat allPrice = 0;
勾芒's avatar
勾芒 committed
322 323
    for (ShopcarModel *model in self.shopResponseArray) {
        if (model.isSelected) {
勾芒's avatar
勾芒 committed
324
            allPrice += ([model.costPrice floatValue]?[model.costPrice floatValue]:[model.goods.tagPrice floatValue]) * model.goodsNum;
勾芒's avatar
勾芒 committed
325 326
        }
    }
勾芒's avatar
勾芒 committed
327
    self.totalpriceLabe.text = [NSString stringWithFormat:@"¥%.2f",allPrice];
勾芒's avatar
勾芒 committed
328 329
}

曹云霄's avatar
曹云霄 committed
330

勾芒's avatar
勾芒 committed
331 332 333
#pragma mark -删除选中商品
- (IBAction)delecteSelectedGoods:(UIButton *)sender {

勾芒's avatar
勾芒 committed
334 335 336 337 338 339
    
    [self CreateMBProgressHUDLoding];
    DeleteCartRequest *delecteGoods = [[DeleteCartRequest alloc]init];
    //code数组
    NSMutableArray *codeArr = [NSMutableArray array];
    //需要删除的cell数组indexpath
勾芒's avatar
勾芒 committed
340
    NSMutableArray *delecteArray = [NSMutableArray array];
勾芒's avatar
勾芒 committed
341 342
    //模型数组
    NSMutableArray *delectemodel = [NSMutableArray array];
勾芒's avatar
勾芒 committed
343 344 345 346
    for (int i=0; i<self.shopResponseArray.count; i++) {
        
        ShopcarModel *model = [self.shopResponseArray objectAtIndex_opple:i];
        if (model.isSelected) {
勾芒's avatar
勾芒 committed
347 348 349
            
            [codeArr addObject:model.fid];
            [delectemodel addObject:model];
勾芒's avatar
勾芒 committed
350 351 352 353
            NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:0];
            [delecteArray addObject:indexpath];
        }
    }
勾芒's avatar
勾芒 committed
354 355 356 357 358 359
    //没有选中任何商品
    if (codeArr.count == 0) {
        [self RemoveMBProgressHUDLoding];
        return;
    }
    delecteGoods.cartIds = codeArr;
曹云霄's avatar
曹云霄 committed
360
    WS(weakSelf);
361
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(REMOVESHOPPINGBAG) WithRequestType:0 WithParameter:delecteGoods WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
362
        
曹云霄's avatar
曹云霄 committed
363
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
364 365
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
曹云霄's avatar
曹云霄 committed
366
            [weakSelf QueryShoppingCarNumber];
勾芒's avatar
勾芒 committed
367 368
            //删除商品
            for (ShopcarModel *model in delectemodel) {
曹云霄's avatar
曹云霄 committed
369
                [weakSelf.shopResponseArray removeObject:model];
勾芒's avatar
勾芒 committed
370
            }
曹云霄's avatar
曹云霄 committed
371
            [weakSelf.shoppingTableview deleteRowsAtIndexPaths:delecteArray withRowAnimation:UITableViewRowAnimationLeft];
曹云霄's avatar
曹云霄 committed
372
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
曹云霄's avatar
曹云霄 committed
373
                [weakSelf.shoppingTableview reloadData];
曹云霄's avatar
曹云霄 committed
374
            });
曹云霄's avatar
曹云霄 committed
375 376 377 378
            [weakSelf SuccessMBProgressView:@"删除成功"];
            [weakSelf CalculateSelectedGoodsAllprice];
            weakSelf.allSelectedButton.selected = NO;
            [weakSelf.settlementButton setTitle:@"去结算(0)" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
379 380
        }else
        {
曹云霄's avatar
曹云霄 committed
381
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
382
        }
勾芒's avatar
勾芒 committed
383

勾芒's avatar
勾芒 committed
384
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
385 386
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:@"无网络"];
勾芒's avatar
勾芒 committed
387 388 389
        
    } WithFailureBlock:^(id error) {
        
曹云霄's avatar
曹云霄 committed
390
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
391
    }];
勾芒's avatar
勾芒 committed
392
}
曹云霄's avatar
曹云霄 committed
393 394


勾芒's avatar
勾芒 committed
395

勾芒's avatar
勾芒 committed
396
#pragma mark -改变商品数量
曹云霄's avatar
曹云霄 committed
397
- (void)ChangeGoodsNumber:(NSInteger)goodsNumber WithcostPrice:(CGFloat)costprice Withcellindex:(NSInteger)cellindex returnValue:(void (^)(id))result
勾芒's avatar
勾芒 committed
398
{
勾芒's avatar
勾芒 committed
399
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
400 401 402 403 404 405
    //保存商品数量
    ShopcarModel *model = [self.shopResponseArray objectAtIndex_opple:cellindex];
    model.goodsNum = goodsNumber;
//    [self.shopResponseArray replaceObjectAtIndex:cellindex withObject:model];
    //保存成交价格
    ShopcarModel *Newmodel = [self.shopResponseArray objectAtIndex_opple:cellindex];
勾芒's avatar
勾芒 committed
406
    Newmodel.costPrice = [NSNumber numberWithFloat:costprice];
勾芒's avatar
勾芒 committed
407
//    [self.shopResponseArray replaceObjectAtIndex:cellindex withObject:Newmodel];
曹云霄's avatar
曹云霄 committed
408
    //在服务器保存数量、成交价
勾芒's avatar
勾芒 committed
409 410 411 412 413
    //购物车ID
    NSString *carid = [[self.shopResponseArray objectAtIndex_opple:cellindex] fid];
    //商品id
    NSString *goodsis = [[[self.shopResponseArray objectAtIndex_opple:cellindex] goods] fid];
    //成交价
勾芒's avatar
勾芒 committed
414
    NSString *costpriceString = [NSString stringWithFormat:@"%.2f",costprice];
勾芒's avatar
勾芒 committed
415
    //商品数量
曹云霄's avatar
曹云霄 committed
416 417
    NSString *goodsNumberString = [NSString stringWithFormat:@"%ld",(long)goodsNumber];
    WS(weakSelf);
418
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@/%@",SERVERREQUESTURL(CHANGESHOPPINGBAGNUMBERPRICE),carid,goodsis,costpriceString,goodsNumberString] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
419
        
曹云霄's avatar
曹云霄 committed
420 421
        [weakSelf RemoveMBProgressHUDLoding];
        result(returnValue);//提供是否支持修改的参数
勾芒's avatar
勾芒 committed
422 423
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            NSLog(@"写入服务器成功");
曹云霄's avatar
曹云霄 committed
424 425 426 427 428
            [weakSelf CalculateSelectedGoodsAllprice];
            [weakSelf QueryShoppingCarNumber];
        }else{
            
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
429 430 431
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
432 433
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:@"无网络"];
勾芒's avatar
勾芒 committed
434 435 436
        
    } WithFailureBlock:^(id error) {
        NSLog(@"写入服务器失败");
曹云霄's avatar
曹云霄 committed
437
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
438
    }];
勾芒's avatar
勾芒 committed
439
}
曹云霄's avatar
曹云霄 committed
440 441


曹云霄's avatar
曹云霄 committed
442 443 444 445
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
曹云霄's avatar
曹云霄 committed
446
    
曹云霄's avatar
曹云霄 committed
447 448 449 450 451 452 453 454
}


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

勾芒's avatar
勾芒 committed
455

曹云霄's avatar
曹云霄 committed
456
@end