CustomerOrderViewController.m 14.2 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 24 25 26 27 28
/**
 *  当前页数
 */
@property (nonatomic,assign) int indexPage;

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

勾芒's avatar
勾芒 committed
29 30 31 32 33
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

曹云霄's avatar
曹云霄 committed
34

勾芒's avatar
勾芒 committed
35

曹云霄's avatar
曹云霄 committed
36 37 38 39
@end

@implementation CustomerOrderViewController

勾芒's avatar
勾芒 committed
40 41 42 43 44 45 46 47 48 49 50 51

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

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

63
- (OrderFilter *)model
64 65
{
    if (!_model) {
66
        _model = [[OrderFilter alloc]init];
67 68 69 70
    }
    return _model;
}

曹云霄's avatar
曹云霄 committed
71 72 73 74
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
75
   
曹云霄's avatar
曹云霄 committed
76 77
}

勾芒's avatar
勾芒 committed
78 79 80

#pragma mark -UI
- (void)uiConfigAction
曹云霄's avatar
曹云霄 committed
81
{
勾芒's avatar
勾芒 committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95
    self.searchCustomerOrder.delegate = self;
    self.view.backgroundColor = kTCColor(238, 238, 238);
    self.customerOrderTableView.dataSource = self;
    self.customerOrderTableView.delegate = self;
    self.customerOrderTableView.backgroundColor = [UIColor clearColor];
    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];
96 97
    //经销商代码
    self.model.resellerCodeEquals = [[Shoppersmanager manager].Shoppers.employee.currentDepart  orgCode];
勾芒's avatar
勾芒 committed
98
    //下拉刷新
99
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
100
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
勾芒's avatar
勾芒 committed
101 102
        
        self.indexPage = 1;
勾芒's avatar
勾芒 committed
103
        DataPage *page = [[DataPage alloc]init];
104 105
        page.page = weakSelf.indexPage;
        page.rows = KROWS;
106
        weakSelf.model.dp = page;
107 108
        [weakSelf.customerOrderTableView.mj_footer resetNoMoreData];
        [weakSelf getGuideAllcustomerOrder:YES WithorderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
109
    }];
勾芒's avatar
勾芒 committed
110 111 112
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.customerOrderTableView.mj_header = headerRefresh;
勾芒's avatar
勾芒 committed
113 114 115 116
    [self.customerOrderTableView.mj_header beginRefreshing];
    //上拉加载
    self.customerOrderTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
117 118
        if ( ++ weakSelf.indexPage > weakSelf.totalPages) {
            [weakSelf.customerOrderTableView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
119 120 121
        }else
        {
            DataPage *page = [[DataPage alloc]init];
122
            page.page = weakSelf.indexPage;
123
            page.rows = KROWS;
124
            weakSelf.model.dp = page;
125
            [weakSelf getGuideAllcustomerOrder:NO WithorderBill:weakSelf.model];
勾芒's avatar
勾芒 committed
126
        }
勾芒's avatar
勾芒 committed
127
    }];
勾芒's avatar
勾芒 committed
128 129 130
}


勾芒's avatar
勾芒 committed
131
#pragma mark -获取导购下客户订单  ----isdelecte 表示是否清空数组
132
- (void)getGuideAllcustomerOrder:(BOOL)isdelecte WithorderBill:(OrderFilter *)allOrder
勾芒's avatar
勾芒 committed
133
{
勾芒's avatar
勾芒 committed
134 135

    [self CreateMBProgressHUDLoding];
136
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(QUERYORDER) WithRequestType:0 WithParameter:allOrder WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
137
        
曹云霄's avatar
曹云霄 committed
138 139
        self.customerOrderTableView.emptyDataSetSource = self;
        self.customerOrderTableView.emptyDataSetDelegate = self;
勾芒's avatar
勾芒 committed
140 141
        [self RemoveMBProgressHUDLoding];
        [self endRefreshingForTableView:self.customerOrderTableView];
勾芒's avatar
勾芒 committed
142 143
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
勾芒's avatar
勾芒 committed
144 145 146
            if (isdelecte) {
                [self.datasArray removeAllObjects];
            }
勾芒's avatar
勾芒 committed
147
            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
148
            self.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
149 150 151 152
            for (OrderBill *model in Allorder.orderBillList) {
                [self.datasArray addObject:model];
            }
            [self.customerOrderTableView reloadData];
勾芒's avatar
勾芒 committed
153 154 155 156 157 158 159 160 161
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
162 163
        [self endRefreshingForTableView:self.customerOrderTableView];
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
164 165 166 167
    }];
}

#pragma mark -订单状态筛选
勾芒's avatar
勾芒 committed
168
- (void)OrderStateButtonClick:(UIButton *)button
勾芒's avatar
勾芒 committed
169
{
勾芒's avatar
勾芒 committed
170
    [self ShowPopoverViewController:CGSizeMake(200, 400) Withdatas:self.orderStateArray ShowButton:button SelectedIndex:0];
曹云霄's avatar
曹云霄 committed
171 172
}

勾芒's avatar
勾芒 committed
173

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

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

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

勾芒's avatar
勾芒 committed
197 198 199 200 201 202 203 204
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
    TOOrderEntity *model = [[self.datasArray objectAtIndex_opple:indexPath.row] order];
    orderdetails.orderCode = model.orderNumber;
    orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
    orderdetails.isShowattachment = YES;
曹云霄's avatar
曹云霄 committed
205
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
206 207 208 209
        orderdetails.isShowPrintButton = YES;
        orderdetails.isDelectedButton = NO;
    }
    if ([model.orderState isEqualToString:@"001"]) {
勾芒's avatar
勾芒 committed
210
        orderdetails.isShowPayButton = YES;
勾芒's avatar
勾芒 committed
211
        orderdetails.isDelectedButton = YES;
勾芒's avatar
勾芒 committed
212 213 214 215 216
        orderdetails.isShowPrintButton = YES;
    }
    [self.navigationController pushViewController:orderdetails animated:YES];
}

曹云霄's avatar
曹云霄 committed
217 218


勾芒's avatar
勾芒 committed
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
#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;
勾芒's avatar
勾芒 committed
252 253 254 255 256 257 258
    //全部订单
    if ([title isEqualToString:@"全部订单"]) {
        orderState = nil;
    }
    //待支付
    else if ([title isEqualToString:@"待支付"]) {
        orderState = @"001";
勾芒's avatar
勾芒 committed
259
    }
勾芒's avatar
勾芒 committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    //已支付
   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";
    }
280 281
    self.model.consumerNameOrMobileEquals = nil;
    self.model.orderStateEquals = orderState;
282
    [self.customerOrderTableView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
283 284 285 286 287 288 289 290
}



#pragma mark -Search点击
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
291 292
    self.model.consumerNameOrMobileEquals = textField.text;
    self.model.orderStateEquals = nil;
293
    [self.customerOrderTableView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
294 295 296 297 298
    return YES;
}



勾芒's avatar
勾芒 committed
299
#pragma mark -撤销订单
勾芒's avatar
勾芒 committed
300
- (void)undoOrderButtonClick:(NSInteger)cellindex
勾芒's avatar
勾芒 committed
301
{
勾芒's avatar
勾芒 committed
302 303 304 305 306
    __weak typeof(self) weakSelf = self;
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请确认是否撤销订单" preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }]];
勾芒's avatar
勾芒 committed
307
    
勾芒's avatar
勾芒 committed
308 309 310 311
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        [weakSelf CreateMBProgressHUDLoding];
        OrderBill *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
312
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),model.order.orderNumber,model.order.orderState,@"005"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
313
            
勾芒's avatar
勾芒 committed
314 315
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
            [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
316 317
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
                
勾芒's avatar
勾芒 committed
318
                [weakSelf SuccessMBProgressView:@"撤销成功"];
勾芒's avatar
勾芒 committed
319 320
                model.order.orderState = @"005";
                NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
勾芒's avatar
勾芒 committed
321
                [weakSelf.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationLeft];
勾芒's avatar
勾芒 committed
322 323 324
            }
            else
            {
勾芒's avatar
勾芒 committed
325
                [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
326 327 328 329 330 331
            }
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            
        } WithFailureBlock:^(id error) {
            
勾芒's avatar
勾芒 committed
332
            [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
333
        }];
勾芒's avatar
勾芒 committed
334 335 336
    }]];
    
    [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
337 338 339
}


勾芒's avatar
勾芒 committed
340 341

#pragma mark -去支付
勾芒's avatar
勾芒 committed
342 343 344 345 346 347 348 349
- (void)TopayButtonClick:(NSInteger)cellindex
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
    TOOrderEntity *model = [[self.datasArray objectAtIndex_opple:cellindex] order];
    orderdetails.orderCode = model.orderNumber;
    orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
    orderdetails.isShowattachment = YES;
曹云霄's avatar
曹云霄 committed
350
    if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
        orderdetails.isShowPrintButton = YES;
        orderdetails.isDelectedButton = NO;
    }
    if ([model.orderState isEqualToString:@"001"]) {
        orderdetails.isShowPayButton = YES;
        orderdetails.isDelectedButton = YES;
        orderdetails.isShowPrintButton = YES;
    }
    
    //撤销、支付回调
    [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
371 372


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

曹云霄's avatar
曹云霄 committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406

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