DispatchRequirementReceiptController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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 "DispatchRequirementReceiptController.h"
  9. #import "DispatchReceiptModel.h"
  10. #import "DispatchReceiptFrame.h"
  11. #import "DispatchRequirementDetailController.h"
  12. #import "DateFormat.h"
  13. #import "SideSlipModel.h"
  14. #import "DispatchReceiptCell.h"
  15. #define receiptTextFont [UIFont systemFontOfSize:14]
  16. @interface DispatchRequirementReceiptController ()<DispatchReceiptCellDelegate>
  17. @end
  18. @implementation DispatchRequirementReceiptController
  19. #pragma mark - 公共函数
  20. /**
  21. 视图加载完成函数
  22. */
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. _dataList = [[NSMutableArray alloc]init];
  26. UIView *searchView=[[UIView alloc]init];
  27. searchView.frame=CGRectMake(0, 0, Screen_Width,55);
  28. [searchView setBackgroundColor:[UIColor whiteColor]];
  29. _btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  30. _btnSearch.frame=CGRectMake(15, 10, Screen_Width-30, 35);
  31. [_btnSearch setTitle:@"查询" forState:UIControlStateNormal];
  32. [_btnSearch setBackgroundColor:[UIColor colorWithRed:232.0/255.0 green:233.0/255.0 blue:235.0/255.0 alpha:1]];
  33. _btnSearch.layer.cornerRadius = 10;
  34. _btnSearch.layer.masksToBounds = YES;
  35. [_btnSearch setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  36. _btnSearch.titleLabel.font=receiptTextFont;
  37. [_btnSearch addTarget:self action:@selector(searchReceiptData)
  38. forControlEvents:UIControlEventTouchUpInside];
  39. [self.view addSubview:searchView];
  40. [searchView addSubview:_btnSearch];
  41. _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(searchView.frame), self.view.frame.size.width - 20, self.view.frame.size.height-55)];
  42. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  44. _tableView.backgroundColor = [UIColor clearColor];
  45. _tableView.mTableView.showsVerticalScrollIndicator = NO;
  46. _tableView.delegate = self;
  47. [self.view addSubview:_tableView];
  48. _pageNumber = 1;
  49. _arrangementNo=@"";
  50. _startDate=@"";
  51. _endDate=@"";
  52. _customerName=@"";
  53. _customerTelephone=@"";
  54. _receiptNo=@"";
  55. __weak typeof(self) weakself=self;
  56. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  57. for (SideSlipModel *model in dataList) {
  58. model.selectedItemList = nil;
  59. model.customDict = nil;
  60. }
  61. } commitBlock:^(NSArray *dataList) {
  62. _pageNumber=1;
  63. SideSlipModel *serviceRegionModel = dataList[0];
  64. DispatchReceiptSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  65. _arrangementNo=m.arrangementNo;
  66. _customerName=m.customerName;
  67. _customerTelephone=m.customerTelephone;
  68. _receiptNo=m.receiptNo;
  69. _startDate=m.startDate;
  70. _endDate=m.endDate;
  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. [_tableView reloadData];
  81. }
  82. [weakself.filterController dismiss];
  83. [self reloadData];
  84. }];
  85. _filterController.animationDuration = .3f;
  86. _filterController.hasHeadView = YES;
  87. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  88. _filterController.dataList = [self packageDataList];
  89. [self reloadData];
  90. }
  91. /**
  92. 安全区视图发生变化
  93. */
  94. -(void)viewSafeAreaInsetsDidChange{
  95. _tableView.frame = CGRectMake(10,55,Screen_Width-20, self.view.superview.frame.size.height-55);
  96. [super viewSafeAreaInsetsDidChange];
  97. }
  98. #pragma mark - 委托函数
  99. /**
  100. 数据加载成功函数
  101. @param sender <#sender description#>
  102. */
  103. - (void)onLoadFinish:(ASIDownManager *)sender {
  104. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  105. [self cancel];
  106. int iNewCount = 0;
  107. int iStatus = resultModel.status;
  108. NSString *message = resultModel.message;
  109. if (iStatus == 0) {
  110. NSArray * infoArr =(NSArray*)resultModel.result;
  111. if(infoArr != nil&&infoArr.count > 0)
  112. {
  113. for(int i=0;i<infoArr.count;i++)
  114. {
  115. DispatchReceiptModel *model = [DispatchReceiptModel dk_modelWithDictionary:infoArr[i]];
  116. DispatchReceiptFrame *frame = [DispatchReceiptFrame new];
  117. [frame setReceiptedListFrame:model];
  118. [_dataList addObject:frame];
  119. }
  120. iNewCount = (int)infoArr.count;
  121. _tableView.mbMoreHidden = (iNewCount == 0);
  122. [_tableView FinishLoading];
  123. [_tableView reloadData];
  124. }
  125. else{
  126. [_tableView FinishLoading];
  127. if(_pageNumber == 1)
  128. {
  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. DispatchReceiptFrame *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. DispatchReceiptCell *cell1 = [tableView dequeueReusableCellWithIdentifier:DeliveryCellIdentifier];
  195. cell1 = [[DispatchReceiptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeliveryCellIdentifier];
  196. cell1.delegate = self;
  197. cell1.telephoneDelegate=self;
  198. NSUInteger row = [indexPath section];
  199. DispatchReceiptFrame *frame= [_dataList objectAtIndex:row];
  200. [cell1 setReceiptedListFrame:frame];
  201. return cell1;
  202. }
  203. -(void)dialTelephone:(NSString *)telephone{
  204. NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",telephone];
  205. CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
  206. if (version >= 10.0) {
  207. /// 大于等于10.0系统使用此openURL方法
  208. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
  209. } else {
  210. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
  211. }
  212. }
  213. /**
  214. scrollview 回调函数
  215. @param scrollView <#scrollView description#>
  216. */
  217. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  218. if (scrollView.isDragging) {//显示下拉更新
  219. if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) {
  220. [_tableView.mRefreshHeader setState:PullRefreshNormal];
  221. }
  222. else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) {
  223. //显示松开更新
  224. [_tableView.mRefreshHeader setState:PullRefreshPulling];
  225. }
  226. }
  227. }
  228. /**
  229. tableview分区视图
  230. @param tableView <#tableView description#>
  231. @param section <#section description#>
  232. @return <#return value description#>
  233. */
  234. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  235. {
  236. UIView *view = [[UIView alloc] init];
  237. view.backgroundColor = [UIColor clearColor];
  238. return view ;
  239. }
  240. /**
  241. tableview分区的间隔高度
  242. @param tableView <#tableView description#>
  243. @param section <#section description#>
  244. @return <#return value description#>
  245. */
  246. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  247. {
  248. return 10;
  249. }
  250. /**
  251. tableview列表项点击事件
  252. @param tableView <#tableView description#>
  253. @param indexPath <#indexPath description#>
  254. */
  255. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  256. {
  257. DispatchRequirementDetailController *detail = [[DispatchRequirementDetailController alloc] init];
  258. NSUInteger row = [indexPath section];
  259. DispatchReceiptFrame *frame = [_dataList objectAtIndex:row];
  260. NSString *receiptID = [frame.deliveryListModel receiptID];
  261. detail.receiptID= receiptID;
  262. detail.receiptTypeFlag=[frame.deliveryListModel recReceiptType];
  263. detail.refreshDelegate=self;
  264. self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES;
  265. [self.cNav pushViewController:detail animated:YES];
  266. }
  267. /**
  268. 是否能刷新tableview函数
  269. @param sender <#sender description#>
  270. @return <#return value description#>
  271. */
  272. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  273. return YES;
  274. }
  275. /**
  276. 加载更多函数
  277. @param sender <#sender description#>
  278. */
  279. - (void)LoadMoreList:(RefreshTableView *)sender {
  280. _pageNumber++;
  281. [self reloadData];
  282. }
  283. /**
  284. 下拉刷新函数回调
  285. @param sender <#sender description#>
  286. */
  287. - (void)ReloadList:(RefreshTableView *)sender{
  288. _pageNumber = 1;
  289. [_dataList removeAllObjects];
  290. [_tableView reloadData];
  291. _tableView.mbMoreHidden = YES;
  292. [self reloadData];
  293. }
  294. /**
  295. scrollview回调函数
  296. @param scrollView <#scrollView description#>
  297. */
  298. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  299. {
  300. [self.view endEditing:YES];
  301. }
  302. #pragma mark - 私有函数
  303. /**
  304. 加载数据函数
  305. */
  306. - (void)reloadData
  307. {
  308. [self startLoading];
  309. NSString *urlStr = ServerURL;
  310. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  311. [dict setObject:@"GetInstallationDemandReceiptIphone" forKey:@"Action"];
  312. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  313. [dict setObject:kkUserCode forKey:@"UserCode"];
  314. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  315. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  316. [dict setObject:_arrangementNo forKeyedSubscript:@"ArrangementNo"];
  317. [dict setObject:_receiptNo forKeyedSubscript:@"ReceiptNo"];
  318. [dict setObject:_startDate forKeyedSubscript:@"BeginTime"];
  319. [dict setObject:_endDate forKeyedSubscript:@"EndTime"];
  320. [dict setObject:_customerName forKeyedSubscript:@"CustomerName"];
  321. [dict setObject:_customerTelephone forKeyedSubscript:@"Telephone"];
  322. [dict setObject:[NSString stringWithFormat:@"%ld",(long)_pageNumber] forKey:@"PageNum"];
  323. [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"];
  324. self.mDownManager = [[ASIDownManager alloc] init];
  325. _mDownManager.delegate = self;
  326. _mDownManager.onRequestSuccess = @selector(onLoadFinish:);
  327. _mDownManager.onRequestFail = @selector(onLoadFail:);
  328. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  329. }
  330. -(void)searchReceiptData{
  331. [_filterController showPagerView:self.cNav];
  332. }
  333. /**
  334. 抽屉加载布局
  335. @return
  336. */
  337. - (NSArray *)packageDataList {
  338. NSMutableArray *dataArray = [NSMutableArray array];
  339. SideSlipModel *model = [[SideSlipModel alloc] init];
  340. model.containerCellClass = @"DispatchReceiptSearchCell";
  341. model.regionTitle = @"查询条件";
  342. [dataArray addObject:model];
  343. return [dataArray mutableCopy];
  344. }
  345. /**
  346. 取消进度条加载函数
  347. */
  348. - (void)cancel {
  349. [self stopLoading];
  350. }
  351. /**
  352. 撤销回执
  353. @param cell <#cell description#>
  354. */
  355. - (void)showReturnReceipt:(DispatchReceiptModel*) model{
  356. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  357. message:@"是否要撤销回执?" preferredStyle:UIAlertControllerStyleAlert];
  358. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  359. style:UIAlertActionStyleDefault
  360. handler:^(UIAlertAction *action){
  361. [self requestCancelDeliveryReceipt:model.receiptID];
  362. }];
  363. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
  364. style:UIAlertActionStyleDefault
  365. handler:^(UIAlertAction *action){
  366. }];
  367. UIColor *cancelColor = [UIColor blackColor];
  368. UIColor *sureColor = [UIColor redColor];
  369. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  370. [okAction setValue:sureColor forKey:@"titleTextColor"];
  371. [alert addAction:okAction];
  372. [alert addAction:cancelAction];
  373. [self presentViewController:alert animated:YES completion:nil];
  374. }
  375. /**
  376. 请求撤销回执
  377. @param receiptID <#receiptID description#>
  378. */
  379. -(void) requestCancelDeliveryReceipt:(NSString *) receiptID{
  380. [self startLoading];
  381. NSString *urlStr = ServerURL;
  382. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  383. [dict setObject:@"CancelInstallationDemandReceipt" 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:kkLicenseCode forKey:@"LicenseCode"];
  389. [dict setObject:receiptID forKeyedSubscript:@"ReceiptID"];
  390. self.mDownManager = [[ASIDownManager alloc] init];
  391. _mDownManager.delegate = self;
  392. _mDownManager.onRequestSuccess = @selector(onRequestCancelReceiptFinish:);
  393. _mDownManager.onRequestFail = @selector(onRequestCancelReceiptFail:);
  394. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  395. }
  396. /**
  397. 请求成功
  398. @param sender <#sender description#>
  399. */
  400. - (void)onRequestCancelReceiptFinish:(ASIDownManager *) sender{
  401. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  402. [self cancel];
  403. int iNewCount = 0;
  404. int iStatus = resultModel.status;
  405. NSString *message = resultModel.message;
  406. if (iStatus == 0) {
  407. [self showAlertViewText:@"撤销成功"];
  408. [self ReloadList:_tableView];
  409. }
  410. else if(iStatus == ActionResultStatusAuthError
  411. ||iStatus == ActionResultStatusNoLogin
  412. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  413. [self showReLoginDialog:message];
  414. return;
  415. }
  416. else{
  417. [self showAlertViewText:message];
  418. return;
  419. }
  420. }
  421. -(void)refreshData
  422. {
  423. [self ReloadList:_tableView];
  424. if([self.refreshDelegate respondsToSelector:@selector(refreshData)])
  425. {
  426. [self.refreshDelegate refreshData];
  427. }
  428. }
  429. /**
  430. 请求失败
  431. @param sender <#sender description#>
  432. */
  433. - (void)onRequestCancelReceiptFail:(ASIDownManager *) sender{
  434. [self cancel];
  435. [self showAlertViewText:@"请求失败"];
  436. }
  437. @end