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

#import "AllCustomerViewController.h"
#import "AllCutomerTableViewCell.h"
勾芒's avatar
勾芒 committed
11 12 13
#import "DateSelectedViewController.h"
#import "MyclientEntityModel.h"
@interface AllCustomerViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
曹云霄's avatar
曹云霄 committed
14

勾芒's avatar
勾芒 committed
15 16 17 18
/**
 *  数据源
 */
@property (nonatomic,strong) NSMutableArray *CustomerresultArray;
曹云霄's avatar
曹云霄 committed
19 20 21 22
@end

@implementation AllCustomerViewController

勾芒's avatar
勾芒 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36

/**
 *  初始化客户数据源
 */
- (NSMutableArray *)CustomerresultArray
{
    if (_CustomerresultArray == nil) {
        
        _CustomerresultArray = [NSMutableArray array];
    }
    return _CustomerresultArray;
}


曹云霄's avatar
曹云霄 committed
37 38 39 40 41
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
42
    [self getShoppersAssociatedCustomer];
曹云霄's avatar
曹云霄 committed
43 44 45 46 47 48 49
    
}


#pragma mark -UI
- (void)uiConfigAction
{
勾芒's avatar
勾芒 committed
50
    
曹云霄's avatar
曹云霄 committed
51 52
    self.allCustomerTableview.dataSource = self;
    self.allCustomerTableview.delegate = self;
勾芒's avatar
勾芒 committed
53 54 55 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 84
    self.searchTextfield.delegate = self;
    self.searchTextfield.returnKeyType = UIReturnKeySearch;
    
    //调整布局
    [self.begindateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.RecentlydateLabe.mas_right).mas_offset(0);
        make.top.equalTo(self.RecentlydateLabe).mas_offset(-4);
        make.width.mas_offset(120);
    }];
    [self.redesignLabe mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.begindateButton.mas_right).mas_offset(10);
        make.top.equalTo(self.RecentlydateLabe).mas_offset(2);
        make.width.mas_offset(20);
    }];
    [self.enddateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.redesignLabe.mas_right).mas_offset(10);
        make.top.equalTo(self.RecentlydateLabe).mas_offset(-4);
        make.width.mas_offset(120);
    }];
    
    //设置按钮时间
    [self.begindateButton setTitle:[self dateAsString:[NSDate date]] forState:UIControlStateNormal];
    [self.enddateButton setTitle:[self dateAsString:[NSDate date]] forState:UIControlStateNormal];
    
    
    self.begindateButton.layer.masksToBounds = YES;
    self.begindateButton.layer.cornerRadius = 10;
    self.enddateButton.layer.masksToBounds = YES;
    self.enddateButton.layer.cornerRadius = 10;
曹云霄's avatar
曹云霄 committed
85 86 87
}


勾芒's avatar
勾芒 committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

#pragma mark -获取导购关联客户
- (void)getShoppersAssociatedCustomer
{
    
    [self CreateMBProgressHUDLoding];
    ConsumerQueryCondition *condition = [[ConsumerQueryCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    condition.page = page;
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/consumer/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            ConsumerPageResult *Customerresult = [[ConsumerPageResult alloc]initWithDictionary:returnValue[@"data"] error:nil];
            for (TOConsumerEntity *objc in Customerresult.results) {
                
                MyclientEntityModel *myclientModel = [[MyclientEntityModel alloc]init];
                myclientModel.fid = objc.fid;
                myclientModel.createName = objc.createName;
                myclientModel.createBy = objc.createBy;
                myclientModel.createDate = objc.createDate;
                myclientModel.sysOrgCode = objc.sysOrgCode;
                myclientModel.name = objc.name;
                myclientModel.mobile = objc.mobile;
                myclientModel.province = objc.province;
                myclientModel.city = objc.city;
                myclientModel.country = objc.country;
                myclientModel.address = objc.address;
                myclientModel.picture = objc.picture;
                myclientModel.lastVisitedTime = objc.lastVisitedTime;
                
                [self.CustomerresultArray addObject:myclientModel];
            }
            
            [self.allCustomerTableview reloadData];
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        
    } WithFailureBlock:^(id error) {
        
        [self RemoveMBProgressHUDLoding];
    }];
}



曹云霄's avatar
曹云霄 committed
142 143 144 145 146 147
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AllCutomerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"allcustomercell" forIndexPath:indexPath];
    cell.contentBackView.layer.masksToBounds = YES;
    cell.contentBackView.layer.cornerRadius = kCornerRadius;
    cell.backgroundColor = [UIColor clearColor];
勾芒's avatar
勾芒 committed
148 149
    cell.Model = [self.CustomerresultArray objectAtIndex_opple:indexPath.row];
    
曹云霄's avatar
曹云霄 committed
150 151 152 153 154
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
155
    return self.CustomerresultArray.count;
曹云霄's avatar
曹云霄 committed
156 157 158 159 160 161 162 163
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 116;
}



勾芒's avatar
勾芒 committed
164 165 166 167 168 169 170 171 172 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 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 252 253 254 255 256 257 258 259 260 261 262 263
#pragma mark -开始筛选时间
- (IBAction)StartscreeningButtonClick:(UIButton *)sender {
    
    DateSelectedViewController *datevc = [[DateSelectedViewController alloc]init];
    //选中时间回调
    [datevc setSelectedDateBlock:^(NSDate *selectedDate) {
        
        [self.begindateButton setTitle:[self dateAsString:selectedDate] forState:UIControlStateNormal];
        [self CalltimeSearch];
    }];
    
    datevc.preferredContentSize = CGSizeMake(300, 250);
    datevc.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = datevc.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = datevc.view;
    [self presentViewController:datevc animated:YES completion:nil];
}


#pragma mark -时间转换NSDate转NSString
- (NSString*)dateAsString:(NSDate*)date {
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString * timeString = [formatter stringFromDate:date];
    return timeString;
    
}

#pragma mark -结束筛选时间
- (IBAction)EndscreeningButtonClick:(UIButton *)sender {
    
    
    DateSelectedViewController *datevc = [[DateSelectedViewController alloc]init];
    //选中时间回调
    [datevc setSelectedDateBlock:^(NSDate *selectedDate) {
        
        [self.enddateButton setTitle:[self dateAsString:selectedDate] forState:UIControlStateNormal];
        [self CalltimeSearch];
        
    }];
    datevc.preferredContentSize = CGSizeMake(300, 250);
    datevc.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = datevc.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = datevc.view;
    [self presentViewController:datevc animated:YES completion:nil];
}


#pragma mark -调用时间段搜索
- (void)CalltimeSearch
{
    NSString *startString = self.begindateButton.currentTitle;
    NSString *endString = self.enddateButton.currentTitle;
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd"];
    NSDate* date = [formater dateFromString:startString];
    [formater setDateFormat:@"yyyy-MM-dd"];
    NSDate* date1 = [formater dateFromString:endString];
    
    //比较结果
    NSInteger result = [self compareOneDay:date withAnotherDay:date1];
    ConsumerQueryCondition *searchCustomer = [[ConsumerQueryCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    searchCustomer.page = page;

    //比较两个NSDate的大小
    switch (result) {
        case -1://start < end
        {
            [formater setDateFormat:@"yyyy-MM-dd HH:dd:ss"];
            searchCustomer.createTimeBegin = [formater stringFromDate:date];
            searchCustomer.createTimeEnd = [formater stringFromDate:date1];
        }
            break;
        case 0://start == end
        {
            [formater setDateFormat:@"yyyy-MM-dd HH:dd:ss"];
            searchCustomer.createTimeBegin = [formater stringFromDate:date];
            searchCustomer.createTimeEnd = [formater stringFromDate:date1];
        }
            break;
        case 1://start > end
        {
            [formater setDateFormat:@"yyyy-MM-dd HH:dd:ss"];
            searchCustomer.createTimeBegin = [formater stringFromDate:date1];
            searchCustomer.createTimeEnd = [formater stringFromDate:date];
        }
            break;
            
        default:
            break;
    }
    
    [self searchCustomerInforMation:searchCustomer];
}

曹云霄's avatar
曹云霄 committed
264

勾芒's avatar
勾芒 committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 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 335 336 337
#pragma mark -比较两个NSDate的大小
- (int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay);
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
    
}

#pragma mark -Return键检测
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    ConsumerQueryCondition *searchCustomer = [[ConsumerQueryCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    searchCustomer.page = page;
    searchCustomer.nameEquals = self.searchTextfield.text;
    searchCustomer.mobileEquals = self.searchTextfield.text;
    
    if (self.searchTextfield.text.length == 0) {
        
        [self ErrorMBProgressView:@"搜索信息不能为空"];
        return YES;
    }
    [self searchCustomerInforMation:searchCustomer];
    return YES;
}

#pragma amrk -搜索客户信息
- (void)searchCustomerInforMation:(ConsumerQueryCondition *)Condition
{

    
    [self CreateMBProgressHUDLoding];
    //request
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/consumer/query"] WithRequestType:0 WithParameter:Condition WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            ConsumerPageResult *result = [[ConsumerPageResult alloc]initWithDictionary:returnValue error:nil];
            NSLog(@"%@",result);
            [self SuccessMBProgressView:@"成功"];
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
        [self RemoveMBProgressHUDLoding];
    }];
}
曹云霄's avatar
曹云霄 committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358





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