GenerateOrdersViewController.m 21.6 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//
//  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 "ModifyShippingAddressView.h"
#import "AppDelegate.h"
#import "OrderdetailsViewController.h"
曹云霄's avatar
曹云霄 committed
19
#import "AddressViewController.h"
勾芒's avatar
勾芒 committed
20 21
#import "AddressModel.h"
@interface GenerateOrdersViewController ()<UITableViewDelegate,UITableViewDataSource,delecteDelegate>
曹云霄's avatar
曹云霄 committed
22 23 24 25 26 27

/**
 *  增加或者修改地址
 */
@property (nonatomic,strong) ModifyShippingAddressView *addressView;

勾芒's avatar
勾芒 committed
28 29 30 31 32 33
/**
 *  数据源
 */
@property (nonatomic,strong) NSMutableArray *datasArray;


曹云霄's avatar
曹云霄 committed
34 35 36 37 38
@property (nonatomic,strong) UIView *Tabbarview;
@end

@implementation GenerateOrdersViewController

勾芒's avatar
勾芒 committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
 *  初始化数据源
 */
- (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
55 56
        AddressModel *model = [[AddressModel alloc]init];
        model.name = @"地址占位";
勾芒's avatar
勾芒 committed
57
        //地址占位
勾芒's avatar
勾芒 committed
58
        [[_datasArray objectAtIndex_opple:1] addObject:model];
勾芒's avatar
勾芒 committed
59 60 61 62 63 64 65
        
        //加入商品信息
        [_datasArray replaceObjectAtIndex:2 withObject:_settlementGoodsdatas];
    }
    
    return _datasArray;
}
曹云霄's avatar
曹云霄 committed
66 67


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

勾芒's avatar
勾芒 committed
77 78 79 80 81 82
}

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

勾芒's avatar
勾芒 committed
88
}
曹云霄's avatar
曹云霄 committed
89

曹云霄's avatar
曹云霄 committed
90 91 92 93
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
94
    [self getAddressDatasRequest];
曹云霄's avatar
曹云霄 committed
95 96 97 98 99 100 101 102
}

#pragma mark -UI
- (void)uiConfigAction
{
    self.generateOrderTableview.dataSource = self;
    self.generateOrderTableview.delegate = self;
    self.generateOrderTableview.tableFooterView = [UIView new];
勾芒's avatar
勾芒 committed
103 104 105 106
    self.backShoppingbagsButton.layer.masksToBounds = YES;
    self.backShoppingbagsButton.layer.cornerRadius = kCornerRadius;
    self.createOrderButton.layer.masksToBounds = YES;
    self.createOrderButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
107 108 109
}


勾芒's avatar
勾芒 committed
110 111 112
#pragma mark -获得地址信息
- (void)getAddressDatasRequest
{
勾芒's avatar
勾芒 committed
113
    [self CreateMBProgressHUDLoding];
114 115
    WS(weakSelf);
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(SHIPPINGADDRESS),[Customermanager manager].model.fid] WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
116
        
117
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
118 119 120
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
         
            RsShippingAddrEntity *address = [[RsShippingAddrEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
121
            
勾芒's avatar
勾芒 committed
122 123 124
            for (NSInteger i=address.list.count-1; i>=0; i--) {
                
                TOShippingAddrEntity *model = [address.list objectAtIndex_opple:i];
勾芒's avatar
勾芒 committed
125 126 127 128 129 130 131 132 133 134 135 136 137
                //自定义model
                AddressModel *Newmodel = [[AddressModel alloc]init];
                Newmodel.fid = model.fid;
                Newmodel.createDate = model.createDate;
                Newmodel.sysOrgCode = model.sysOrgCode;
                Newmodel.name = model.name;
                Newmodel.miblephone = model.miblephone;
                Newmodel.province = model.province;
                Newmodel.city = model.city;
                Newmodel.country = model.country;
                Newmodel.consumerId = model.consumerId;
                Newmodel.address = model.address;
                
138
                [[weakSelf.datasArray objectAtIndex_opple:1]insertObject:Newmodel atIndex:0];
勾芒's avatar
勾芒 committed
139 140
            }
            
勾芒's avatar
勾芒 committed
141
            //地址数组
142
            NSArray *addressArray = [weakSelf.datasArray objectAtIndex_opple:1];
勾芒's avatar
勾芒 committed
143 144 145 146 147 148
            //增加cell
            NSMutableArray *addCellArray = [NSMutableArray array];
            for (int i=0; i<addressArray.count-1; i++) {
                NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:1];
                [addCellArray addObject:indexpath];
            }
149
            [weakSelf.generateOrderTableview insertRowsAtIndexPaths:addCellArray withRowAnimation:UITableViewRowAnimationBottom];
勾芒's avatar
勾芒 committed
150 151 152
        }
        else
        {
153
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
154 155 156
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
157 158
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
勾芒's avatar
勾芒 committed
159
        
160 161 162
    } WithFailureBlock:^(NSError *error) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
163 164 165
    }];
}

曹云霄's avatar
曹云霄 committed
166 167 168 169 170 171 172 173


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
174
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
175 176 177 178
        return cell;
    }
    else if (indexPath.section == 1)
    {
勾芒's avatar
勾芒 committed
179 180 181
        NSArray *Addressarr = [self.datasArray objectAtIndex_opple:indexPath.section];
        if (indexPath.row == Addressarr.count-1) {
            
勾芒's avatar
勾芒 committed
182 183 184 185
            GenerateOrdersModifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Modifycell" forIndexPath:indexPath];
            //增加地址或者修改
            [cell.addAddressButton addTarget:self action:@selector(AddAddressButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.changeButton addTarget:self action:@selector(ChangeButtonClick) forControlEvents:UIControlEventTouchUpInside];
勾芒's avatar
勾芒 committed
186
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
187
            cell.backgroundColor = kTCColor(242, 242, 242);
曹云霄's avatar
曹云霄 committed
188 189
            return cell;
        }
勾芒's avatar
勾芒 committed
190
        GenerateOrdersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"consigneecell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
191 192
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = kTCColor(242, 242, 242);
勾芒's avatar
勾芒 committed
193 194
        cell.indexNumber = indexPath.row;
        //回调
195
        __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
196 197
        [cell setBlockSeletced:^(NSInteger index) {
            
198
            [weakSelf SetCustomerButtonClick:index];
勾芒's avatar
勾芒 committed
199 200
        }];
        cell.NewModel = [self.datasArray objectAtIndex_opple:indexPath.section][indexPath.row];
曹云霄's avatar
曹云霄 committed
201 202
        return cell;
    }
曹云霄's avatar
曹云霄 committed
203 204 205 206
    NSArray *Addressarr = [self.datasArray objectAtIndex_opple:indexPath.section];
    if (indexPath.row == Addressarr.count-1) {
        
        AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
207
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
208
        cell.goodsAllprice = [self.datasArray objectAtIndex_opple:indexPath.section];
曹云霄's avatar
曹云霄 committed
209 210
        return cell;
    }
曹云霄's avatar
曹云霄 committed
211 212 213 214
    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
215 216 217 218 219
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
220 221
    NSArray *arr = [self.datasArray objectAtIndex_opple:section];
    return arr.count;
曹云霄's avatar
曹云霄 committed
222 223 224 225 226 227 228 229
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
勾芒's avatar
勾芒 committed
230
            return 110;
曹云霄's avatar
曹云霄 committed
231 232 233 234
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
235 236 237 238 239
            NSArray *arr = [self.datasArray objectAtIndex_opple:indexPath.section];
            if (indexPath.row == arr.count-1) {
                
                return 70;
            }
曹云霄's avatar
曹云霄 committed
240 241 242 243 244
            return 56;
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
245 246
            NSArray *arr = [self.datasArray objectAtIndex_opple:indexPath.section];
            if (indexPath.row == arr.count-1) {
曹云霄's avatar
曹云霄 committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
                
                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
270
            return 5;
曹云霄's avatar
曹云霄 committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
        }
            break;
        case 2:
        {
            return 44;
        }
            break;
            
        default:
            break;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
287 288 289
    switch (section) {
        case 1:
        {
勾芒's avatar
勾芒 committed
290
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 5)];
勾芒's avatar
勾芒 committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            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)];
            lineView.backgroundColor = kTCColor(242, 242, 242);
            [view addSubview:lineView];
            return view;
        }
            break;
            
        default:
            break;
    }
    return nil;
曹云霄's avatar
曹云霄 committed
316 317 318 319 320 321
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
322
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
323 324
}

勾芒's avatar
勾芒 committed
325

曹云霄's avatar
曹云霄 committed
326 327 328


#pragma mark -新增或者修改收货地址
勾芒's avatar
勾芒 committed
329
- (void)CreateModifyShippingView:(AddressModel *)model Withindex:(NSInteger)cellindex
曹云霄's avatar
曹云霄 committed
330 331
{
    
曹云霄's avatar
曹云霄 committed
332
    AddressViewController *address = [[AddressViewController alloc]init];
勾芒's avatar
勾芒 committed
333 334 335 336 337 338
    address.delegate = self;
    if (model != nil) {
        
        address.model = model;
        address.isChange = YES;
    }
勾芒's avatar
勾芒 committed
339
    address.cellindex = cellindex;
曹云霄's avatar
曹云霄 committed
340 341 342 343 344 345
    address.preferredContentSize = CGSizeMake(315, 320);
    address.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = address.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = address.view;
    [self presentViewController:address animated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
346 347 348 349 350 351 352 353
}




#pragma mark -生成订单
- (IBAction)CreateOrderButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
354
    OrderBill *order = [[OrderBill alloc]init];
勾芒's avatar
勾芒 committed
355
    //分页
勾芒's avatar
勾芒 committed
356
    DataPage *page = [[DataPage alloc]init];
曹云霄's avatar
曹云霄 committed
357
    page.page = ONE;
勾芒's avatar
勾芒 committed
358 359
    order.datapage = page;
    //收货地址
勾芒's avatar
勾芒 committed
360
    TOOrderEntity *orderReceiver = [[TOOrderEntity alloc]init];
勾芒's avatar
勾芒 committed
361
    NSArray *Adressarr = [self.datasArray objectAtIndex_opple:1];
勾芒's avatar
勾芒 committed
362
    //总价格
曹云霄's avatar
曹云霄 committed
363
    CGFloat allPrice = ZERO;
勾芒's avatar
勾芒 committed
364
    //总数量
曹云霄's avatar
曹云霄 committed
365
    NSInteger allNumber = ZERO;
勾芒's avatar
勾芒 committed
366 367 368 369
    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
370
                //收货人信息
勾芒's avatar
勾芒 committed
371
                orderReceiver.receiverName = model.name;
勾芒's avatar
勾芒 committed
372
                orderReceiver.orderTime = [self GetCurrenttime];
勾芒's avatar
勾芒 committed
373 374
                orderReceiver.receiverMobile = model.miblephone;
                orderReceiver.receiverAddress = model.address;
勾芒's avatar
勾芒 committed
375 376
                order.order = orderReceiver;
                orderReceiver.guideId = [[Shoppersmanager manager] Shoppers].employee.fid;
勾芒's avatar
勾芒 committed
377
                orderReceiver.consumerId = [Customermanager manager].model.fid;
勾芒's avatar
勾芒 committed
378
                orderReceiver.orderState = @"001";
勾芒's avatar
勾芒 committed
379 380 381 382 383 384
                //商品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
385
                    orderGoods.goodsId = model.goodsId;
勾芒's avatar
勾芒 committed
386 387 388 389 390
                    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;
391
                    orderGoods.goodsNum = [NSString stringWithFormat:@"%ld",(long)model.goodsNum];
勾芒's avatar
勾芒 committed
392
                    orderGoods.goodsPrice = model.costPrice;
勾芒's avatar
勾芒 committed
393 394
                    orderGoods.remark = model.goods.spec;
                    orderGoods.goodsUnit = model.goods.unit;
勾芒's avatar
勾芒 committed
395
                    //总价
勾芒's avatar
勾芒 committed
396
                    allPrice += model.goodsNum *[model.costPrice floatValue];
勾芒's avatar
勾芒 committed
397 398
                    //总数量
                    allNumber += model.goodsNum;
曹云霄's avatar
曹云霄 committed
399
                    orderGoods.goodsTotalPrice = [NSNumber numberWithFloat:model.goodsNum *[model.costPrice floatValue]];
勾芒's avatar
勾芒 committed
400 401
                    [goodidArr addObject:orderGoods];
                }
勾芒's avatar
勾芒 committed
402
                //总价
曹云霄's avatar
曹云霄 committed
403 404
                orderReceiver.orderPrice = [NSNumber numberWithFloat:allPrice];
                orderReceiver.oldPrice = [NSNumber numberWithFloat:allPrice];
勾芒's avatar
勾芒 committed
405 406
                //总数量
                orderReceiver.goodsNum = [NSString stringWithFormat:@"%ld",allNumber];
勾芒's avatar
勾芒 committed
407
                order.orderdetailList = (NSArray<TOOrderdetailEntity> *)goodidArr;
勾芒's avatar
勾芒 committed
408
                [self CreateMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
409
                WS(weakSelf);
410
                [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CREATEORDER) WithCallClass:weakSelf WithRequestType:0 WithParameter:order WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
411
                    [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
412
                    if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
413 414 415 416 417 418
                        //商品购物车id
                        NSMutableArray *codeArrray = [NSMutableArray array];
                        for (ShopcarModel *model in _settlementGoodsdatas) {
                            [codeArrray addObject:model.fid?model.fid:@" "];
                        }
                        //调用删除购物车
曹云霄's avatar
曹云霄 committed
419 420
                        if (weakSelf.DelecteSelectedGoods) {
                            weakSelf.DelecteSelectedGoods(codeArrray);
勾芒's avatar
勾芒 committed
421
                        }
曹云霄's avatar
曹云霄 committed
422
                        OrderdetailsViewController *orderDetails = [[[weakSelf class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
勾芒's avatar
勾芒 committed
423
                        orderDetails.orderCode = returnValue[@"data"];
勾芒's avatar
勾芒 committed
424
                        orderDetails.isShowPayButton = YES;
425
                        orderDetails.isUserInteractionEnabled = YES;
426
                        orderDetails.isShowHeaderView = YES;
勾芒's avatar
勾芒 committed
427
                        orderDetails.isSliding = YES;//取消滑动返回
曹云霄's avatar
曹云霄 committed
428
                        [weakSelf.navigationController pushViewController:orderDetails animated:YES];
勾芒's avatar
勾芒 committed
429
                        
勾芒's avatar
勾芒 committed
430 431
                    }else
                    {
曹云霄's avatar
曹云霄 committed
432
                        [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
433 434
                    }
                } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
435
                    [weakSelf RemoveMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
436 437
                    [weakSelf ErrorMBProgressView:NETWORK];
                } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
438
                    [weakSelf RemoveMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
439
                    [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
440
                }];
勾芒's avatar
勾芒 committed
441 442
                return;
            }
勾芒's avatar
勾芒 committed
443 444 445 446
            else if (i == Adressarr.count -1)
            {
               [self ErrorMBProgressView:@"未选中地址"];
            }
勾芒's avatar
勾芒 committed
447 448
        }
    }
曹云霄's avatar
曹云霄 committed
449 450 451
}


勾芒's avatar
勾芒 committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
#pragma mark -获取当前日期
- (NSString *)GetCurrenttime
{
    NSDate *date = [[NSDate alloc] init];
    //获取一下当前的时区
     NSTimeZone *zone=[NSTimeZone timeZoneWithName:@"UTC"];
    //根据对应的时区,获取和0时区相差的秒数
    NSInteger seconds = [zone secondsFromGMTForDate:date];
    //获取当前的时间
    NSDate *localDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *datetime = [formatter stringFromDate:localDate];
    return datetime;
}

曹云霄's avatar
曹云霄 committed
468 469 470 471 472 473 474 475
#pragma mark -返回购物车

- (IBAction)BackShoppingBagsButtonClick:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}


勾芒's avatar
勾芒 committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
#pragma mark -设置为当前地址回调
- (void)SetCustomerButtonClick:(NSInteger)index;
{
    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
497 498


勾芒's avatar
勾芒 committed
499 500 501 502 503 504
#pragma mark -修改地址
- (void)ChangeButtonClick
{
    NSArray *arr = [self.datasArray objectAtIndex_opple:1];
    for (int i=0; i<arr.count; i++) {
        
505 506
        AddressModel *model = [arr objectAtIndex_opple:i];
        if ([model isKindOfClass:[AddressModel class]]) {
勾芒's avatar
勾芒 committed
507 508 509 510
            
            //判断是否为选中
            if (model.isSelected) {
                
勾芒's avatar
勾芒 committed
511
                [self CreateModifyShippingView:[arr objectAtIndex_opple:i] Withindex:i];
512 513 514 515 516 517
                break;
            }else
            {
                if (i == arr.count-1) {
                    [self ErrorMBProgressView:@"请先勾选一个地址"];
                }
勾芒's avatar
勾芒 committed
518 519 520 521
            }
        }
    }
}
曹云霄's avatar
曹云霄 committed
522 523


勾芒's avatar
勾芒 committed
524 525 526
#pragma mark -新增地址
- (void)AddAddressButtonClick
{
勾芒's avatar
勾芒 committed
527
    [self CreateModifyShippingView:nil Withindex:0];
勾芒's avatar
勾芒 committed
528 529 530 531 532 533 534 535 536 537
}


#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];
538 539 540
    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
541 542
}

勾芒's avatar
勾芒 committed
543 544 545 546 547 548 549 550 551
#pragma mark -修改地址回调
- (void)ChangeAddresscell:(AddressModel *)model Withcellindex:(NSInteger)cellindex
{
    [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
552 553 554
#pragma mark -删除地址
- (void)delecteCell:(NSString *)addressid
{
555
    [self dismissViewControllerAnimated:YES completion:nil];
勾芒's avatar
勾芒 committed
556 557 558 559 560 561 562 563 564 565 566 567
    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];
568 569 570 571
                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
572 573 574 575
            }
        }
    }
}
曹云霄's avatar
曹云霄 committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592

- (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