CustomerTraceListVc.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. //
  2. // CustomerTraceListVc.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2019/4/10.
  6. // Copyright © 2019 elongtian. All rights reserved.
  7. //
  8. #import "CustomerTraceListVc.h"
  9. @interface CustomerTraceListVc ()
  10. @end
  11. @implementation CustomerTraceListVc
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. _dataList=[[NSMutableArray alloc]init];
  15. [self loadNavStyle];
  16. [self initUI];
  17. [self initSlideSlip];
  18. UIView *view = [self backGroundPromptViewByFrame:_vTableView.bounds promptStr:@"请筛选后查询"];
  19. _vTableView.tableHeaderView = nil;
  20. _vTableView.backgroundView = view;
  21. }
  22. /**
  23. 安全区视图发生变化
  24. */
  25. -(void)viewSafeAreaInsetsDidChange{
  26. _vTableView.frame=CGRectMake(0, 0, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height);
  27. [super viewSafeAreaInsetsDidChange];
  28. }
  29. -(void)search{
  30. [_filterController show];
  31. }
  32. /**
  33. 初始化UI
  34. */
  35. -(void)initUI
  36. {
  37. _vTableView = [[UITableView alloc]
  38. initWithFrame:CGRectMake(0,0,
  39. self.view.frame.size.width,
  40. Screen_Height)];
  41. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  43. _vTableView.backgroundColor = [UIColor whiteColor];
  44. _vTableView.delegate = self;
  45. _vTableView.dataSource=self;
  46. [self.view addSubview:_vTableView];
  47. }
  48. /**
  49. 抽屉初始化
  50. */
  51. - (void)initSlideSlip{
  52. // 抽屉对象
  53. __weak typeof(self) weakself=self;
  54. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  55. for (SideSlipModel *model in dataList) {
  56. //selectedItem
  57. model.selectedItemList = nil;
  58. model.customDict = nil;
  59. }
  60. } commitBlock:^(NSArray *dataList) {
  61. // 查询条件
  62. SideSlipModel *serviceRegionModel = dataList[0];
  63. self->_searchModel = [serviceRegionModel.customDict objectForKey:CUSTOMER_TRACE_LIST_SEARCH_MODEL];
  64. if(self->_dataList!=nil&&self->_dataList.count>0){
  65. [self->_dataList removeAllObjects];
  66. [self->_vTableView reloadData];
  67. }
  68. if([self->_searchModel.estimateSalesAmountStartDate isEqualToString:@"请选择预估销售金额创建开始日期"]){
  69. self->_searchModel.estimateSalesAmountStartDate=@"";
  70. }
  71. if([self->_searchModel.estimateSalesAmountEndDate isEqualToString:@"请选择预估销售金额创建结束日期"]){
  72. self->_searchModel.estimateSalesAmountEndDate=@"";
  73. }
  74. if(self->_searchModel.estimateSalesAmountStartDate.length>0&&self->_searchModel.estimateSalesAmountEndDate.length>0){
  75. NSUInteger result= [DateFormat compareDate:self->_searchModel.estimateSalesAmountStartDate withDate:self->_searchModel.estimateSalesAmountEndDate];
  76. if(result == -1){
  77. [self showAlertViewText:@"预估销售金额创建开始日期不能大于结束日期"];
  78. return;
  79. }
  80. NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
  81. [dateformater setDateFormat:@"yyyy-MM-dd"];
  82. NSDate *dta = [[NSDate alloc] init];
  83. NSDate *dtb = [[NSDate alloc] init];
  84. dta = [dateformater dateFromString:self->_searchModel.estimateSalesAmountStartDate];
  85. dtb = [dateformater dateFromString:self->_searchModel.estimateSalesAmountEndDate];
  86. NSInteger days=[DateFormat calculateDaysFromBegin:dta end:dtb];
  87. if(days>31){
  88. [self showAlertViewText:@"预估销售金额日期间隔不能超过31天"];
  89. return;
  90. }
  91. }
  92. if([self->_searchModel.accountStartDate isEqualToString:@"请选择账务开始日期"]){
  93. self->_searchModel.accountStartDate=@"";
  94. }
  95. if([self->_searchModel.accountEndDate isEqualToString:@"请选择账务结束日期"]){
  96. self->_searchModel.accountEndDate=@"";
  97. }
  98. if(self->_searchModel.accountStartDate.length>0&&self->_searchModel.accountEndDate.length>0){
  99. NSUInteger result= [DateFormat compareDate:self->_searchModel.accountStartDate withDate:self->_searchModel.accountEndDate];
  100. if(result == -1){
  101. [self showAlertViewText:@"账务开始日期不能大于结束日期"];
  102. return;
  103. }
  104. NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
  105. [dateformater setDateFormat:@"yyyy-MM-dd"];
  106. NSDate *dta = [[NSDate alloc] init];
  107. NSDate *dtb = [[NSDate alloc] init];
  108. dta = [dateformater dateFromString:self->_searchModel.accountStartDate];
  109. dtb = [dateformater dateFromString:self->_searchModel.accountEndDate];
  110. NSInteger days=[DateFormat calculateDaysFromBegin:dta end:dtb];
  111. if(days>31){
  112. [self showAlertViewText:@"账务日期间隔不能超过31天"];
  113. return;
  114. }
  115. }
  116. [weakself.filterController dismiss];
  117. [self reloadData];
  118. }];
  119. _filterController.animationDuration = AnimationDuration;
  120. _filterController.hasHeadView = YES;
  121. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  122. _filterController.dataList = [self packageDataList];
  123. }
  124. /**
  125. 加载数据
  126. */
  127. - (void)reloadData
  128. {
  129. [self startLoading];
  130. NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL];
  131. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  132. [dict setObject:@"GetCustomerTrackingIphone" forKey:@"Action"];
  133. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  134. [dict setObject:kkUserCode forKey:@"UserCode"];
  135. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  136. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  137. [dict setObject:_searchModel.organizationCode==nil?@"":_searchModel.organizationCode forKeyedSubscript:@"OrganizationCode"];
  138. [dict setObject:_searchModel.accountStartDate==nil?@"":_searchModel.accountStartDate forKeyedSubscript:@"AccountDateFrom"];
  139. [dict setObject:_searchModel.accountEndDate==nil?@"":_searchModel.accountEndDate forKeyedSubscript:@"AccountDateTo"];
  140. [dict setObject:_searchModel.estimateSalesAmountStartDate==nil?@"":_searchModel.estimateSalesAmountStartDate forKeyedSubscript:@"CreateDateFrom"];
  141. [dict setObject:_searchModel.estimateSalesAmountStartDate==nil?@"":_searchModel.estimateSalesAmountStartDate forKeyedSubscript:@"CreateDateTo"];
  142. _downManager = [[ASIDownManager alloc] init];
  143. _downManager.delegate = self;
  144. _downManager.onRequestSuccess = @selector(onLoadFinish:);
  145. _downManager.onRequestFail = @selector(onLoadFail:);
  146. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  147. }
  148. #pragma mark 委托接口回调函数
  149. /**
  150. 调用接口成功回调
  151. @param sender <#sender description#>
  152. */
  153. - (void)onLoadFinish:(ASIDownManager *)sender {
  154. // 取消进度条
  155. [self cancel];
  156. // 服务器返回数据
  157. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  158. // 服务器返回数据状态值
  159. int iStatus = resultModel.status;
  160. // 服务器返回数据消息
  161. NSString *message = resultModel.message;
  162. _vTableView.backgroundView = nil;
  163. // 服务器返回数据状态值正确
  164. if (iStatus == 0) {
  165. NSArray *infoArray = (NSArray *)resultModel.result;
  166. if(infoArray!=nil&&infoArray.count>0){
  167. for(int i=0;i<infoArray.count;i++){
  168. NSDictionary *infoDic=[infoArray objectAtIndex:i];
  169. CustomerTraceListModel *model = [CustomerTraceListModel dk_modelWithDictionary:infoDic];
  170. [_dataList addObject:model];
  171. }
  172. [_vTableView reloadData];
  173. }
  174. else{
  175. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  176. // 未找到匹配结果
  177. if(_dataList == nil || _dataList.count == 0){
  178. _vTableView.backgroundView = [self noDataViewByFrame:_vTableView.bounds];
  179. [self showAlertViewBackText:@"未找到匹配结果"];
  180. }
  181. }
  182. }
  183. // 服务器返回数据状态值异常
  184. else if(iStatus == ActionResultStatusAuthError
  185. ||iStatus == ActionResultStatusNoLogin
  186. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  187. [self showReLoginDialog:message];
  188. }
  189. else{
  190. [self showAlertViewText:message];
  191. return;
  192. }
  193. }
  194. /**
  195. 调用接口失败回调
  196. @param sender <#sender description#>
  197. */
  198. - (void)onLoadFail:(ASIDownManager *)sender {
  199. [self cancel];
  200. [_vTableView reloadData];
  201. [self showAlertViewText:@"网络异常"];
  202. }
  203. /**
  204. 单元格cell个数
  205. @param tableView <#tableView description#>
  206. @param section <#section description#>
  207. @return <#return value description#>
  208. */
  209. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  210. {
  211. return [_dataList count];
  212. }
  213. /**
  214. <#Description#>
  215. @param tableView <#tableView description#>
  216. @return <#return value description#>
  217. */
  218. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  219. return 1;
  220. }
  221. /**
  222. 高度
  223. @param tableView <#tableView description#>
  224. @param indexPath <#indexPath description#>
  225. @return <#return value description#>
  226. */
  227. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  228. return 150;
  229. }
  230. /**
  231. 每个单元格cell
  232. @param tableView <#tableView description#>
  233. @param indexPath <#indexPath description#>
  234. @return <#return value description#>
  235. */
  236. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  237. {
  238. static NSString *cellIdentifier = @"CustomerTraceListCell";
  239. CustomerTraceListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  240. if (!cell) {
  241. cell = [[CustomerTraceListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  242. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  243. }
  244. else
  245. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  246. {
  247. while ([cell.contentView.subviews lastObject] != nil) {
  248. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  249. }
  250. }
  251. CustomerTraceListModel *traceListModel= [_dataList objectAtIndex:indexPath.row];
  252. [cell setCustomerTraceListCell:traceListModel];
  253. return cell;
  254. }
  255. /**
  256. 点击单元格事件
  257. @param tableView tableView description
  258. @param indexPath indexPath description
  259. */
  260. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  261. {
  262. self.hidesBottomBarWhenPushed=YES;
  263. CustomerTraceListDetailVc *detailVc = [[CustomerTraceListDetailVc alloc] init];
  264. CustomerTraceListModel *traceListModel= [_dataList objectAtIndex:indexPath.row];
  265. detailVc.traceListModel=traceListModel;
  266. [self.navigationController pushViewController:detailVc animated:YES];
  267. }
  268. /**
  269. 进度条隐藏
  270. */
  271. - (void)cancel {
  272. [self stopLoading];
  273. }
  274. /**
  275. 数据源
  276. @return <#return value description#>
  277. */
  278. - (NSArray *)packageDataList {
  279. NSMutableArray *dataArray = [NSMutableArray array];
  280. SideSlipModel *model = [[SideSlipModel alloc] init];
  281. model.containerCellClass = @"CustomerTraceListSearchCell";
  282. model.regionTitle = @"查询条件";
  283. [dataArray addObject:model];
  284. return [dataArray mutableCopy];
  285. }
  286. /**
  287. 导航按钮样式
  288. */
  289. - (void)loadNavStyle {
  290. self.navigationItem.title = @"客户跟踪表";
  291. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  292. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  293. [button addTarget:self action:@selector(goBack)
  294. forControlEvents:UIControlEventTouchUpInside];
  295. button.frame = CGRectMake(0, 0,45,22);
  296. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  297. self.navigationItem.leftBarButtonItem = menuButton;
  298. // 右边
  299. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 12)];
  300. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  301. [btnfilter addTarget:self action:@selector(search)
  302. forControlEvents:UIControlEventTouchUpInside];
  303. btnfilter.frame = CGRectMake(0, 0,16, 16);
  304. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  305. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  306. forState:UIControlStateNormal];
  307. [v addSubview:btnfilter];
  308. UIButton *filterLbl = [[UIButton alloc]init];
  309. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  310. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  311. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  312. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  313. [filterLbl addTarget:self action:@selector(search)
  314. forControlEvents:UIControlEventTouchUpInside];
  315. [v addSubview:filterLbl];
  316. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  317. self.navigationItem.rightBarButtonItem = menubtnAdd;
  318. }
  319. @end