ClientdetailsViewController.m 14.9 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
#import "ShopcarModel.h"
14
#import "ProductDetailsViewController.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
                [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)//订单记录
        {
            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
199
                Neworder.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
200 201 202 203 204 205 206
                allOrder.datapage = page;
                allOrder.order = Neworder;
                [self getGuideAllcustomerOrder:allOrder isRemove:NO];
            }
        }
    }];
}
勾芒's avatar
勾芒 committed
207

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

勾芒's avatar
勾芒 committed
227

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

勾芒's avatar
勾芒 committed
241

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

勾芒's avatar
勾芒 committed
255 256


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



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



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


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

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


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

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

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

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


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