InstallReceiptedVC.m 16 KB

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