GenerateOrdersViewController.m 20.2 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
//  GenerateOrdersViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/5.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "GenerateOrdersViewController.h"
#import "GenerateOrdersTableViewCell.h"
#import "GenerateOrdersModifyTableViewCell.h"
#import "PersonInformationTableViewCell.h"
#import "CommodityListTableViewCell.h"
#import "AllpriceTableViewCell.h"
#import "AddaddressViewController.h"
#import "AppDelegate.h"
#import "OrderdetailsViewController.h"
曹云霄's avatar
曹云霄 committed
18
#import "AddressViewController.h"
勾芒's avatar
勾芒 committed
19 20
#import "AddressModel.h"
@interface GenerateOrdersViewController ()<UITableViewDelegate,UITableViewDataSource,delecteDelegate>
曹云霄's avatar
曹云霄 committed
21 22


勾芒's avatar
勾芒 committed
23 24 25 26 27 28
/**
 *  数据源
 */
@property (nonatomic,strong) NSMutableArray *datasArray;


曹云霄's avatar
曹云霄 committed
29 30 31 32 33
@property (nonatomic,strong) UIView *Tabbarview;
@end

@implementation GenerateOrdersViewController

勾芒's avatar
勾芒 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/**
 *  初始化数据源
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
        
        _datasArray = [NSMutableArray array];
        for (int i=0; i<3; i++) {
            NSMutableArray *arr = [NSMutableArray array];
            [_datasArray addObject:arr];
        }
        //加入客户信息model
        Customermanager *customerModel = [Customermanager manager];
        [[_datasArray firstObject] addObject:customerModel];
        
勾芒's avatar
勾芒 committed
50 51
        AddressModel *model = [[AddressModel alloc]init];
        model.name = @"地址占位";
勾芒's avatar
勾芒 committed
52
        //地址占位
勾芒's avatar
勾芒 committed
53
        [[_datasArray objectAtIndex_opple:1] addObject:model];
勾芒's avatar
勾芒 committed
54 55 56 57 58 59
        //加入商品信息
        [_datasArray replaceObjectAtIndex:2 withObject:_settlementGoodsdatas];
    }
    
    return _datasArray;
}
曹云霄's avatar
曹云霄 committed
60 61


勾芒's avatar
勾芒 committed
62 63 64 65
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
曹云霄's avatar
曹云霄 committed
66
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
67 68 69
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
勾芒's avatar
勾芒 committed
70 71 72 73 74 75
}

#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
曹云霄's avatar
曹云霄 committed
76
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
77 78 79
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
曹云霄's avatar
曹云霄 committed
80

勾芒's avatar
勾芒 committed
81
}
曹云霄's avatar
曹云霄 committed
82

曹云霄's avatar
曹云霄 committed
83 84 85 86
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
87
    [self getAddressDatasRequest];
曹云霄's avatar
曹云霄 committed
88 89 90 91 92 93 94 95
}

#pragma mark -UI
- (void)uiConfigAction
{
    self.generateOrderTableview.dataSource = self;
    self.generateOrderTableview.delegate = self;
    self.generateOrderTableview.tableFooterView = [UIView new];
勾芒's avatar
勾芒 committed
96 97 98 99
    self.backShoppingbagsButton.layer.masksToBounds = YES;
    self.backShoppingbagsButton.layer.cornerRadius = kCornerRadius;
    self.createOrderButton.layer.masksToBounds = YES;
    self.createOrderButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
100 101 102
}


勾芒's avatar
勾芒 committed
103 104 105
#pragma mark -获得地址信息
- (void)getAddressDatasRequest
{
曹云霄's avatar
曹云霄 committed
106
    [XBLoadingView showHUDViewWithDefault];
107
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
108
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(SHIPPINGADDRESS),[Customermanager manager].model.fid]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
109
        
曹云霄's avatar
曹云霄 committed
110
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
111
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
112
            RsShippingAddrEntity *address = [[RsShippingAddrEntity alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
勾芒's avatar
勾芒 committed
113 114
            for (NSInteger i=address.list.count-1; i>=0; i--) {
                TOShippingAddrEntity *model = [address.list objectAtIndex_opple:i];
勾芒's avatar
勾芒 committed
115
                //自定义model
曹云霄's avatar
曹云霄 committed
116 117
                AddressModel *newmodel = [[AddressModel alloc]initWithDictionary:[model toDictionary] error:nil];
                [[weakSelf.datasArray objectAtIndex_opple:1]insertObject:newmodel atIndex:0];
勾芒's avatar
勾芒 committed
118
            }
勾芒's avatar
勾芒 committed
119
            //地址数组
120
            NSArray *addressArray = [weakSelf.datasArray objectAtIndex_opple:1];
勾芒's avatar
勾芒 committed
121 122 123 124 125 126
            //增加cell
            NSMutableArray *addCellArray = [NSMutableArray array];
            for (int i=0; i<addressArray.count-1; i++) {
                NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:1];
                [addCellArray addObject:indexpath];
            }
127
            [weakSelf.generateOrderTableview insertRowsAtIndexPaths:addCellArray withRowAnimation:UITableViewRowAnimationBottom];
勾芒's avatar
勾芒 committed
128 129 130
        }
        else
        {
131
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
132
        }
133
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
134
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
135 136 137
    }];
}

曹云霄's avatar
曹云霄 committed
138 139 140 141 142

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
143
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
144 145 146 147
        return cell;
    }
    else if (indexPath.section == 1)
    {
勾芒's avatar
勾芒 committed
148 149
        NSArray *Addressarr = [self.datasArray objectAtIndex_opple:indexPath.section];
        if (indexPath.row == Addressarr.count-1) {
勾芒's avatar
勾芒 committed
150 151
            GenerateOrdersModifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Modifycell" forIndexPath:indexPath];
            //增加地址或者修改
152 153
            [cell.addAddressButton addTarget:self action:@selector(addAddressButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.changeButton addTarget:self action:@selector(changeButtonClick) forControlEvents:UIControlEventTouchUpInside];
勾芒's avatar
勾芒 committed
154
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
155
            cell.backgroundColor = RGB(242, 242, 242,1);
曹云霄's avatar
曹云霄 committed
156 157
            return cell;
        }
勾芒's avatar
勾芒 committed
158
        GenerateOrdersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"consigneecell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
159
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
160
        cell.backgroundColor = RGB(242, 242, 242,1);
勾芒's avatar
勾芒 committed
161 162
        cell.indexNumber = indexPath.row;
        //回调
163
        __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
164
        [cell setBlockSeletced:^(NSInteger index) {
165
            [weakSelf setCustomerButtonClick:index];
勾芒's avatar
勾芒 committed
166 167
        }];
        cell.NewModel = [self.datasArray objectAtIndex_opple:indexPath.section][indexPath.row];
曹云霄's avatar
曹云霄 committed
168 169
        return cell;
    }
曹云霄's avatar
曹云霄 committed
170 171 172 173
    NSArray *Addressarr = [self.datasArray objectAtIndex_opple:indexPath.section];
    if (indexPath.row == Addressarr.count-1) {
        
        AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
174
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
175
        cell.goodsAllprice = [self.datasArray objectAtIndex_opple:indexPath.section];
曹云霄's avatar
曹云霄 committed
176 177
        return cell;
    }
曹云霄's avatar
曹云霄 committed
178 179 180 181
    CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.datasArray objectAtIndex_opple:indexPath.section][indexPath.row];
    return cell;
曹云霄's avatar
曹云霄 committed
182 183 184 185 186
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
187 188
    NSArray *arr = [self.datasArray objectAtIndex_opple:section];
    return arr.count;
曹云霄's avatar
曹云霄 committed
189 190 191 192 193 194 195 196
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
勾芒's avatar
勾芒 committed
197
            return 110;
曹云霄's avatar
曹云霄 committed
198 199 200 201
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
202 203 204 205 206
            NSArray *arr = [self.datasArray objectAtIndex_opple:indexPath.section];
            if (indexPath.row == arr.count-1) {
                
                return 70;
            }
曹云霄's avatar
曹云霄 committed
207 208 209 210 211
            return 56;
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
212 213
            NSArray *arr = [self.datasArray objectAtIndex_opple:indexPath.section];
            if (indexPath.row == arr.count-1) {
曹云霄's avatar
曹云霄 committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
                
                return 50;
            }
            return 80;
        }
            break;
            
        default:
            break;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        {
            return 0;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
237
            return 5;
曹云霄's avatar
曹云霄 committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
        }
            break;
        case 2:
        {
            return 44;
        }
            break;
            
        default:
            break;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
254 255 256
    switch (section) {
        case 1:
        {
勾芒's avatar
勾芒 committed
257
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 5)];
勾芒's avatar
勾芒 committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
            imageView.image = TCImage(@"lineNew");
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
            [view addSubview:imageView];
            return view;
        }
            break;
        case 2:
        {
            UILabel *titleLabe = [[UILabel alloc]initWithFrame:CGRectMake(50, 0, 100, 44)];
            titleLabe.text = @"购物袋清单";
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
            [view addSubview:titleLabe];
            
            //横线
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 43, ScreenWidth, 1)];
曹云霄's avatar
曹云霄 committed
273
            lineView.backgroundColor = RGB(242, 242, 242,1);
勾芒's avatar
勾芒 committed
274 275 276 277 278 279 280 281 282
            [view addSubview:lineView];
            return view;
        }
            break;
            
        default:
            break;
    }
    return nil;
曹云霄's avatar
曹云霄 committed
283 284 285 286
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
287
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
288 289 290
}

#pragma mark -新增或者修改收货地址
291
- (void)createModifyShippingView:(AddressModel *)model Withindex:(NSInteger)cellindex
曹云霄's avatar
曹云霄 committed
292
{
曹云霄's avatar
曹云霄 committed
293
    AddressViewController *address = [[AddressViewController alloc]init];
勾芒's avatar
勾芒 committed
294 295 296 297 298
    address.delegate = self;
    if (model != nil) {
        address.model = model;
        address.isChange = YES;
    }
勾芒's avatar
勾芒 committed
299
    address.cellindex = cellindex;
300
    address.preferredContentSize = CGSizeMake(350, 350);
曹云霄's avatar
曹云霄 committed
301 302 303 304 305
    address.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = address.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = address.view;
    [self presentViewController:address animated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
306 307 308
}

#pragma mark -生成订单
309
- (IBAction)createOrderButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
310
    OrderBill *order = [[OrderBill alloc]init];
勾芒's avatar
勾芒 committed
311
    //分页
勾芒's avatar
勾芒 committed
312
    DataPage *page = [[DataPage alloc]init];
曹云霄's avatar
曹云霄 committed
313
    page.page = ONE;
勾芒's avatar
勾芒 committed
314 315
    order.datapage = page;
    //收货地址
勾芒's avatar
勾芒 committed
316
    TOOrderEntity *orderReceiver = [[TOOrderEntity alloc]init];
勾芒's avatar
勾芒 committed
317
    NSArray *Adressarr = [self.datasArray objectAtIndex_opple:1];
勾芒's avatar
勾芒 committed
318
    //总价格
曹云霄's avatar
曹云霄 committed
319
    CGFloat allPrice = ZERO;
勾芒's avatar
勾芒 committed
320
    //总数量
曹云霄's avatar
曹云霄 committed
321
    NSInteger allNumber = ZERO;
勾芒's avatar
勾芒 committed
322 323 324 325
    for (int i=0; i<Adressarr.count; i++) {
        if ([[Adressarr objectAtIndex_opple:i] isKindOfClass:[AddressModel class]]) {
            AddressModel *model = [Adressarr objectAtIndex_opple:i];
            if (model.isSelected) {
勾芒's avatar
勾芒 committed
326
                //收货人信息
勾芒's avatar
勾芒 committed
327
                orderReceiver.receiverName = model.name;
328
                orderReceiver.orderTime = [[NSDate date] httpParameterString];
勾芒's avatar
勾芒 committed
329 330
                orderReceiver.receiverMobile = model.miblephone;
                orderReceiver.receiverAddress = model.address;
勾芒's avatar
勾芒 committed
331
                order.order = orderReceiver;
332
                orderReceiver.guideId = [[Shoppersmanager manager] shoppers].employee.fid;
勾芒's avatar
勾芒 committed
333
                orderReceiver.consumerId = [Customermanager manager].model.fid;
334
                orderReceiver.orderState = UNPAID;
勾芒's avatar
勾芒 committed
335 336 337 338 339 340
                //商品ID
                NSArray *goodArray = [self.datasArray lastObject];
                NSMutableArray *goodidArr = [NSMutableArray array];
                for (int i=0; i<goodArray.count-1; i++) {
                    ShopcarModel *model = [goodArray objectAtIndex_opple:i];
                    TOOrderdetailEntity *orderGoods = [[TOOrderdetailEntity alloc]init];
勾芒's avatar
勾芒 committed
341
                    orderGoods.goodsId = model.goodsId;
勾芒's avatar
勾芒 committed
342 343 344 345 346
                    orderGoods.goodsCover = model.goods.pictures;
                    orderGoods.goodsCode = model.goods.code;
                    orderGoods.goodsSpec = model.goods.spec;
                    orderGoods.goodsName = model.goods.name;
                    orderGoods.goodsBrand = model.goods.brandId;
347
                    orderGoods.goodsNum = [NSString stringWithFormat:@"%ld",(long)model.goodsNum];
勾芒's avatar
勾芒 committed
348
                    orderGoods.goodsPrice = model.costPrice;
勾芒's avatar
勾芒 committed
349 350
                    orderGoods.remark = model.goods.spec;
                    orderGoods.goodsUnit = model.goods.unit;
351
                    orderGoods.attachmentUrl = model.attachmentUrl;
勾芒's avatar
勾芒 committed
352
                    //总价
勾芒's avatar
勾芒 committed
353
                    allPrice += model.goodsNum *[model.costPrice floatValue];
勾芒's avatar
勾芒 committed
354 355
                    //总数量
                    allNumber += model.goodsNum;
曹云霄's avatar
曹云霄 committed
356
                    orderGoods.goodsTotalPrice = [NSNumber numberWithFloat:model.goodsNum *[model.costPrice floatValue]];
勾芒's avatar
勾芒 committed
357 358
                    [goodidArr addObject:orderGoods];
                }
勾芒's avatar
勾芒 committed
359
                //总价
曹云霄's avatar
曹云霄 committed
360 361
                orderReceiver.orderPrice = [NSNumber numberWithFloat:allPrice];
                orderReceiver.oldPrice = [NSNumber numberWithFloat:allPrice];
勾芒's avatar
勾芒 committed
362 363
                //总数量
                orderReceiver.goodsNum = [NSString stringWithFormat:@"%ld",allNumber];
勾芒's avatar
勾芒 committed
364
                order.orderdetailList = (NSArray<TOOrderdetailEntity> *)goodidArr;
365 366 367 368 369
                order.order.isSuccessSend = NO;
                order.order.province = [Customermanager manager].model.province;
                order.order.city = [Customermanager manager].model.city;
                order.order.country = [Customermanager manager].model.country;
                order.order.storeNumber = [Shoppersmanager manager].shoppers.storeCode;
曹云霄's avatar
曹云霄 committed
370
                [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
371
                WS(weakSelf);
曹云霄's avatar
曹云霄 committed
372
                [HTTP networkRequestWithURL:SERVERREQUESTURL(CREATEORDER)  withRequestType:ZERO withParameter:order withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
373
                    [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
374
                    if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
375 376 377 378 379 380
                        //商品购物车id
                        NSMutableArray *codeArrray = [NSMutableArray array];
                        for (ShopcarModel *model in _settlementGoodsdatas) {
                            [codeArrray addObject:model.fid?model.fid:@" "];
                        }
                        //调用删除购物车
曹云霄's avatar
曹云霄 committed
381 382
                        if (weakSelf.DelecteSelectedGoods) {
                            weakSelf.DelecteSelectedGoods(codeArrray);
勾芒's avatar
勾芒 committed
383
                        }
曹云霄's avatar
曹云霄 committed
384
                        OrderdetailsViewController *orderDetails = [[[weakSelf class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
曹云霄's avatar
曹云霄 committed
385
                        orderDetails.orderCode = RESPONSE(returnValue);
勾芒's avatar
勾芒 committed
386
                        orderDetails.isShowPayButton = YES;
387
                        orderDetails.isUserInteractionEnabled = YES;
388
                        orderDetails.isShowHeaderView = YES;
勾芒's avatar
勾芒 committed
389
                        orderDetails.isSliding = YES;//取消滑动返回
曹云霄's avatar
曹云霄 committed
390
                        [weakSelf.navigationController pushViewController:orderDetails animated:YES];
勾芒's avatar
勾芒 committed
391
                        
勾芒's avatar
勾芒 committed
392 393
                    }else
                    {
394
                        [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
395
                    }
396
                }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
397 398
                    [XBLoadingView hideHUDViewWithDefault];
                    [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
399
                }];
勾芒's avatar
勾芒 committed
400 401
                return;
            }
勾芒's avatar
勾芒 committed
402 403
            else if (i == Adressarr.count -1)
            {
曹云霄's avatar
曹云霄 committed
404
               [XBLoadingView showHUDViewWithText:@"未选中地址"];
勾芒's avatar
勾芒 committed
405
            }
勾芒's avatar
勾芒 committed
406 407
        }
    }
曹云霄's avatar
曹云霄 committed
408 409 410 411
}


#pragma mark -返回购物车
412
- (IBAction)backShoppingBagsButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
413 414 415 416
    [self.navigationController popViewControllerAnimated:YES];
}


勾芒's avatar
勾芒 committed
417
#pragma mark -设置为当前地址回调
418
- (void)setCustomerButtonClick:(NSInteger)index;
勾芒's avatar
勾芒 committed
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
{
    for (UITableViewCell *cell in self.generateOrderTableview.visibleCells) {
        if ([cell isKindOfClass:[GenerateOrdersTableViewCell class]]) {
           GenerateOrdersTableViewCell *Newcell = (GenerateOrdersTableViewCell *)cell;
           Newcell.isSelectedButton.selected = NO;
        }
    }
    for (id objc in [self.datasArray objectAtIndex_opple:1]) {
        
        if ([objc isKindOfClass:[AddressModel class]]) {
            
            AddressModel *model = (AddressModel *)objc;
            model.isSelected = NO;
        }
    }
    AddressModel *model = [[self.datasArray objectAtIndex_opple:1] objectAtIndex_opple:index];
    model.isSelected = YES;
}

曹云霄's avatar
曹云霄 committed
438 439


勾芒's avatar
勾芒 committed
440
#pragma mark -修改地址
441
- (void)changeButtonClick
勾芒's avatar
勾芒 committed
442 443 444 445
{
    NSArray *arr = [self.datasArray objectAtIndex_opple:1];
    for (int i=0; i<arr.count; i++) {
        
446 447
        AddressModel *model = [arr objectAtIndex_opple:i];
        if ([model isKindOfClass:[AddressModel class]]) {
勾芒's avatar
勾芒 committed
448 449 450 451
            
            //判断是否为选中
            if (model.isSelected) {
                
452
                [self createModifyShippingView:[arr objectAtIndex_opple:i] Withindex:i];
453 454 455 456
                break;
            }else
            {
                if (i == arr.count-1) {
曹云霄's avatar
曹云霄 committed
457
                    [XBLoadingView showHUDViewWithText:@"请先勾选一个地址"];
458
                }
勾芒's avatar
勾芒 committed
459 460 461 462
            }
        }
    }
}
曹云霄's avatar
曹云霄 committed
463 464


勾芒's avatar
勾芒 committed
465
#pragma mark -新增地址
466
- (void)addAddressButtonClick
勾芒's avatar
勾芒 committed
467
{
468
    [self createModifyShippingView:nil Withindex:0];
勾芒's avatar
勾芒 committed
469 470 471 472 473 474 475 476 477 478
}


#pragma mark -新增地址回调
- (void)addAddressCell:(AddressModel *)model
{
    [self dismissViewControllerAnimated:YES completion:nil];
    [[self.datasArray objectAtIndex_opple:1]insertObject:model atIndex:0];
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:0 inSection:1];
    [self.generateOrderTableview insertRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationLeft];
479 480 481
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.generateOrderTableview reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
    });
勾芒's avatar
勾芒 committed
482 483
}

勾芒's avatar
勾芒 committed
484
#pragma mark -修改地址回调
485
- (void)changeAddresscell:(AddressModel *)model withcellindex:(NSInteger)cellindex
勾芒's avatar
勾芒 committed
486 487 488 489 490 491 492
{
    [self dismissViewControllerAnimated:YES completion:nil];
    [[self.datasArray objectAtIndex_opple:1]replaceObjectAtIndex:cellindex withObject:model];
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:cellindex inSection:1];
    [self.generateOrderTableview reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationLeft];
}

勾芒's avatar
勾芒 committed
493 494 495
#pragma mark -删除地址
- (void)delecteCell:(NSString *)addressid
{
496
    [self dismissViewControllerAnimated:YES completion:nil];
勾芒's avatar
勾芒 committed
497 498 499 500 501 502 503 504 505 506 507 508
    NSArray *arr = [self.datasArray objectAtIndex_opple:1];
    for (int i=0; i<arr.count; i++) {
        
        if ([[arr objectAtIndex_opple:i] isKindOfClass:[AddressModel class]]) {
            
            AddressModel *model = [arr objectAtIndex_opple:i];
            //判断是否为选中
            if ([model.fid isEqualToString:addressid]) {
                
                [[self.datasArray objectAtIndex_opple:1] removeObjectAtIndex:i];
                NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:1];
                [self.generateOrderTableview deleteRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationLeft];
509 510 511 512
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.generateOrderTableview reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
                });
                break;
勾芒's avatar
勾芒 committed
513 514 515 516
            }
        }
    }
}
曹云霄's avatar
曹云霄 committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533

- (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.
}
*/

@end