ClientdetailsViewController.m 8.95 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 37 38


@end

@implementation ClientdetailsViewController

勾芒's avatar
勾芒 committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

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


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



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


#pragma mark -UI
- (void)uiConfigAction
{
勾芒's avatar
勾芒 committed
80
    
曹云霄's avatar
曹云霄 committed
81 82
    self.ClientdetailsTableview.delegate = self;
    self.ClientdetailsTableview.dataSource = self;
勾芒's avatar
勾芒 committed
83
    self.ClientdetailsTableview.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
84 85
    
    //圆角
曹云霄's avatar
曹云霄 committed
86 87 88 89 90 91
    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
92 93
    self.setupButton.layer.masksToBounds = YES;
    self.setupButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
94 95 96 97 98
    
    //默认选中购物袋
    self.shoppingBagButton.selected = YES;
    self.shoppingBagButton.backgroundColor = [UIColor whiteColor];
    
勾芒's avatar
勾芒 committed
99 100 101 102 103 104
    //赋值
    [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
105 106
}

勾芒's avatar
勾芒 committed
107 108


曹云霄's avatar
曹云霄 committed
109 110
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
111 112 113 114
    if (self.shoppingBagButton.selected) {
        
        ClientDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClientDetails" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
115
        cell.model = [self.shopResponseArray objectAtIndex_opple:indexPath.row];
116 117 118 119 120 121
        return cell;
        
    }else if (self.orderRecordButton.selected)
    {
        OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ordercell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
122
        cell.model = [self.orderRecordArray objectAtIndex_opple:indexPath.row];
123 124 125
        return  cell;
    }
    return  nil;
曹云霄's avatar
曹云霄 committed
126 127
}

勾芒's avatar
勾芒 committed
128

曹云霄's avatar
曹云霄 committed
129 130
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
131 132 133 134 135 136 137 138 139
    if (self.shoppingBagButton.selected) {
        
        return self.shopResponseArray.count;
    }
    if (self.orderRecordButton.selected) {
        
        return self.orderRecordArray.count;
    }
    return 0;
曹云霄's avatar
曹云霄 committed
140 141
}

勾芒's avatar
勾芒 committed
142

曹云霄's avatar
曹云霄 committed
143 144
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
145 146 147 148 149 150 151 152 153
    if (self.shoppingBagButton.selected) {
        
        return 100;
    }
    else if (self.orderRecordButton.selected)
    {
        return 200;
    }
    return 0;
曹云霄's avatar
曹云霄 committed
154 155
}

勾芒's avatar
勾芒 committed
156 157


158 159
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
160 161 162 163 164 165 166 167 168 169 170
    if (self.shoppingBagButton.selected) {
        
        return;
        
    }else if (self.orderRecordButton.selected)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
        OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
        orderdetails.orderCode = [[[self.orderRecordArray objectAtIndex_opple:indexPath.row] order] orderNumber];
        [self.navigationController pushViewController:orderdetails animated:YES];
    }
勾芒's avatar
勾芒 committed
171 172 173 174 175 176 177 178
}



#pragma mark -获取购物车商品
- (void)getShoppingCardata
{
    ShopCartFilter *shopcarNumber = [[ShopCartFilter alloc]init];
勾芒's avatar
勾芒 committed
179
    shopcarNumber.consumerId = _model.fid;
勾芒's avatar
勾芒 committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
    DataPage *Newpage = [[DataPage alloc]init];
    Newpage.page = 0;
    shopcarNumber.dp = Newpage;
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/shopcart/query"] WithRequestType:0 WithParameter:shopcarNumber WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            ShopCartResponse *shopcar = [[ShopCartResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //自定义属性
            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) {
        
        [self RemoveMBProgressHUDLoding];
    }];
221
}
曹云霄's avatar
曹云霄 committed
222 223 224



勾芒's avatar
勾芒 committed
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265
#pragma mark -获取客户订单数据
- (void)getGuideAllcustomerOrder
{
    
    OrderBill *allOrder = [[OrderBill alloc]init];
    //分页
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    page.rows = 10;
    //订单
    TOOrderEntity *Neworder = [[TOOrderEntity alloc]init];
    Neworder.guideId = [Shoppersmanager manager].Shoppers.employee.fid;
    allOrder.datapage = page;
    allOrder.order = Neworder;
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/order/query"] WithRequestType:0 WithParameter:allOrder WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {

            OrderResponse *Allorder = [[OrderResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            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
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -设为当前的客户
- (IBAction)SetupcurrentUserButtonClick:(UIButton *)sender {
    
    
}


#pragma mark -购物袋
- (IBAction)ShoppingbagButtonClick:(UIButton *)sender {
    
    
曹云霄's avatar
曹云霄 committed
283 284 285
    sender.backgroundColor = [UIColor whiteColor];
    sender.selected = YES;
    self.orderRecordButton.selected = NO;
286
    self.orderRecordButton.backgroundColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
287
    
288
    [self.ClientdetailsTableview reloadData];
曹云霄's avatar
曹云霄 committed
289 290 291 292 293
}

#pragma mark -订单记录
- (IBAction)OrderrecordButtonClick:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
294
    
曹云霄's avatar
曹云霄 committed
295
    sender.backgroundColor = [UIColor whiteColor];
曹云霄's avatar
曹云霄 committed
296 297
    sender.selected = YES;
    self.shoppingBagButton.selected = NO;
298 299
    self.shoppingBagButton.backgroundColor = kMainBlueColor;
    [self.ClientdetailsTableview reloadData];
曹云霄's avatar
曹云霄 committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
    
}


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