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

#import "CustomerOrderViewController.h"
#import "CustomerOrderTableViewCell.h"
勾芒's avatar
勾芒 committed
11
#import "OrderdetailsViewController.h"
曹云霄's avatar
曹云霄 committed
12
@interface CustomerOrderViewController ()<UITableViewDataSource,UITableViewDelegate,ReturnTableviewcellIndexpathdelegate,UITextFieldDelegate,undoOrderDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
曹云霄's avatar
曹云霄 committed
13

勾芒's avatar
勾芒 committed
14 15 16 17 18
/**
 *  数据源数组
 */
@property (nonatomic,strong) NSMutableArray *datasArray;

勾芒's avatar
勾芒 committed
19 20 21 22 23
/**
 *  订单状态数组
 */
@property (nonatomic,strong) NSArray *orderStateArray;

勾芒's avatar
勾芒 committed
24 25 26 27 28
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

曹云霄's avatar
曹云霄 committed
29

勾芒's avatar
勾芒 committed
30

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

@implementation CustomerOrderViewController

勾芒's avatar
勾芒 committed
35 36 37 38 39 40 41 42 43 44 45 46

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

勾芒's avatar
勾芒 committed
47 48 49 50 51 52 53 54 55 56
/**
 *  订单状态数组
 */
- (NSArray *)orderStateArray
{
    if (_orderStateArray == nil) {
        _orderStateArray = [NSArray arrayWithObjects:@"全部订单",@"待支付",@"已支付",@"已发货",@"已完成",@"已撤销",@"已退货", nil];
    }
    return _orderStateArray;
}
勾芒's avatar
勾芒 committed
57

58
- (OrderFilter *)model
59 60
{
    if (!_model) {
61
        _model = [[OrderFilter alloc]init];
62 63 64 65
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _model.dp = page;
66 67 68 69
    }
    return _model;
}

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#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;
    }
}

曹云霄's avatar
曹云霄 committed
90 91 92 93 94
- (void)viewDidLoad {
    [super viewDidLoad];
    [self uiConfigAction];
}

勾芒's avatar
勾芒 committed
95 96 97

#pragma mark -UI
- (void)uiConfigAction
曹云霄's avatar
曹云霄 committed
98
{
勾芒's avatar
勾芒 committed
99 100 101 102 103
    self.searchCustomerOrder.delegate = self;
    self.view.backgroundColor = kTCColor(238, 238, 238);
    self.customerOrderTableView.dataSource = self;
    self.customerOrderTableView.delegate = self;
    self.customerOrderTableView.backgroundColor = [UIColor clearColor];
104 105 106 107 108 109 110 111 112
    self.styleButton = [ScreeningButton buttonWithType:UIButtonTypeCustom];
    self.styleButton.frame = CGRectMake(ScreenWidth-250, 20, 150, 30);
    self.styleButton.backgroundColor = kTCColor(131, 131, 131);
    [self.styleButton setTitle:@"订单状态" forState:UIControlStateNormal];
    [self.styleButton addTarget:self action:@selector(OrderStateButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.styleButton setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
    self.styleButton.layer.masksToBounds = YES;
    self.styleButton.layer.cornerRadius = 10;
    [self.orderStateBackView addSubview:self.styleButton];
113 114
    //经销商代码
    self.model.resellerCodeEquals = [[Shoppersmanager manager].Shoppers.employee.currentDepart  orgCode];
勾芒's avatar
勾芒 committed
115
    //下拉刷新
116
    WS(weakSelf);
勾芒's avatar
勾芒 committed
117
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
勾芒's avatar
勾芒 committed
118
        
119 120
        [weakSelf.customerOrderTableView.mj_footer resetNoMoreData];
        [weakSelf getGuideAllcustomerOrder:YES WithorderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
121
    }];
勾芒's avatar
勾芒 committed
122 123 124
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.customerOrderTableView.mj_header = headerRefresh;
勾芒's avatar
勾芒 committed
125 126 127 128
    [self.customerOrderTableView.mj_header beginRefreshing];
    //上拉加载
    self.customerOrderTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
129
        if ( ++ weakSelf.model.dp.page > weakSelf.totalPages) {
130
            [weakSelf.customerOrderTableView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
131 132
        }else
        {
133
            [weakSelf getGuideAllcustomerOrder:NO WithorderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
134
        }
勾芒's avatar
勾芒 committed
135
    }];
曹云霄's avatar
曹云霄 committed
136
    self.customerOrderTableView.mj_footer.automaticallyHidden = YES;
勾芒's avatar
勾芒 committed
137 138 139
}


勾芒's avatar
勾芒 committed
140
#pragma mark -获取导购下客户订单  ----isdelecte 表示是否清空数组
141
- (void)getGuideAllcustomerOrder:(BOOL)isdelecte WithorderBill:(OrderFilter *)allOrder
勾芒's avatar
勾芒 committed
142
{
曹云霄's avatar
曹云霄 committed
143
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
144
    WS(weakSelf);
145
    [[NetworkRequestClassManager manager] networkRequestWithURL:SERVERREQUESTURL(QUERYORDER)  withRequestType:ZERO withParameter:allOrder withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
146
        
曹云霄's avatar
曹云霄 committed
147 148
        weakSelf.customerOrderTableView.emptyDataSetSource = weakSelf;
        weakSelf.customerOrderTableView.emptyDataSetDelegate = weakSelf;
曹云霄's avatar
曹云霄 committed
149
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
150
        [weakSelf endRefreshingForTableView:weakSelf.customerOrderTableView];
勾芒's avatar
勾芒 committed
151 152
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
勾芒's avatar
勾芒 committed
153
            if (isdelecte) {
曹云霄's avatar
曹云霄 committed
154
                [weakSelf.datasArray removeAllObjects];
勾芒's avatar
勾芒 committed
155
            }
勾芒's avatar
勾芒 committed
156
            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
曹云霄's avatar
曹云霄 committed
157
            weakSelf.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
158
            for (OrderBill *model in Allorder.orderBillList) {
曹云霄's avatar
曹云霄 committed
159
                [weakSelf.datasArray addObject:model];
勾芒's avatar
勾芒 committed
160
            }
曹云霄's avatar
曹云霄 committed
161
            [weakSelf.customerOrderTableView reloadData];
勾芒's avatar
勾芒 committed
162 163
        }else
        {
曹云霄's avatar
曹云霄 committed
164
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
165
        }
166
    }withFailureBlock:^(id error) {
曹云霄's avatar
曹云霄 committed
167
        [weakSelf endRefreshingForTableView:weakSelf.customerOrderTableView];
曹云霄's avatar
曹云霄 committed
168
        [XBLoadingView hideHUDViewWithDefault];
勾芒's avatar
勾芒 committed
169 170 171 172
    }];
}

#pragma mark -订单状态筛选
勾芒's avatar
勾芒 committed
173
- (void)OrderStateButtonClick:(UIButton *)button
勾芒's avatar
勾芒 committed
174
{
175
    [self showPopoverViewController:CGSizeMake(200, 400) withDatas:self.orderStateArray showButton:button selectedIndex:0];
曹云霄's avatar
曹云霄 committed
176 177
}

勾芒's avatar
勾芒 committed
178

曹云霄's avatar
曹云霄 committed
179 180 181 182 183
- (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
184
    cell.model = [self.datasArray objectAtIndex_opple:indexPath.row];
曹云霄's avatar
曹云霄 committed
185
    cell.cellBackView.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
186 187 188
    cell.backgroundColor = [UIColor clearColor];
    cell.cellIndex = indexPath.row;
    cell.delegate = self;
曹云霄's avatar
曹云霄 committed
189 190 191 192 193
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
194
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
195 196 197 198 199 200 201
}

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

勾芒's avatar
勾芒 committed
202 203
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
204
    OrderdetailsViewController *orderdetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
205
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:indexPath.row] order];
勾芒's avatar
勾芒 committed
206
    orderdetails.orderCode = model.orderNumber;
207
    orderdetails.consumerID = model.consumerId;
曹云霄's avatar
曹云霄 committed
208
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
209
        orderdetails.isShowPrintButton = YES;
210 211
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
212
        orderdetails.isUserInteractionEnabled = NO;
213 214
        
    } else if ([model.orderState isEqualToString:@"001"]) {//未付款
勾芒's avatar
勾芒 committed
215
        orderdetails.isShowPayButton = YES;
216 217
        orderdetails.isShowPrintButton = NO;
        orderdetails.isShowHeaderView = YES;
218
        orderdetails.isUserInteractionEnabled = YES;
219 220 221
        
    }else{
        orderdetails.isShowHeaderView = NO;
勾芒's avatar
勾芒 committed
222
    }
223 224 225 226 227 228 229
    //撤销、支付回调
    [orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
        OrderBill *model = [self.datasArray objectAtIndex_opple:cellindex];
        model.order.orderState = orderSate;
        NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
        [self.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
    }];
勾芒's avatar
勾芒 committed
230 231 232
    [self.navigationController pushViewController:orderdetails animated:YES];
}

勾芒's avatar
勾芒 committed
233
#pragma mark -弹出popover视图控制器
234
- (void)showPopoverViewController:(CGSize)size withDatas:(NSArray *)datasArray showButton:(UIButton *)button selectedIndex:(NSInteger)index
勾芒's avatar
勾芒 committed
235 236 237 238 239
{
    PopoverViewController *popover = [[PopoverViewController alloc]init];
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.isString = YES;
240
    popover.selectedindex = index;
勾芒's avatar
勾芒 committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    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
 */
257
- (void)returnCellindexpathwithrow:(NSString *)type withCellTitle:(NSString *)title withSelected:(NSInteger)selected
勾芒's avatar
勾芒 committed
258
{
259
    [self.styleButton setTitle:title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
260 261 262
    [self dismissViewControllerAnimated:YES completion:nil];
    
    NSString *orderState = nil;
勾芒's avatar
勾芒 committed
263 264 265 266 267 268 269
    //全部订单
    if ([title isEqualToString:@"全部订单"]) {
        orderState = nil;
    }
    //待支付
    else if ([title isEqualToString:@"待支付"]) {
        orderState = @"001";
勾芒's avatar
勾芒 committed
270
    }
勾芒's avatar
勾芒 committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    //已支付
   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";
    }
291 292
    self.model.consumerNameOrMobileEquals = nil;
    self.model.orderStateEquals = orderState;
293
    [self.customerOrderTableView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
294 295 296 297 298 299 300
}


#pragma mark -Search点击
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
301 302
    self.model.consumerNameOrMobileEquals = textField.text;
    self.model.orderStateEquals = nil;
303
    [self.customerOrderTableView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
304 305 306 307 308
    return YES;
}



勾芒's avatar
勾芒 committed
309
#pragma mark -撤销订单
勾芒's avatar
勾芒 committed
310
- (void)undoOrderButtonClick:(NSInteger)cellindex
勾芒's avatar
勾芒 committed
311
{
312
    WS(weakSelf);
勾芒's avatar
勾芒 committed
313
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请确认是否撤销订单" preferredStyle:UIAlertControllerStyleAlert];
314
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
勾芒's avatar
勾芒 committed
315 316
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
曹云霄's avatar
曹云霄 committed
317
        [XBLoadingView showHUDViewWithDefault];
勾芒's avatar
勾芒 committed
318
        OrderBill *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
319
        [[NetworkRequestClassManager manager] networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),model.order.orderNumber,model.order.orderState,@"005"]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
320
            
曹云霄's avatar
曹云霄 committed
321
            [XBLoadingView hideHUDViewWithDefault];
勾芒's avatar
勾芒 committed
322
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
323
                [XBLoadingView showHUDViewWithSuccessText:@"撤销成功" completeBlock:nil];
勾芒's avatar
勾芒 committed
324 325
                model.order.orderState = @"005";
                NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
勾芒's avatar
勾芒 committed
326
                [weakSelf.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationLeft];
勾芒's avatar
勾芒 committed
327 328 329
            }
            else
            {
曹云霄's avatar
曹云霄 committed
330
                [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
331
            }
332
        }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
333 334
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
335
        }];
勾芒's avatar
勾芒 committed
336 337
    }]];
    [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
338 339 340
}


勾芒's avatar
勾芒 committed
341 342

#pragma mark -去支付
勾芒's avatar
勾芒 committed
343 344
- (void)TopayButtonClick:(NSInteger)cellindex
{
曹云霄's avatar
曹云霄 committed
345
    OrderdetailsViewController *orderdetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
曹云霄's avatar
曹云霄 committed
346
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:cellindex] order];
勾芒's avatar
勾芒 committed
347
    orderdetails.orderCode = model.orderNumber;
曹云霄's avatar
曹云霄 committed
348
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
349
        orderdetails.isShowPrintButton = YES;
350 351
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
352
        orderdetails.isUserInteractionEnabled = NO;
353 354
        
    } else if ([model.orderState isEqualToString:@"001"]) {//未付款
勾芒's avatar
勾芒 committed
355
        orderdetails.isShowPayButton = YES;
356 357
        orderdetails.isShowPrintButton = NO;
        orderdetails.isShowHeaderView = YES;
358
        orderdetails.isUserInteractionEnabled = YES;
359 360 361
        
    }else{
        orderdetails.isShowHeaderView = NO;
勾芒's avatar
勾芒 committed
362 363 364 365 366 367 368 369 370 371 372 373
    }
    //撤销、支付回调
    [orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
        
        OrderBill *model = [self.datasArray objectAtIndex_opple:cellindex];
        model.order.orderState = orderSate;
        NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
        [self.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
        
    }];
    [self.navigationController pushViewController:orderdetails animated:YES];
}
勾芒's avatar
勾芒 committed
374 375


曹云霄's avatar
曹云霄 committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

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

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

勾芒's avatar
勾芒 committed
392

曹云霄's avatar
曹云霄 committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

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