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

#import "ClientdetailsViewController.h"
#import "ClientDetailsTableViewCell.h"
11 12
#import "OrderTableViewCell.h"
#import "OrderdetailsViewController.h"
勾芒's avatar
勾芒 committed
13 14
#import "ShopcarModel.h"

15

曹云霄's avatar
曹云霄 committed
16 17 18 19 20 21 22
@interface ClientdetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

/**
 *  客户详情
 */
@property (weak, nonatomic) IBOutlet UITableView *ClientdetailsTableview;

勾芒's avatar
勾芒 committed
23 24 25 26 27 28 29 30 31 32
/**
 *  购物车数据源
 */
@property (nonatomic,strong) NSMutableArray *shopResponseArray;

/**
 *  订单记录数据
 */
@property (nonatomic,strong) NSMutableArray *orderRecordArray;

勾芒's avatar
勾芒 committed
33 34 35 36
/**
 *  购物袋当前页数
 */
@property (nonatomic,assign) int shoppingBagPage;
曹云霄's avatar
曹云霄 committed
37

勾芒's avatar
勾芒 committed
38 39 40 41
/**
 *  购物袋总页数
 */
@property (nonatomic,assign) int shoppingBagTotalPage;
曹云霄's avatar
曹云霄 committed
42

勾芒's avatar
勾芒 committed
43 44 45 46 47 48 49 50 51
/**
 *  订单记录当前页数
 */
@property (nonatomic,assign) int orderRecordPage;

/**
 *  订单记录总页数
 */
@property (nonatomic,assign) int orderRecordTotalPage;
曹云霄's avatar
曹云霄 committed
52 53 54 55
@end

@implementation ClientdetailsViewController

勾芒's avatar
勾芒 committed
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

/**
 *  购物袋数据源
 */
- (NSMutableArray *)shopResponseArray
{
    if (_shopResponseArray == nil) {
        
        _shopResponseArray = [NSMutableArray array];
    }
    return _shopResponseArray;
}


/**
 *  订单记录数据源
 */
- (NSMutableArray *)orderRecordArray
{
    if (_orderRecordArray == nil) {
        
        _orderRecordArray = [NSMutableArray array];
    }
    return _orderRecordArray;
}



曹云霄's avatar
曹云霄 committed
84 85 86 87 88
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
89
    [self GetdatasAciton];
曹云霄's avatar
曹云霄 committed
90 91 92 93 94 95
}


#pragma mark -UI
- (void)uiConfigAction
{
勾芒's avatar
勾芒 committed
96
    
曹云霄's avatar
曹云霄 committed
97 98
    self.ClientdetailsTableview.delegate = self;
    self.ClientdetailsTableview.dataSource = self;
勾芒's avatar
勾芒 committed
99
    self.ClientdetailsTableview.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
100 101
    
    //圆角
曹云霄's avatar
曹云霄 committed
102 103 104 105 106 107
    self.shoppingAndRecordBackview.layer.masksToBounds = YES;
    self.shoppingAndRecordBackview.layer.cornerRadius = kCornerRadius;
    self.shoppingBagButton.layer.masksToBounds = YES;
    self.shoppingBagButton.layer.cornerRadius = kCornerRadius;
    self.orderRecordButton.layer.masksToBounds = YES;
    self.orderRecordButton.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
108 109
    self.setupButton.layer.masksToBounds = YES;
    self.setupButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
110 111 112 113 114
    
    //默认选中购物袋
    self.shoppingBagButton.selected = YES;
    self.shoppingBagButton.backgroundColor = [UIColor whiteColor];
    
勾芒's avatar
勾芒 committed
115 116 117 118
    //赋值
    [self.customerHeader sd_setImageWithURL:[NSURL URLWithString:self.model.picture] placeholderImage:ReplaceImage];
    self.customerName.text = self.model.name;
    self.customerPhoneNumber.text = self.model.mobile;
勾芒's avatar
勾芒 committed
119
    self.companyName.text = self.model.company;
勾芒's avatar
勾芒 committed
120
    self.customerLocation.text = self.model.address;
勾芒's avatar
勾芒 committed
121 122
    self.setupButton.selected = self.model.selectedState;
    [self.setupButton setTitle:self.model.selectedState?@"退出当前客户":@"设为当前客户" forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
123 124
}

勾芒's avatar
勾芒 committed
125

勾芒's avatar
勾芒 committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
#pragma mark -获取数据
- (void)GetdatasAciton
{
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //购物袋
        if (self.shoppingBagButton.selected) {
            self.shoppingBagPage = 1;
            ShopCartFilter *shopcarNumber = [[ShopCartFilter alloc]init];
            shopcarNumber.consumerId = _model.fid;
            DataPage *Newpage = [[DataPage alloc]init];
            Newpage.page = self.shoppingBagPage;
            Newpage.rows = KROWS;
            shopcarNumber.dp = Newpage;
            [self.ClientdetailsTableview.mj_footer resetNoMoreData];
            [self getShoppingCardata:shopcarNumber isRemove:YES];
        }
        else if (self.orderRecordButton.selected)//订单记录
        {
            self.orderRecordPage = 1;
            OrderBill *allOrder = [[OrderBill alloc]init];
            //分页
            DataPage *page = [[DataPage alloc]init];
            page.page = self.orderRecordPage;
            page.rows = KROWS;
            //订单
            TOOrderEntity *Neworder = [[TOOrderEntity alloc]init];
            Neworder.guideId = [Shoppersmanager manager].Shoppers.employee.fid;
勾芒's avatar
勾芒 committed
154
            Neworder.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            allOrder.datapage = page;
            allOrder.order = Neworder;
            [self getGuideAllcustomerOrder:allOrder isRemove:YES];
        }
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.ClientdetailsTableview.mj_header =headerRefresh;
    
    //进入刷新状态
    [self.ClientdetailsTableview.mj_header beginRefreshing];
    //上拉加载
    self.ClientdetailsTableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [self.ClientdetailsTableview.mj_footer resetNoMoreData];
        //购物袋
        if (self.shoppingBagButton.selected) {
勾芒's avatar
勾芒 committed
172
            if (++ self.shoppingBagPage > self.shoppingBagTotalPage) {
勾芒's avatar
勾芒 committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                [self.ClientdetailsTableview.mj_footer endRefreshingWithNoMoreData];
            }else
            {
                ShopCartFilter *shopcarNumber = [[ShopCartFilter alloc]init];
                shopcarNumber.consumerId = _model.fid;
                DataPage *Newpage = [[DataPage alloc]init];
                Newpage.page = self.shoppingBagPage++;
                Newpage.rows = KROWS;
                shopcarNumber.dp = Newpage;
                [self getShoppingCardata:shopcarNumber isRemove:NO];
            }
        }
        else if (self.orderRecordButton.selected)//订单记录
        {
            self.orderRecordPage = 1;
            if (self.orderRecordPage ++ > self.orderRecordTotalPage) {
                [self.ClientdetailsTableview.mj_footer endRefreshingWithNoMoreData];
            }else
            {
                OrderBill *allOrder = [[OrderBill alloc]init];
                //分页
                DataPage *page = [[DataPage alloc]init];
                page.page = self.orderRecordPage++;
                page.rows = KROWS;
                //订单
                TOOrderEntity *Neworder = [[TOOrderEntity alloc]init];
                Neworder.guideId = [Shoppersmanager manager].Shoppers.employee.fid;
勾芒's avatar
勾芒 committed
200
                Neworder.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
201 202
                allOrder.datapage = page;
                allOrder.order = Neworder;
勾芒's avatar
勾芒 committed
203
     
勾芒's avatar
勾芒 committed
204 205 206 207 208
                [self getGuideAllcustomerOrder:allOrder isRemove:NO];
            }
        }
    }];
}
勾芒's avatar
勾芒 committed
209

曹云霄's avatar
曹云霄 committed
210 211
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
212 213 214 215
    if (self.shoppingBagButton.selected) {
        
        ClientDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClientDetails" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
216
        cell.model = [self.shopResponseArray objectAtIndex_opple:indexPath.row];
217 218 219 220 221 222
        return cell;
        
    }else if (self.orderRecordButton.selected)
    {
        OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ordercell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
223
        cell.model = [self.orderRecordArray objectAtIndex_opple:indexPath.row];
224 225 226
        return  cell;
    }
    return  nil;
曹云霄's avatar
曹云霄 committed
227 228
}

勾芒's avatar
勾芒 committed
229

曹云霄's avatar
曹云霄 committed
230 231
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
232 233 234 235 236 237 238 239 240
    if (self.shoppingBagButton.selected) {
        
        return self.shopResponseArray.count;
    }
    if (self.orderRecordButton.selected) {
        
        return self.orderRecordArray.count;
    }
    return 0;
曹云霄's avatar
曹云霄 committed
241 242
}

勾芒's avatar
勾芒 committed
243

曹云霄's avatar
曹云霄 committed
244 245
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
246 247 248 249 250 251 252 253 254
    if (self.shoppingBagButton.selected) {
        
        return 100;
    }
    else if (self.orderRecordButton.selected)
    {
        return 200;
    }
    return 0;
曹云霄's avatar
曹云霄 committed
255 256
}

勾芒's avatar
勾芒 committed
257 258


259 260
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
261 262 263 264 265 266 267 268
    if (self.shoppingBagButton.selected) {
        
        return;
        
    }else if (self.orderRecordButton.selected)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
        OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
勾芒's avatar
勾芒 committed
269 270
        TOOrderEntity *model = [[self.orderRecordArray objectAtIndex_opple:indexPath.row] order];
        orderdetails.orderCode = model.orderNumber;
勾芒's avatar
勾芒 committed
271 272
        orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
        orderdetails.isShowattachment = YES;
勾芒's avatar
勾芒 committed
273
        if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
勾芒's avatar
勾芒 committed
274
            orderdetails.isShowPrintButton = YES;
勾芒's avatar
勾芒 committed
275 276 277
            orderdetails.isDelectedButton = NO;
        }
        if ([model.orderState isEqualToString:@"001"]) {
勾芒's avatar
勾芒 committed
278
            orderdetails.isShowPayButton = YES;
勾芒's avatar
勾芒 committed
279 280
            orderdetails.isDelectedButton = YES;
            orderdetails.isShowPrintButton = YES;
勾芒's avatar
勾芒 committed
281
        }
勾芒's avatar
勾芒 committed
282 283
        [self.navigationController pushViewController:orderdetails animated:YES];
    }
勾芒's avatar
勾芒 committed
284 285 286 287 288
}



#pragma mark -获取购物车商品
勾芒's avatar
勾芒 committed
289
- (void)getShoppingCardata:(ShopCartFilter *)shopCar isRemove:(BOOL)remove
勾芒's avatar
勾芒 committed
290 291
{
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
292
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/shopcart/query"] WithRequestType:0 WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
293
        
勾芒's avatar
勾芒 committed
294 295
        [self endRefreshingForTableView:self.ClientdetailsTableview];
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
296
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
297 298 299
            if (remove) {
                [self.shopResponseArray removeAllObjects];
            }
勾芒's avatar
勾芒 committed
300
            ShopCartResponse *shopcar = [[ShopCartResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
301
            self.shoppingBagTotalPage = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
302
            if (shopcar.shopcart.count == 0) {
勾芒's avatar
勾芒 committed
303
                [self PromptinformationViewWithimage:TCImage(@"ablum-副本") withTitle:@"暂无购物袋信息~" withpoint:CGPointMake(ScreenHeight/2, ScreenWidth/2)];
勾芒's avatar
勾芒 committed
304
                [self endRefreshingForTableView:self.ClientdetailsTableview];
勾芒's avatar
勾芒 committed
305
            }
勾芒's avatar
勾芒 committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
            //自定义属性
            for (TOShopcartEntity *objc in shopcar.shopcart) {
                
                ShopcarModel *model = [[ShopcarModel alloc]init];
                model.goods = objc.goods;
                model.fid = objc.fid;
                model.createName = objc.createName;
                model.createBy = objc.createBy;
                model.createDate = objc.createDate;
                model.updateName = objc.updateName;
                model.updateBy = objc.updateBy;
                model.updateDate = objc.updateDate;
                model.goodsId = objc.goodsId;
                model.goodsNum = objc.goodsNum;
                model.consumerId = objc.consumerId;
                
                [self.shopResponseArray addObject:model];
            }
            [self.ClientdetailsTableview reloadData];
            
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
335
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
336
    }];
337
}
曹云霄's avatar
曹云霄 committed
338 339 340



勾芒's avatar
勾芒 committed
341
#pragma mark -获取客户订单数据
勾芒's avatar
勾芒 committed
342
- (void)getGuideAllcustomerOrder:(OrderBill *)allOrder isRemove:(BOOL)remove
勾芒's avatar
勾芒 committed
343
{
勾芒's avatar
勾芒 committed
344
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
345 346 347
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/order/query"] WithRequestType:0 WithParameter:allOrder WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
348
        [self endRefreshingForTableView:self.ClientdetailsTableview];
勾芒's avatar
勾芒 committed
349
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
350 351 352
            if (remove) {
                [self.orderRecordArray removeAllObjects];
            }
勾芒's avatar
勾芒 committed
353
            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
354
            self.orderRecordTotalPage = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
355 356 357 358 359
            if (Allorder.orderBillList.count == 0) {
                [self PromptinformationViewWithimage:TCImage(@"changjingtubiao") withTitle:@"暂无订单信息~" withpoint:CGPointMake(ScreenHeight/2, ScreenWidth/2)];
                [self RemoveMBProgressHUDLoding];
                [self endRefreshingForTableView:self.ClientdetailsTableview];
            }
勾芒's avatar
勾芒 committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
            for (OrderBill *model in Allorder.orderBillList) {
                [self.orderRecordArray addObject:model];
            }
            [self.ClientdetailsTableview reloadData];
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
        [self RemoveMBProgressHUDLoding];
    }];
}



曹云霄's avatar
曹云霄 committed
379 380 381 382 383 384 385 386
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -设为当前的客户
- (IBAction)SetupcurrentUserButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
387
   
曹云霄's avatar
曹云霄 committed
388
    
勾芒's avatar
勾芒 committed
389
    if (self.CurrentUserBlock) {
勾芒's avatar
勾芒 committed
390
        self.CurrentUserBlock(_cellindex,sender.currentTitle);
勾芒's avatar
勾芒 committed
391
    }
勾芒's avatar
勾芒 committed
392 393 394
     [sender setTitle:sender.selected?@"设为当前客户":@"退出当前客户" forState:UIControlStateNormal];
     sender.selected = !sender.selected;

曹云霄's avatar
曹云霄 committed
395 396 397 398 399 400 401
}


#pragma mark -购物袋
- (IBAction)ShoppingbagButtonClick:(UIButton *)sender {
    
    
曹云霄's avatar
曹云霄 committed
402 403 404
    sender.backgroundColor = [UIColor whiteColor];
    sender.selected = YES;
    self.orderRecordButton.selected = NO;
405
    self.orderRecordButton.backgroundColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
406

勾芒's avatar
勾芒 committed
407 408
    [self RemovePromptinformationView];
    [self.ClientdetailsTableview.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
409 410 411 412 413
}

#pragma mark -订单记录
- (IBAction)OrderrecordButtonClick:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
414
    
曹云霄's avatar
曹云霄 committed
415
    sender.backgroundColor = [UIColor whiteColor];
曹云霄's avatar
曹云霄 committed
416 417
    sender.selected = YES;
    self.shoppingBagButton.selected = NO;
418
    self.shoppingBagButton.backgroundColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
419

勾芒's avatar
勾芒 committed
420 421
    [self RemovePromptinformationView];
    [self.ClientdetailsTableview.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435
}


/*
#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