DeliveryRequirementReceiptController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. //
  2. // DeliveryRequirementReceiptController.m
  3. // IBOSSHSH
  4. //
  5. // Created by ssl on 2018/1/12.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "DeliveryRequirementReceiptController.h"
  9. #import "RequirementReceiptModel.h"
  10. #import "RequirementReceiptFrame.h"
  11. #import "DeliveryRequirementDetailController.h"
  12. #import "DateFormat.h"
  13. #import "SideSlipModel.h"
  14. #import "RequirementReceiptCell.h"
  15. #import "RequirementReceiptSearchModel.h"
  16. #define receiptTextFont [UIFont systemFontOfSize:14]
  17. @interface DeliveryRequirementReceiptController ()<RequirementReceiptCellDelegate>
  18. @end
  19. @implementation DeliveryRequirementReceiptController
  20. #pragma mark - 公共函数
  21. /**
  22. 视图加载完成函数
  23. */
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. _dataList = [[NSMutableArray 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-55)];
  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. RequirementReceiptSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  64. _deliveryNo=m.deliveryNo;
  65. _receiptType=m.receiptType;
  66. _startDate=m.startDate;
  67. _endDate=m.endDate;
  68. if(_startDate!=nil&&_endDate!=nil){
  69. NSUInteger result= [DateFormat compareDate:_startDate withDate:_endDate];
  70. if(result == -1){
  71. [self showAlertViewText:@"开始日期不能大于结束日期"];
  72. return;
  73. }
  74. }
  75. if(_dataList!=nil&&_dataList.count>0){
  76. [_dataList removeAllObjects];
  77. [_tableView reloadData];
  78. }
  79. [weakself.filterController dismiss];
  80. [self reloadData];
  81. }];
  82. _filterController.animationDuration = .3f;
  83. _filterController.hasHeadView = YES;
  84. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  85. _filterController.dataList = [self packageDataList];
  86. [self reloadData];
  87. }
  88. /**
  89. 安全区视图发生变化
  90. */
  91. -(void)viewSafeAreaInsetsDidChange{
  92. _tableView.frame = CGRectMake(10,55,Screen_Width-20, self.view.superview.frame.size.height-55);
  93. [super viewSafeAreaInsetsDidChange];
  94. }
  95. #pragma mark - 委托函数
  96. /**
  97. 数据加载成功函数
  98. @param sender <#sender description#>
  99. */
  100. - (void)onLoadFinish:(ASIDownManager *)sender {
  101. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  102. [self cancel];
  103. int iNewCount = 0;
  104. _tableView.mTableView.backgroundView = nil;
  105. int iStatus = resultModel.status;
  106. NSString *message = resultModel.message;
  107. if (iStatus == 0) {
  108. NSArray * infoArr =(NSArray*)resultModel.result;
  109. if(infoArr != nil&&infoArr.count > 0)
  110. {
  111. for(int i=0;i<infoArr.count;i++)
  112. {
  113. RequirementReceiptModel *model = [RequirementReceiptModel dk_modelWithDictionary:infoArr[i]];
  114. RequirementReceiptFrame *frame = [RequirementReceiptFrame new];
  115. [frame setReceiptedListFrame:model];
  116. [_dataList addObject:frame];
  117. }
  118. iNewCount = (int)infoArr.count;
  119. _tableView.mbMoreHidden = (iNewCount == 0);
  120. [_tableView FinishLoading];
  121. [_tableView reloadData];
  122. }
  123. else{
  124. [_tableView FinishLoading];
  125. if(_pageNumber == 1)
  126. {
  127. _tableView.mbMoreHidden=YES;
  128. _tableView.mTableView.backgroundView = [self noDataViewByFrame:_tableView.mTableView.bounds];
  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. tableview行数
  157. @param tableView <#tableView description#>
  158. @param section <#section description#>
  159. @return <#return value description#>
  160. */
  161. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  162. {
  163. return 1;
  164. }
  165. /**
  166. tableview分区数
  167. @param tableView <#tableView description#>
  168. @return <#return value description#>
  169. */
  170. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  171. return [_dataList count] ;
  172. }
  173. /**
  174. tableview高度
  175. @param tableView <#tableView description#>
  176. @param indexPath <#indexPath description#>
  177. @return <#return value description#>
  178. */
  179. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  180. NSUInteger row = [indexPath section];
  181. RequirementReceiptFrame *receiptedListFrame = [_dataList objectAtIndex:row];
  182. NSInteger cellHeight = [receiptedListFrame cellHeight];
  183. return cellHeight;
  184. }
  185. /**
  186. 获取tableview cell
  187. @param tableView <#tableView description#>
  188. @param indexPath <#indexPath description#>
  189. @return <#return value description#>
  190. */
  191. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  192. {
  193. static NSString *DeliveryCellIdentifier = @"CellId";
  194. RequirementReceiptCell *cell1 = [tableView dequeueReusableCellWithIdentifier:DeliveryCellIdentifier];
  195. cell1 = [[RequirementReceiptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeliveryCellIdentifier];
  196. cell1.delegate = self;
  197. NSUInteger row = [indexPath section];
  198. RequirementReceiptFrame *frame= [_dataList objectAtIndex:row];
  199. [cell1 setReceiptedListFrame:frame];
  200. return cell1;
  201. }
  202. /**
  203. scrollview 回调函数
  204. @param scrollView <#scrollView description#>
  205. */
  206. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  207. if (scrollView.isDragging) {//显示下拉更新
  208. if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) {
  209. [_tableView.mRefreshHeader setState:PullRefreshNormal];
  210. }
  211. else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) {
  212. //显示松开更新
  213. [_tableView.mRefreshHeader setState:PullRefreshPulling];
  214. }
  215. }
  216. }
  217. /**
  218. tableview分区视图
  219. @param tableView <#tableView description#>
  220. @param section <#section description#>
  221. @return <#return value description#>
  222. */
  223. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  224. {
  225. UIView *view = [[UIView alloc] init];
  226. view.backgroundColor = [UIColor clearColor];
  227. return view ;
  228. }
  229. /**
  230. tableview分区的间隔高度
  231. @param tableView <#tableView description#>
  232. @param section <#section description#>
  233. @return <#return value description#>
  234. */
  235. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  236. {
  237. return 10;
  238. }
  239. /**
  240. tableview列表项点击事件
  241. @param tableView <#tableView description#>
  242. @param indexPath <#indexPath description#>
  243. */
  244. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  245. {
  246. DeliveryRequirementDetailController *detail = [[DeliveryRequirementDetailController alloc] init];
  247. NSUInteger row = [indexPath section];
  248. RequirementReceiptFrame *frame = [_dataList objectAtIndex:row];
  249. NSString *deliveryId = [frame.deliveryListModel deliveryId];
  250. NSString *arrangementId = [frame.deliveryListModel arrangementId];
  251. NSString *recReceiptNo = [frame.deliveryListModel recReceiptNo];
  252. NSString *receiptID = [frame.deliveryListModel receiptID];
  253. detail.receiptID= receiptID;
  254. detail.deliveryId = deliveryId;
  255. detail.arrangementId = arrangementId;
  256. detail.recReceiptNo = recReceiptNo;
  257. self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES;
  258. [self.cNav pushViewController:detail animated:YES];
  259. }
  260. /**
  261. 是否能刷新tableview函数
  262. @param sender <#sender description#>
  263. @return <#return value description#>
  264. */
  265. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  266. return YES;
  267. }
  268. /**
  269. 加载更多函数
  270. @param sender <#sender description#>
  271. */
  272. - (void)LoadMoreList:(RefreshTableView *)sender {
  273. _pageNumber++;
  274. [self reloadData];
  275. }
  276. /**
  277. 下拉刷新函数回调
  278. @param sender <#sender description#>
  279. */
  280. - (void)ReloadList:(RefreshTableView *)sender{
  281. _pageNumber = 1;
  282. [_dataList removeAllObjects];
  283. [_tableView reloadData];
  284. _tableView.mbMoreHidden = YES;
  285. [self reloadData];
  286. }
  287. /**
  288. scrollview回调函数
  289. @param scrollView <#scrollView description#>
  290. */
  291. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  292. {
  293. [self.view endEditing:YES];
  294. }
  295. #pragma mark - 私有函数
  296. /**
  297. 加载数据函数
  298. */
  299. - (void)reloadData
  300. {
  301. [self startLoading];
  302. NSString *urlStr = ServerURL;
  303. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  304. [dict setObject:@"GetDeliveryRequirementReceiptIphone" forKey:@"Action"];
  305. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  306. [dict setObject:kkUserCode forKey:@"UserCode"];
  307. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  308. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  309. [dict setObject:_deliveryNo forKeyedSubscript:@"DeliveryNo"];
  310. [dict setObject:_receiptType forKeyedSubscript:@"ReceiptType"];
  311. [dict setObject:_startDate forKeyedSubscript:@"BeginTime"];
  312. [dict setObject:_endDate forKeyedSubscript:@"endTime"];
  313. [dict setObject:[NSString stringWithFormat:@"%ld",(long)_pageNumber] forKey:@"PageNum"];
  314. [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"];
  315. self.mDownManager = [[ASIDownManager alloc] init];
  316. _mDownManager.delegate = self;
  317. _mDownManager.onRequestSuccess = @selector(onLoadFinish:);
  318. _mDownManager.onRequestFail = @selector(onLoadFail:);
  319. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  320. }
  321. -(void)searchReceiptData{
  322. [_filterController showPagerView:self.cNav];
  323. }
  324. /**
  325. 抽屉加载布局
  326. @return
  327. */
  328. - (NSArray *)packageDataList {
  329. NSMutableArray *dataArray = [NSMutableArray array];
  330. SideSlipModel *model = [[SideSlipModel alloc] init];
  331. model.containerCellClass = @"RequirementReceiptSearchCell";
  332. model.regionTitle = @"查询条件";
  333. [dataArray addObject:model];
  334. return [dataArray mutableCopy];
  335. }
  336. /**
  337. 取消进度条加载函数
  338. */
  339. - (void)cancel {
  340. [self stopLoading];
  341. }
  342. /**
  343. 撤销回执
  344. @param cell <#cell description#>
  345. */
  346. - (void)showReturnReceipt:(RequirementReceiptModel*) model{
  347. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  348. message:@"是否要撤销回执?" preferredStyle:UIAlertControllerStyleAlert];
  349. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  350. style:UIAlertActionStyleDefault
  351. handler:^(UIAlertAction *action){
  352. [self requestCancelDeliveryReceipt:model.receiptID];
  353. }];
  354. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
  355. style:UIAlertActionStyleDefault
  356. handler:^(UIAlertAction *action){
  357. }];
  358. UIColor *cancelColor = [UIColor blackColor];
  359. UIColor *sureColor = [UIColor redColor];
  360. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  361. [okAction setValue:sureColor forKey:@"titleTextColor"];
  362. [alert addAction:okAction];
  363. [alert addAction:cancelAction];
  364. [self presentViewController:alert animated:YES completion:nil];
  365. }
  366. /**
  367. 请求撤销回执
  368. @param receiptID <#receiptID description#>
  369. */
  370. -(void) requestCancelDeliveryReceipt:(NSString *) receiptID{
  371. [self startLoading];
  372. NSString *urlStr = ServerURL;
  373. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  374. [dict setObject:@"CancelDeliveryReceiptIphone" forKey:@"Action"];
  375. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  376. [dict setObject:kkUserCode forKey:@"UserCode"];
  377. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  378. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  379. [dict setObject:receiptID forKeyedSubscript:@"ReceiptID"];
  380. self.mDownManager = [[ASIDownManager alloc] init];
  381. _mDownManager.delegate = self;
  382. _mDownManager.onRequestSuccess = @selector(onRequestCancelReceiptFinish:);
  383. _mDownManager.onRequestFail = @selector(onRequestCancelReceiptFail:);
  384. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  385. }
  386. /**
  387. 请求成功
  388. @param sender <#sender description#>
  389. */
  390. - (void)onRequestCancelReceiptFinish:(ASIDownManager *) sender{
  391. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  392. [self cancel];
  393. int iNewCount = 0;
  394. int iStatus = resultModel.status;
  395. NSString *message = resultModel.message;
  396. if (iStatus == 0) {
  397. [self showAlertViewText:@"撤销成功"];
  398. [self ReloadList:_tableView];
  399. }
  400. else if(iStatus == ActionResultStatusAuthError
  401. ||iStatus == ActionResultStatusNoLogin
  402. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  403. [self showReLoginDialog:message];
  404. return;
  405. }
  406. else{
  407. [self showAlertViewText:message];
  408. return;
  409. }
  410. }
  411. /**
  412. 请求失败
  413. @param sender <#sender description#>
  414. */
  415. - (void)onRequestCancelReceiptFail:(ASIDownManager *) sender{
  416. [self cancel];
  417. [self showAlertViewText:@"请求失败"];
  418. }
  419. @end