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

#import "CustomerOrderViewController.h"
#import "CustomerOrderTableViewCell.h"
#import "OrderdetailsViewController.h"
12
@interface CustomerOrderViewController ()<UITableViewDataSource,UITableViewDelegate,ReturnTableviewcellIndexpathdelegate,UITextFieldDelegate,undoOrderDelegate>
曹云霄's avatar
曹云霄 committed
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

/**
 *  数据源数组
 */
@property (nonatomic,strong) NSMutableArray *datasArray;

/**
 *  订单状态数组
 */
@property (nonatomic,strong) NSArray *orderStateArray;


@end

@implementation CustomerOrderViewController


/**
 *  初始化数据源数组
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
        _datasArray = [NSMutableArray array];
    }
    return _datasArray;
}

/**
 *  订单状态数组
 */
- (NSArray *)orderStateArray
{
    if (_orderStateArray == nil) {
        _orderStateArray = [NSArray arrayWithObjects:@"全部订单",@"待支付",@"已支付",@"已发货",@"已完成",@"已撤销",@"已退货", nil];
    }
    return _orderStateArray;
}

- (OrderFilter *)model
{
    if (!_model) {
        _model = [[OrderFilter alloc]init];
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _model.dp = page;
        //经销商代码
        _model.resellerCodeEquals = [[Shoppersmanager manager].shoppers.employee.currentDepart  orgCode];
    }
    return _model;
}

#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

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

#pragma mark -UI
- (void)uiConfigAction
{
    self.searchCustomerOrder.delegate = self;
    self.styleButton = [ScreeningButton buttonWithType:UIButtonTypeCustom];
    self.styleButton.frame = CGRectMake(ScreenWidth-250, 20, 150, 30);
    self.styleButton.backgroundColor = RGB(131, 131, 131,1);
    [self.styleButton setTitle:@"订单状态" forState:UIControlStateNormal];
    [self.styleButton addTarget:self action:@selector(OrderStateButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.styleButton setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
102
    [self.styleButton addCorner:10];
曹云霄's avatar
曹云霄 committed
103 104 105
    [self.orderStateBackView addSubview:self.styleButton];
}

106 107
#pragma mark -加载数据
- (void)loadWebDataSource
曹云霄's avatar
曹云霄 committed
108 109
{
    WS(weakSelf);
110 111 112 113 114 115 116 117 118
    if (self.pullPageIndex == ONE) {
        [self.datasArray removeAllObjects];
    }
    self.model.dp.page = self.pullPageIndex;
    [self getGuideAllcustomerOrder:self.model completed:^(OrderResponse *result) {
        if (weakSelf.pullPageIndex >= result.totalpages) {
            [weakSelf endRefresh:EndRefreshNotData];
        }else {
            [weakSelf endRefresh:EndRefreshDefault];
曹云霄's avatar
曹云霄 committed
119 120 121 122 123
        }
    }];
}


124 125
#pragma mark -获取导购下客户订单
- (void)getGuideAllcustomerOrder:(OrderFilter *)allOrder completed:(void(^)(OrderResponse *result))completed
曹云霄's avatar
曹云霄 committed
126 127 128 129
{
    WS(weakSelf);
    [HTTP networkRequestWithURL:SERVERREQUESTURL(QUERYORDER)  withRequestType:ZERO withParameter:allOrder withReturnValueBlock:^(id returnValue) {
        if (RESULT(returnValue)) {
130 131 132
            OrderResponse *allorder = [[OrderResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            completed(allorder);
            for (OrderBill *model in allorder.orderBillList) {
曹云霄's avatar
曹云霄 committed
133 134
                [weakSelf.datasArray addObject:model];
            }
135
            [weakSelf.tableView reloadData];
曹云霄's avatar
曹云霄 committed
136 137 138 139
        }else
        {
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
140 141 142
    }withFailureBlock:^(NSError *error) {
        [weakSelf endRefresh:EndRefreshDefault];
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    }];
}

#pragma mark -订单状态筛选
- (void)OrderStateButtonClick:(UIButton *)button
{
    [self showPopoverViewController:CGSizeMake(200, 400) withDatas:self.orderStateArray showButton:button selectedIndex:0];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomerOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customerordercell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.cellBackView.layer.masksToBounds = YES;
曹云霄's avatar
曹云霄 committed
158
    cell.model = [self.datasArray objectAtIndex_opple:indexPath.row];
曹云霄's avatar
曹云霄 committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    cell.cellBackView.layer.cornerRadius = kCornerRadius;
    cell.backgroundColor = [UIColor clearColor];
    cell.cellIndex = indexPath.row;
    cell.delegate = self;
    return cell;
}

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

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
178
    OrderdetailsViewController *orderdetails = [OrderdetailsViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
曹云霄's avatar
曹云霄 committed
179
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:indexPath.row] order];
曹云霄's avatar
曹云霄 committed
180 181
    orderdetails.orderCode = model.orderNumber;
    orderdetails.consumerID = model.consumerId;
182 183
    if ([model.orderState isEqualToString:COMPLETED] || [model.orderState isEqualToString:PAID] || [model.orderState isEqualToString:SHIPPED]) {
        orderdetails.isShowShareButton = YES;
曹云霄's avatar
曹云霄 committed
184 185 186 187
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
        orderdetails.isUserInteractionEnabled = NO;
        
188
    } else if ([model.orderState isEqualToString:UNPAID]) {//未付款
曹云霄's avatar
曹云霄 committed
189
        orderdetails.isShowPayButton = YES;
190
        orderdetails.isShowShareButton = YES;
曹云霄's avatar
曹云霄 committed
191 192 193 194 195 196 197
        orderdetails.isShowHeaderView = YES;
        orderdetails.isUserInteractionEnabled = YES;
        
    }else{
        orderdetails.isShowHeaderView = NO;
    }
    //撤销、支付回调
198
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
199
    [orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
曹云霄's avatar
曹云霄 committed
200
        OrderBill *model = [self.datasArray objectAtIndex_opple:cellindex];
曹云霄's avatar
曹云霄 committed
201 202
        model.order.orderState = orderSate;
        NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
203
        [weakSelf.tableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
曹云霄's avatar
曹云霄 committed
204
    }];
205
    [self pushViewController:orderdetails animated:YES];
曹云霄's avatar
曹云霄 committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
}

#pragma mark -弹出popover视图控制器
- (void)showPopoverViewController:(CGSize)size withDatas:(NSArray *)datasArray showButton:(UIButton *)button selectedIndex:(NSInteger)index
{
    PopoverViewController *popover = [[PopoverViewController alloc]init];
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.isString = YES;
    popover.selectedindex = index;
    popover.contentSize = size;
    popover.preferredContentSize = size;
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = popover.view;
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    [self presentViewController:popover animated:YES completion:nil];
}

#pragma mark -选中代理
/**
 *  选中筛选条件对象typecode
 *
 *  @param index NSString
 */
- (void)returnCellindexpathwithrow:(NSString *)type withCellTitle:(NSString *)title withSelected:(NSInteger)selected
{
    [self.styleButton setTitle:title forState:UIControlStateNormal];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    NSString *orderState = nil;
    //全部订单
    if ([title isEqualToString:@"全部订单"]) {
        orderState = nil;
    }
    //待支付
    else if ([title isEqualToString:@"待支付"]) {
        orderState = @"001";
    }
    //已支付
   else if ([title isEqualToString:@"已支付"]) {
        orderState = @"002";
    }
    //已发货
   else  if ([title isEqualToString:@"已发货"]) {
        orderState = @"003";
    }
    //已完成
   else if ([title isEqualToString:@"已完成"]) {
        orderState = @"006";
    }
    //已撤销
   else if ([title isEqualToString:@"已撤销"]) {
        orderState = @"005";
    }
    //已退货
   else if ([title isEqualToString:@"已退货"]) {
        orderState = @"004";
    }
    self.model.consumerNameOrMobileEquals = nil;
    self.model.orderStateEquals = orderState;
268
    [self.tableView.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
269 270 271 272 273 274 275 276 277
}


#pragma mark -Search点击
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    self.model.consumerNameOrMobileEquals = textField.text;
    self.model.orderStateEquals = nil;
278
    [self.tableView.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
279 280 281 282 283 284 285 286 287 288 289 290 291
    return YES;
}


#pragma mark -撤销订单
- (void)undoOrderButtonClick:(NSInteger)cellindex
{
    WS(weakSelf);
    ShowAlertView(@"提示", @"请确认是否撤销订单", @[@"确认",@"取消"], UIAlertControllerStyleAlert, ^(NSInteger index) {
        if (index == ONE) {
            return;
        }
        [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
292
        OrderBill *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
曹云霄's avatar
曹云霄 committed
293 294 295 296 297 298 299
        [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),model.order.orderNumber,model.order.orderState,@"005"]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
            
            [XBLoadingView hideHUDViewWithDefault];
            if (RESULT(returnValue)) {
                [XBLoadingView showHUDViewWithSuccessText:@"撤销成功" completeBlock:nil];
                model.order.orderState = @"005";
                NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
300
                [weakSelf.tableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationLeft];
曹云霄's avatar
曹云霄 committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            }else{
                [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
            }
        }withFailureBlock:^(NSError *error) {
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
        }];
    });
}



#pragma mark -去支付
- (void)TopayButtonClick:(NSInteger)cellindex
{
316
    OrderdetailsViewController *orderdetails = [OrderdetailsViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
曹云霄's avatar
曹云霄 committed
317
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:cellindex] order];
曹云霄's avatar
曹云霄 committed
318
    orderdetails.orderCode = model.orderNumber;
319 320
    if ([model.orderState isEqualToString:COMPLETED] || [model.orderState isEqualToString:PAID] || [model.orderState isEqualToString:SHIPPED]) {
        orderdetails.isShowShareButton = YES;
曹云霄's avatar
曹云霄 committed
321 322 323 324
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
        orderdetails.isUserInteractionEnabled = NO;
        
325
    } else if ([model.orderState isEqualToString:UNPAID]) {//未付款
曹云霄's avatar
曹云霄 committed
326
        orderdetails.isShowPayButton = YES;
327
        orderdetails.isShowShareButton = YES;
曹云霄's avatar
曹云霄 committed
328 329 330 331 332 333 334 335 336
        orderdetails.isShowHeaderView = YES;
        orderdetails.isUserInteractionEnabled = YES;
        
    }else{
        orderdetails.isShowHeaderView = NO;
    }
    //撤销、支付回调
    [orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
        
曹云霄's avatar
曹云霄 committed
337
        OrderBill *model = [self.datasArray objectAtIndex_opple:cellindex];
曹云霄's avatar
曹云霄 committed
338 339
        model.order.orderState = orderSate;
        NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
340
        [self.tableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
曹云霄's avatar
曹云霄 committed
341 342
        
    }];
343
    [self pushViewController:orderdetails animated:YES];
曹云霄's avatar
曹云霄 committed
344 345 346 347 348
}



@end