CustomerOrderViewController.m 14 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
        _model.resellerCodeEquals = [[Shoppersmanager manager].shoppers.employee.currentDepart  orgCode];
68 69 70 71
    }
    return _model;
}

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#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
92 93
- (void)viewDidLoad {
    [super viewDidLoad];
94
    
曹云霄's avatar
曹云霄 committed
95
    [self uiConfigAction];
96
    [self setUpRefresh];
曹云霄's avatar
曹云霄 committed
97 98
}

勾芒's avatar
勾芒 committed
99 100
#pragma mark -UI
- (void)uiConfigAction
曹云霄's avatar
曹云霄 committed
101
{
勾芒's avatar
勾芒 committed
102
    self.searchCustomerOrder.delegate = self;
曹云霄's avatar
曹云霄 committed
103
    self.view.backgroundColor = RGB(238, 238, 238,1);
勾芒's avatar
勾芒 committed
104 105 106
    self.customerOrderTableView.dataSource = self;
    self.customerOrderTableView.delegate = self;
    self.customerOrderTableView.backgroundColor = [UIColor clearColor];
107 108
    self.styleButton = [ScreeningButton buttonWithType:UIButtonTypeCustom];
    self.styleButton.frame = CGRectMake(ScreenWidth-250, 20, 150, 30);
曹云霄's avatar
曹云霄 committed
109
    self.styleButton.backgroundColor = RGB(131, 131, 131,1);
110 111 112
    [self.styleButton setTitle:@"订单状态" forState:UIControlStateNormal];
    [self.styleButton addTarget:self action:@selector(OrderStateButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.styleButton setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
113
    [self.styleButton setMyCorner:10];
114
    [self.orderStateBackView addSubview:self.styleButton];
115 116 117 118 119
}

#pragma mark -设置刷新
- (void)setUpRefresh
{
勾芒's avatar
勾芒 committed
120
    //下拉刷新
121
    WS(weakSelf);
勾芒's avatar
勾芒 committed
122
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
勾芒's avatar
勾芒 committed
123
        
124
        [weakSelf.customerOrderTableView.mj_footer resetNoMoreData];
125
        weakSelf.model.dp.page = ONE;
126
        [weakSelf getGuideAllcustomerOrder:YES withOrderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
127
    }];
勾芒's avatar
勾芒 committed
128 129 130
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.customerOrderTableView.mj_header = headerRefresh;
勾芒's avatar
勾芒 committed
131 132 133 134
    [self.customerOrderTableView.mj_header beginRefreshing];
    //上拉加载
    self.customerOrderTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
135
        if ( ++ weakSelf.model.dp.page > weakSelf.totalPages) {
136
            [weakSelf.customerOrderTableView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
137 138
        }else
        {
139
            [weakSelf getGuideAllcustomerOrder:NO withOrderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
140
        }
勾芒's avatar
勾芒 committed
141
    }];
曹云霄's avatar
曹云霄 committed
142
    self.customerOrderTableView.mj_footer.automaticallyHidden = YES;
勾芒's avatar
勾芒 committed
143 144 145
}


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

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

勾芒's avatar
勾芒 committed
183

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
199
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
200 201 202 203 204 205 206
}

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

勾芒's avatar
勾芒 committed
207 208
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
209
    OrderdetailsViewController *orderdetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
210
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:indexPath.row] order];
勾芒's avatar
勾芒 committed
211
    orderdetails.orderCode = model.orderNumber;
212
    orderdetails.consumerID = model.consumerId;
曹云霄's avatar
曹云霄 committed
213
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
214
        orderdetails.isShowPrintButton = YES;
215 216
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
217
        orderdetails.isUserInteractionEnabled = NO;
218 219
        
    } else if ([model.orderState isEqualToString:@"001"]) {//未付款
勾芒's avatar
勾芒 committed
220
        orderdetails.isShowPayButton = YES;
221 222
        orderdetails.isShowPrintButton = NO;
        orderdetails.isShowHeaderView = YES;
223
        orderdetails.isUserInteractionEnabled = YES;
224 225 226
        
    }else{
        orderdetails.isShowHeaderView = NO;
勾芒's avatar
勾芒 committed
227
    }
228 229 230 231 232 233 234
    //撤销、支付回调
    [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
235 236 237
    [self.navigationController pushViewController:orderdetails animated:YES];
}

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


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


勾芒's avatar
勾芒 committed
313
#pragma mark -撤销订单
勾芒's avatar
勾芒 committed
314
- (void)undoOrderButtonClick:(NSInteger)cellindex
勾芒's avatar
勾芒 committed
315
{
316
    WS(weakSelf);
317
    ShowDefaultAlertView(self, @"提示", @"请确认是否撤销订单", UIAlertControllerStyleAlert, ^{
曹云霄's avatar
曹云霄 committed
318
        [XBLoadingView showHUDViewWithDefault];
勾芒's avatar
勾芒 committed
319
        OrderBill *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
曹云霄's avatar
曹云霄 committed
320
        [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),model.order.orderNumber,model.order.orderState,@"005"]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
321
            
曹云霄's avatar
曹云霄 committed
322
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
323
            if (RESULT(returnValue)) {
324
                [XBLoadingView showHUDViewWithSuccessText:@"撤销成功" completeBlock:nil];
勾芒's avatar
勾芒 committed
325 326
                model.order.orderState = @"005";
                NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
勾芒's avatar
勾芒 committed
327
                [weakSelf.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationLeft];
328
            }else{
329
                [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
330
            }
331
        }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
332 333
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
334
        }];
335
    }, nil);
勾芒's avatar
勾芒 committed
336 337 338
}


勾芒's avatar
勾芒 committed
339 340

#pragma mark -去支付
勾芒's avatar
勾芒 committed
341 342
- (void)TopayButtonClick:(NSInteger)cellindex
{
曹云霄's avatar
曹云霄 committed
343
    OrderdetailsViewController *orderdetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"orderdetails"];
曹云霄's avatar
曹云霄 committed
344
    TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:cellindex] order];
勾芒's avatar
勾芒 committed
345
    orderdetails.orderCode = model.orderNumber;
曹云霄's avatar
曹云霄 committed
346
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
347
        orderdetails.isShowPrintButton = YES;
348 349
        orderdetails.isShowPayButton = NO;
        orderdetails.isShowHeaderView = YES;
350
        orderdetails.isUserInteractionEnabled = NO;
351 352
        
    } else if ([model.orderState isEqualToString:@"001"]) {//未付款
勾芒's avatar
勾芒 committed
353
        orderdetails.isShowPayButton = YES;
354 355
        orderdetails.isShowPrintButton = NO;
        orderdetails.isShowHeaderView = YES;
356
        orderdetails.isUserInteractionEnabled = YES;
357 358 359
        
    }else{
        orderdetails.isShowHeaderView = NO;
勾芒's avatar
勾芒 committed
360 361 362 363 364 365 366 367 368 369 370 371
    }
    //撤销、支付回调
    [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
372 373


曹云霄's avatar
曹云霄 committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
#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
390

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