| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // ForgetClientMoreVC.m
- // shiku_im
- //
- // Created by huangyp-pc on 16/8/18.
- // Copyright © 2016年 Reese. All rights reserved.
- //
- #import "ForgetClientMoreVC.h"
- #import "AFNetworking.h"
- #import "ForgetClientCell.h"
- static NSString *cellID = @"cellID";
- @interface ForgetClientMoreVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic,strong) UITableView *tableView;
- @end
- @implementation ForgetClientMoreVC
- {
- NSMutableArray *_customerData;
- int _pageSize;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.title = @"遗忘客户";
- self.view.backgroundColor = BGKJ_COLOR;
-
- UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
- btn2.frame = CGRectMake(0, 5, 22, 22);
- UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
- image.image = [UIImage imageNamed:@"icon_back_nor3"];
- [btn2 addSubview:image];
- [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
- self.navigationItem.leftBarButtonItems = @[bbi2];
-
- _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = 70;
- [self.view addSubview:_tableView];
-
- UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
- v.backgroundColor = [UIColor whiteColor];
- _tableView.tableFooterView = v;
-
- [_tableView registerClass:[ForgetClientCell class] forCellReuseIdentifier:cellID];
-
- //下拉刷新
- [self setupHeader];
- [self setupFooter];
-
- _customerData = [[NSMutableArray alloc]init];
- _pageSize = 10;
-
- [self getForgetClientDataFromServer];
- }
- -(void)getForgetClientDataFromServer //获取被遗忘用户的数据
- {
- [_customerData removeAllObjects];
-
- /*接口:mobile/crm/getInactionCusts.action
- 参数:String emcode,int page,int pageSize*/
- NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip=[UASUserInfo shareManager].urlIp;
- NSString *emcode=[[NSUserDefaults standardUserDefaults] stringForKey:@"erpaccount"];
- NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
- NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- NSString *url = [NSString stringWithFormat:@"%@mobile/crm/getInactionCusts.action?emcode=%@&page=1&pageSize=%d&sessionId=%@&master=%@&sessionUser=%@",ip,emcode,_pageSize,sessionId,master,sessionUser];
-
-
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
-
- //拼接sessionID
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- // DLog(@"adfssadvfad:%@",responseObject);
- // _customerNumber = [NSString stringWithFormat:@"%@",responseObject[@"datas"][@"customernum"]];
-
- NSString *sessionId = [NSString stringWithFormat:@"%@",responseObject[@"sessionId"]];
- if (![sessionId isEqualToString:@"(null)"]) {
- [[NSUserDefaults standardUserDefaults] setObject:sessionId forKey:@"sessionId"];
- }
-
- for (id obj in responseObject[@"datas"][@"cusdatas"]) {
- [_customerData addObject:obj];
- }
-
- [_tableView reloadData];
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"请求失败:%@",error);
- [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"获取被遗忘用户的数据失败"];
- }];
- }
- //下拉刷新相关函数
- - (void)setupHeader
- {
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- _pageSize = 10;
- [self getForgetClientDataFromServer];
- [_tableView.mj_header endRefreshing];
- });
- }];
-
-
-
-
- // 进入页面自动加载一次数据
- //[refreshHeader beginRefreshing];
- }
- //上啦刷新
- - (void)setupFooter
- {
-
- _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- _pageSize += 10;
- [self getForgetClientDataFromServer];
- [_tableView.mj_footer endRefreshing];
-
- });
-
-
-
- }];
-
- }
- #pragma mark -- UITableView Delegate / DataSoure
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _customerData.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- ForgetClientCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
-
- if (_customerData.count == 0) {
- cell.companyLbl.text = [NSString stringWithFormat:@"客户: ****有限公司"];
- cell.dateLbl.text = @"最后跟进 0000-00-00";
- cell.followDay.text = @"距离上次跟进有__天";
- }else{
- cell.companyLbl.text = [NSString stringWithFormat:@"客户:%@",_customerData[indexPath.row][0]];
- cell.dateLbl.text = [NSString stringWithFormat:@"最后跟进 %@",_customerData[indexPath.row][1]];
-
- NSDate *date = [NSDate date];//获取当前时间
- //字符串转换为日期
- NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
- [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
- NSString *str = [NSString stringWithFormat:@"%@",_customerData[indexPath.row][1]];
- NSDate *fromDate =[dateFormat dateFromString:str];
-
- //算两天的日期
- NSInteger a;
- a = [self getDaysFrom:fromDate To:date];
-
- cell.followDay.text = [NSString stringWithFormat:@"距离上次跟进有%ld天",(long)a];;
- }
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // XiaShuVC *xiashuVC = [[XiaShuVC alloc]init];
- // [self.navigationController pushViewController:xiashuVC animated:YES];
- }
- /*
- 显示完整分割线
- */
- -(void)viewDidLayoutSubviews {
-
- if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
- [_tableView setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
- [_tableView setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- // 计算两天日期之间的天数
- -(NSInteger)getDaysFrom:(NSDate *)serverDate To:(NSDate *)endDate
- {
- NSCalendar *gregorian = [[NSCalendar alloc]
- initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
-
- [gregorian setFirstWeekday:2];
-
- //去掉时分秒信息
- NSDate *fromDate;
- NSDate *toDate;
- [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:NULL forDate:serverDate];
- [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:NULL forDate:endDate];
- NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0];
-
- return dayComponents.day;
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /*
- #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
|