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 119 120
    //赋值
    [self.customerHeader sd_setImageWithURL:[NSURL URLWithString:self.model.picture] placeholderImage:ReplaceImage];
    self.customerName.text = self.model.name;
    self.customerPhoneNumber.text = self.model.mobile;
    self.companyName.text = self.model.name;
    self.customerLocation.text = self.model.address;
勾芒's avatar
勾芒 committed
121 122 123
    
    self.setupButton.selected = self.model.selectedState;
    [self.setupButton setTitle:self.model.selectedState?@"退出当前客户":@"设为当前客户" forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
124 125
}

勾芒's avatar
勾芒 committed
126

勾芒's avatar
勾芒 committed
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 154
#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
155
            Neworder.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
            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
173
            if (++ self.shoppingBagPage > self.shoppingBagTotalPage) {
勾芒's avatar
勾芒 committed
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 200
                [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
201
                Neworder.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
202 203
                allOrder.datapage = page;
                allOrder.order = Neworder;
勾芒's avatar
勾芒 committed
204
     
勾芒's avatar
勾芒 committed
205 206 207 208 209
                [self getGuideAllcustomerOrder:allOrder isRemove:NO];
            }
        }
    }];
}
勾芒's avatar
勾芒 committed
210

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

勾芒's avatar
勾芒 committed
230

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

勾芒's avatar
勾芒 committed
244

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

勾芒's avatar
勾芒 committed
258 259


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



#pragma mark -获取购物车商品
勾芒's avatar
勾芒 committed
290
- (void)getShoppingCardata:(ShopCartFilter *)shopCar isRemove:(BOOL)remove
勾芒's avatar
勾芒 committed
291 292
{
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
293
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/shopcart/query"] WithRequestType:0 WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
294
        
勾芒's avatar
勾芒 committed
295 296
        [self endRefreshingForTableView:self.ClientdetailsTableview];
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
297
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
298 299 300
            if (remove) {
                [self.shopResponseArray removeAllObjects];
            }
勾芒's avatar
勾芒 committed
301
            ShopCartResponse *shopcar = [[ShopCartResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
302
            self.shoppingBagTotalPage = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
303
            if (shopcar.shopcart.count == 0) {
勾芒's avatar
勾芒 committed
304
                [self PromptinformationViewWithimage:TCImage(@"ablum-副本") withTitle:@"暂无购物袋信息~" withpoint:CGPointMake(ScreenHeight/2, ScreenWidth/2)];
勾芒's avatar
勾芒 committed
305
                [self endRefreshingForTableView:self.ClientdetailsTableview];
勾芒's avatar
勾芒 committed
306
            }
勾芒's avatar
勾芒 committed
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 335
            //自定义属性
            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
336
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
337
    }];
338
}
曹云霄's avatar
曹云霄 committed
339 340 341



勾芒's avatar
勾芒 committed
342
#pragma mark -获取客户订单数据
勾芒's avatar
勾芒 committed
343
- (void)getGuideAllcustomerOrder:(OrderBill *)allOrder isRemove:(BOOL)remove
勾芒's avatar
勾芒 committed
344
{
勾芒's avatar
勾芒 committed
345
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
346 347 348
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/order/query"] WithRequestType:0 WithParameter:allOrder WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
349
        [self endRefreshingForTableView:self.ClientdetailsTableview];
勾芒's avatar
勾芒 committed
350
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
351 352 353
            if (remove) {
                [self.orderRecordArray removeAllObjects];
            }
勾芒's avatar
勾芒 committed
354
            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
355
            self.orderRecordTotalPage = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
356 357 358 359 360
            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
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
            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
380 381 382 383 384 385 386 387
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


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

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


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

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

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

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


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