DeliveryUnreceiptListVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. //
  2. // DeliveryUnreceiptListVC.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2017/7/6.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:配送未回执控制器
  9. #import "DeliveryUnreceiptListVC.h"
  10. #import "UnReceiptListCell.h"
  11. #import "NewDeliveryReceiptVC.h"
  12. #import "SideSlipModel.h"
  13. #import "DeliveryUnReceiptSearchModel.h"
  14. #import "DateFormat.h"
  15. #define receiptTextFont [UIFont systemFontOfSize:14]
  16. @interface DeliveryUnreceiptListVC ()
  17. @end
  18. @implementation DeliveryUnreceiptListVC
  19. #pragma mark - 公共函数
  20. /**
  21. 加载视图函数
  22. */
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. _pageNumber = 1;
  26. _dataList = [[NSMutableArray alloc]init];
  27. _unReceiptInfo = [[UnReceiptInfo alloc]init];
  28. UIView *searchView=[[UIView alloc]init];
  29. searchView.frame=CGRectMake(0, 0, Screen_Width,55);
  30. [searchView setBackgroundColor:[UIColor whiteColor]];
  31. _btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  32. _btnSearch.frame=CGRectMake(15, 10, Screen_Width-70, 35);
  33. [_btnSearch setTitle:@"查询" forState:UIControlStateNormal];
  34. [_btnSearch setBackgroundColor:[UIColor colorWithRed:232.0/255.0 green:233.0/255.0 blue:235.0/255.0 alpha:1]];
  35. [self.view addSubview:searchView];
  36. [searchView addSubview:_btnSearch];
  37. _btnSearch.layer.cornerRadius = 10;
  38. _btnSearch.layer.masksToBounds = YES;
  39. [_btnSearch setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  40. _btnSearch.titleLabel.font=receiptTextFont;
  41. [_btnSearch addTarget:self action:@selector(searchUnreceiptData)
  42. forControlEvents:UIControlEventTouchUpInside];
  43. [self.view addSubview:_btnSearch];
  44. UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom];
  45. scan.frame=CGRectMake(searchView.frame.size.width-40,15,25,25);
  46. scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  47. UIImage *backgroundImg = [UIImage imageNamed:@"icon_scan"];
  48. [scan setBackgroundImage:backgroundImg forState:UIControlStateNormal];
  49. [searchView addSubview:scan];
  50. [scan addTarget:self action:@selector(goScan) forControlEvents:UIControlEventTouchUpInside];
  51. _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(searchView.frame), self.view.frame.size.width - 20, self.view.frame.size.height-rectNavHeight-rectStatusHeight - 150)];
  52. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  53. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  54. _tableView.backgroundColor = [UIColor clearColor];
  55. _tableView.mTableView.showsVerticalScrollIndicator = NO;
  56. _tableView.delegate = self;
  57. [self.view addSubview:_tableView];
  58. _deliveryNo=@"";
  59. _arrangementNo=@"";
  60. _customerName=@"";
  61. _startDate=@"";
  62. _endDate=@"";
  63. _customerAddress=@"";
  64. __weak typeof(self) weakself=self;
  65. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  66. for (SideSlipModel *model in dataList) {
  67. model.selectedItemList = nil;
  68. model.customDict = nil;
  69. }
  70. } commitBlock:^(NSArray *dataList) {
  71. SideSlipModel *serviceRegionModel = dataList[0];
  72. _pageNumber=1;
  73. DeliveryUnReceiptSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  74. _deliveryNo=m.deliveryNo;
  75. _arrangementNo=m.arrangementNo;
  76. _customerName=m.customerName;
  77. _startDate=m.startDate;
  78. _customerAddress=m.customerAddress;
  79. _endDate=m.endDate;
  80. if(_startDate!=nil&&_endDate!=nil){
  81. NSUInteger result= [DateFormat compareDate:_startDate withDate:_endDate];
  82. if(result == -1){
  83. [self showAlertViewText:@"开始日期不能大于结束日期"];
  84. return;
  85. }
  86. }
  87. if(_dataList!=nil&&_dataList.count>0){
  88. [_dataList removeAllObjects];
  89. [_tableView reloadData];
  90. }
  91. [weakself.filterController dismiss];
  92. [self initData];
  93. }];
  94. _filterController.animationDuration = .3f;
  95. _filterController.hasHeadView = YES;
  96. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  97. _filterController.dataList = [self packageDataList];
  98. [self initData];
  99. }
  100. /**
  101. 扫描函数
  102. */
  103. - (void)goScan
  104. {
  105. ScanViewController * rt = [[ScanViewController alloc]init];
  106. rt.rootVC=self;
  107. self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES;
  108. [self.cNav pushViewController:rt animated:YES];
  109. }
  110. -(void)dialTelephone:(NSString *)telephone{
  111. NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",telephone];
  112. CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
  113. if (version >= 10.0) {
  114. /// 大于等于10.0系统使用此openURL方法
  115. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
  116. } else {
  117. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
  118. }
  119. }
  120. /**
  121. 安全区视图发生变化
  122. */
  123. -(void)viewSafeAreaInsetsDidChange{
  124. _tableView.frame = CGRectMake(10,55,Screen_Width-20, self.view.superview.frame.size.height-55);
  125. [super viewSafeAreaInsetsDidChange];
  126. }
  127. #pragma mark - 委托函数
  128. /**
  129. 数据加载完成函数
  130. @param sender <#sender description#>
  131. */
  132. - (void)onLoadFinish:(ASIDownManager *)sender {
  133. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  134. [self cancel];
  135. _tableView.mTableView.backgroundView = nil;
  136. long iNewCount = 0;
  137. int iStatus = resultModel.status;
  138. NSString *message =resultModel.message;
  139. if (iStatus == 0) {
  140. NSArray * infoArr = (NSArray *)resultModel.result;
  141. if(infoArr != nil&&infoArr.count > 0)
  142. {
  143. [_dataList addObjectsFromArray:infoArr];
  144. [_unReceiptInfo parseUnDeliveryInfoArr:_dataList];
  145. iNewCount = infoArr.count;
  146. _tableView.mbMoreHidden = (iNewCount == 0);
  147. [_tableView FinishLoading];
  148. [_tableView reloadData];
  149. }
  150. else{
  151. [_tableView FinishLoading];
  152. if(_pageNumber == 1)
  153. {
  154. _tableView.mbMoreHidden=YES;
  155. UIView *noDataView = [self noDataViewByFrame:_tableView.mTableView.bounds];
  156. _tableView.mTableView.backgroundView =noDataView;
  157. // [self showAlertViewText:@"未找到匹配结果"];
  158. return;
  159. }
  160. else{
  161. _tableView.mbMoreHidden = 1;
  162. }
  163. }
  164. }
  165. else if(iStatus == ActionResultStatusAuthError
  166. ||iStatus == ActionResultStatusNoLogin
  167. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  168. [self showReLoginDialog:message];
  169. return;
  170. }
  171. else{
  172. [self showAlertViewText:message];
  173. [_tableView FinishLoading];
  174. return;
  175. }
  176. }
  177. /**
  178. 数据加载失败函数
  179. @param sender <#sender description#>
  180. */
  181. - (void)onLoadFail:(ASIDownManager *)sender {
  182. [self cancel];
  183. [_tableView reloadData];
  184. [self showAlertViewText:@"网络异常"];
  185. }
  186. - (void)reloadDataWithOnlyCode:(NSString *)code{
  187. if(code!=nil&&code.length>0){
  188. NewDeliveryReceiptVC *newDeliveryVC = [[NewDeliveryReceiptVC alloc] init];
  189. newDeliveryVC.refreshDelegate = self;
  190. newDeliveryVC.sReceiptCode =code;
  191. newDeliveryVC.parentVC = self;
  192. self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES;
  193. [self.cNav pushViewController:newDeliveryVC animated:YES];
  194. }
  195. }
  196. /**
  197. 加载更多函数
  198. @param sender <#sender description#>
  199. */
  200. - (void)LoadMoreList:(RefreshTableView *)sender {
  201. _pageNumber++;
  202. [self initData];
  203. }
  204. /**
  205. 上拉刷新函数
  206. @param sender <#sender description#>
  207. */
  208. - (void)ReloadList:(RefreshTableView *)sender{
  209. _pageNumber = 1;
  210. [_dataList removeAllObjects];
  211. [_tableView reloadData];
  212. _tableView.mbMoreHidden=YES;
  213. [self initData];
  214. }
  215. /**
  216. tableview的行数
  217. @param tableView <#tableView description#>
  218. @param section <#section description#>
  219. @return <#return value description#>
  220. */
  221. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  222. {
  223. return 1;
  224. }
  225. /**
  226. tableview的分区数
  227. @param tableView <#tableView description#>
  228. @return <#return value description#>
  229. */
  230. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  231. return [_dataList count] ;
  232. }
  233. /**
  234. 获取tableview cell
  235. @param tableView <#tableView description#>
  236. @param indexPath <#indexPath description#>
  237. @return <#return value description#>
  238. */
  239. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  240. {
  241. static NSString *DeliveryCellIdentifier = @"CellId";
  242. UnReceiptListCell *cell = [tableView dequeueReusableCellWithIdentifier:DeliveryCellIdentifier];
  243. cell = [[ UnReceiptListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeliveryCellIdentifier];
  244. NSUInteger row = [indexPath section];
  245. UnReceiptListFrame *frame = [_unReceiptInfo.unDeliveryInfoArr objectAtIndex:row];
  246. cell.telephoneDelegate=self;
  247. [cell setUnReceiptListFrame:frame];
  248. return cell;
  249. }
  250. /**
  251. tableview分区视图
  252. @param tableView <#tableView description#>
  253. @param section <#section description#>
  254. @return <#return value description#>
  255. */
  256. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  257. {
  258. UIView *view = [[UIView alloc] init];
  259. view.backgroundColor = [UIColor clearColor];
  260. return view ;
  261. }
  262. /**
  263. tableview分区的间隔高度
  264. @param tableView <#tableView description#>
  265. @param section <#section description#>
  266. @return <#return value description#>
  267. */
  268. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  269. {
  270. return 10;
  271. }
  272. /**
  273. tableview的高度
  274. @param tableView <#tableView description#>
  275. @param indexPath <#indexPath description#>
  276. @return <#return value description#>
  277. */
  278. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  279. NSUInteger row = [indexPath section];
  280. UnReceiptListFrame *unReceiptListFrame = [_unReceiptInfo.unDeliveryInfoArr objectAtIndex:row];
  281. NSInteger cellHeight = [unReceiptListFrame cellHeight];
  282. return cellHeight;
  283. }
  284. /**
  285. scrollview滚动代理
  286. @param scrollView <#scrollView description#>
  287. */
  288. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  289. if (scrollView.isDragging) {//显示下拉更新
  290. if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) {
  291. [_tableView.mRefreshHeader setState:PullRefreshNormal];
  292. }
  293. else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) {
  294. //显示松开更新
  295. [_tableView.mRefreshHeader setState:PullRefreshPulling];
  296. }
  297. }
  298. }
  299. /**
  300. tableview点击函数
  301. @param tableView <#tableView description#>
  302. @param indexPath <#indexPath description#>
  303. */
  304. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  305. {
  306. NewDeliveryReceiptVC *newDeliveryVC = [[NewDeliveryReceiptVC alloc] init];
  307. NSUInteger row = [indexPath section];
  308. newDeliveryVC.refreshDelegate = self;
  309. UnReceiptListFrame *frame = [_unReceiptInfo.unDeliveryInfoArr objectAtIndex:row];
  310. UnReceiptListModel *model = [frame unReceiptListModel];
  311. newDeliveryVC.sReceiptCode = model.deliveryNo;
  312. newDeliveryVC.parentVC = self;
  313. self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES;
  314. [self.cNav pushViewController:newDeliveryVC animated:YES];
  315. }
  316. /**
  317. 刷新数据函数
  318. */
  319. - (void)refreshFollowUpData{
  320. [_dataList removeAllObjects];
  321. _tableView.mbMoreHidden = YES;
  322. [_tableView reloadData];
  323. _pageNumber = 1;
  324. [self initData];
  325. }
  326. /**
  327. 是否能刷新tableview
  328. @param sender <#sender description#>
  329. @return <#return value description#>
  330. */
  331. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  332. return YES;
  333. }
  334. #pragma mark - 私有函数
  335. /**
  336. 加载数据函数
  337. */
  338. - (void)initData
  339. {
  340. [self startLoading];
  341. NSString *urlStr = ServerURL;
  342. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  343. [dict setObject:@"GetIntelligentNoReceiptIphone" forKey:@"Action"];
  344. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  345. [dict setObject:kkUserCode forKey:@"UserCode"];
  346. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  347. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  348. [dict setObject:_deliveryNo forKeyedSubscript:@"DeliveryNo"];
  349. [dict setObject:_arrangementNo forKeyedSubscript:@"ArrangementNo"];
  350. [dict setObject:_customerName forKeyedSubscript:@"CustomerName"];
  351. [dict setObject:_startDate forKeyedSubscript:@"BeginTime"];
  352. [dict setObject:_endDate forKeyedSubscript:@"EndTime"];
  353. [dict setObject:_customerAddress forKeyedSubscript:@"Address"];
  354. [dict setObject:[NSString stringWithFormat:@"%d",(int)_pageNumber] forKey:@"PageNum"];
  355. [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"];
  356. self.mDownManager = [[ASIDownManager alloc] init];
  357. self.mDownManager.delegate = self;
  358. self.mDownManager.onRequestSuccess = @selector(onLoadFinish:);
  359. self.mDownManager.onRequestFail = @selector(onLoadFail:);
  360. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  361. }
  362. /**
  363. 弹出抽屉
  364. */
  365. -(void)searchUnreceiptData{
  366. [_filterController showPagerView:self.cNav];
  367. }
  368. /**
  369. 抽屉加载布局
  370. @return
  371. */
  372. - (NSArray *)packageDataList {
  373. NSMutableArray *dataArray = [NSMutableArray array];
  374. SideSlipModel *model = [[SideSlipModel alloc] init];
  375. model.containerCellClass = @"DeliveryUnreceiptSearchCell";
  376. model.regionTitle = @"查询条件";
  377. [dataArray addObject:model];
  378. return [dataArray mutableCopy];
  379. }
  380. /**
  381. 取消进度条
  382. */
  383. - (void)cancel {
  384. [self stopLoading];
  385. }
  386. - (void)ReloadList{
  387. [self ReloadList:_tableView];
  388. }
  389. @end