ForgetClientMoreVC.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // ForgetClientMoreVC.m
  3. // shiku_im
  4. //
  5. // Created by huangyp-pc on 16/8/18.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "ForgetClientMoreVC.h"
  9. #import "AFNetworking.h"
  10. #import "ForgetClientCell.h"
  11. static NSString *cellID = @"cellID";
  12. @interface ForgetClientMoreVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic,strong) UITableView *tableView;
  14. @end
  15. @implementation ForgetClientMoreVC
  16. {
  17. NSMutableArray *_customerData;
  18. int _pageSize;
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.title = @"遗忘客户";
  24. self.view.backgroundColor = BGKJ_COLOR;
  25. UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
  26. btn2.frame = CGRectMake(0, 5, 22, 22);
  27. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
  28. image.image = [UIImage imageNamed:@"icon_back_nor3"];
  29. [btn2 addSubview:image];
  30. [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  31. UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
  32. self.navigationItem.leftBarButtonItems = @[bbi2];
  33. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  34. _tableView.delegate = self;
  35. _tableView.dataSource = self;
  36. _tableView.rowHeight = 70;
  37. [self.view addSubview:_tableView];
  38. UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
  39. v.backgroundColor = [UIColor whiteColor];
  40. _tableView.tableFooterView = v;
  41. [_tableView registerClass:[ForgetClientCell class] forCellReuseIdentifier:cellID];
  42. //下拉刷新
  43. [self setupHeader];
  44. [self setupFooter];
  45. _customerData = [[NSMutableArray alloc]init];
  46. _pageSize = 10;
  47. [self getForgetClientDataFromServer];
  48. }
  49. -(void)getForgetClientDataFromServer //获取被遗忘用户的数据
  50. {
  51. [_customerData removeAllObjects];
  52. /*接口:mobile/crm/getInactionCusts.action
  53. 参数:String emcode,int page,int pageSize*/
  54. NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  55. NSString *ip=[UASUserInfo shareManager].urlIp;
  56. NSString *emcode=[[NSUserDefaults standardUserDefaults] stringForKey:@"erpaccount"];
  57. NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  58. NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  59. NSString *url = [NSString stringWithFormat:@"%@mobile/crm/getInactionCusts.action?emcode=%@&page=1&pageSize=%d&sessionId=%@&master=%@&sessionUser=%@",ip,emcode,_pageSize,sessionId,master,sessionUser];
  60. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  61. UASNetworkManager *manager = [UASNetworkManager shareManager];
  62. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  63. //拼接sessionID
  64. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  65. //设置cookie
  66. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  67. [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
  68. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  69. // DLog(@"adfssadvfad:%@",responseObject);
  70. // _customerNumber = [NSString stringWithFormat:@"%@",responseObject[@"datas"][@"customernum"]];
  71. NSString *sessionId = [NSString stringWithFormat:@"%@",responseObject[@"sessionId"]];
  72. if (![sessionId isEqualToString:@"(null)"]) {
  73. [[NSUserDefaults standardUserDefaults] setObject:sessionId forKey:@"sessionId"];
  74. }
  75. for (id obj in responseObject[@"datas"][@"cusdatas"]) {
  76. [_customerData addObject:obj];
  77. }
  78. [_tableView reloadData];
  79. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  80. DLog(@"请求失败:%@",error);
  81. [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"获取被遗忘用户的数据失败"];
  82. }];
  83. }
  84. //下拉刷新相关函数
  85. - (void)setupHeader
  86. {
  87. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  88. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  89. _pageSize = 10;
  90. [self getForgetClientDataFromServer];
  91. [_tableView.mj_header endRefreshing];
  92. });
  93. }];
  94. // 进入页面自动加载一次数据
  95. //[refreshHeader beginRefreshing];
  96. }
  97. //上啦刷新
  98. - (void)setupFooter
  99. {
  100. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  101. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  102. _pageSize += 10;
  103. [self getForgetClientDataFromServer];
  104. [_tableView.mj_footer endRefreshing];
  105. });
  106. }];
  107. }
  108. #pragma mark -- UITableView Delegate / DataSoure
  109. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  110. {
  111. return 1;
  112. }
  113. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  114. {
  115. return _customerData.count;
  116. }
  117. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  118. {
  119. ForgetClientCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  120. if (_customerData.count == 0) {
  121. cell.companyLbl.text = [NSString stringWithFormat:@"客户: ****有限公司"];
  122. cell.dateLbl.text = @"最后跟进 0000-00-00";
  123. cell.followDay.text = @"距离上次跟进有__天";
  124. }else{
  125. cell.companyLbl.text = [NSString stringWithFormat:@"客户:%@",_customerData[indexPath.row][0]];
  126. cell.dateLbl.text = [NSString stringWithFormat:@"最后跟进 %@",_customerData[indexPath.row][1]];
  127. NSDate *date = [NSDate date];//获取当前时间
  128. //字符串转换为日期
  129. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
  130. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  131. NSString *str = [NSString stringWithFormat:@"%@",_customerData[indexPath.row][1]];
  132. NSDate *fromDate =[dateFormat dateFromString:str];
  133. //算两天的日期
  134. NSInteger a;
  135. a = [self getDaysFrom:fromDate To:date];
  136. cell.followDay.text = [NSString stringWithFormat:@"距离上次跟进有%ld天",(long)a];;
  137. }
  138. return cell;
  139. }
  140. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  141. {
  142. // XiaShuVC *xiashuVC = [[XiaShuVC alloc]init];
  143. // [self.navigationController pushViewController:xiashuVC animated:YES];
  144. }
  145. /*
  146. 显示完整分割线
  147. */
  148. -(void)viewDidLayoutSubviews {
  149. if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
  150. [_tableView setSeparatorInset:UIEdgeInsetsZero];
  151. }
  152. if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
  153. [_tableView setLayoutMargins:UIEdgeInsetsZero];
  154. }
  155. }
  156. // 计算两天日期之间的天数
  157. -(NSInteger)getDaysFrom:(NSDate *)serverDate To:(NSDate *)endDate
  158. {
  159. NSCalendar *gregorian = [[NSCalendar alloc]
  160. initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  161. [gregorian setFirstWeekday:2];
  162. //去掉时分秒信息
  163. NSDate *fromDate;
  164. NSDate *toDate;
  165. [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:NULL forDate:serverDate];
  166. [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:NULL forDate:endDate];
  167. NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0];
  168. return dayComponents.day;
  169. }
  170. -(void)viewWillAppear:(BOOL)animated
  171. {
  172. [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
  173. }
  174. - (void)didReceiveMemoryWarning {
  175. [super didReceiveMemoryWarning];
  176. // Dispose of any resources that can be recreated.
  177. }
  178. -(void)backAction
  179. {
  180. [self.navigationController popViewControllerAnimated:YES];
  181. }
  182. /*
  183. #pragma mark - Navigation
  184. // In a storyboard-based application, you will often want to do a little preparation before navigation
  185. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  186. // Get the new view controller using [segue destinationViewController].
  187. // Pass the selected object to the new view controller.
  188. }
  189. */
  190. @end