DeliveryReceiptedListVC.m 17 KB

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