ResultViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // ApexResultViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Jack on 2019/1/5.
  6. // Copyright © 2019 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ResultViewController+QuickLook.h"
  9. #import "ResultProtocol.h"
  10. #import "ResultPresenter.h"
  11. //#import "ApexResultContainerCell.h"
  12. //#import "ApexResultDocumentCell.h"
  13. //#import "ApexResultAirBookingCell.h"
  14. #import "JLRefreshHeader.h"
  15. #import "JLRefreshFooter.h"
  16. #import "RAProgressHUD.h"
  17. #import "RAUtils.h"
  18. #import "MyQLPreviewController.h"
  19. #import "CustomizeFieldViewController.h"
  20. //#import "ApexResultBookingCell.h"
  21. //#import "ApexResultAirAwbInfoCell.h"
  22. //#import "ApexResultBLInfoCell.h"
  23. #import "ResultACICell.h"
  24. #import "ResultACEM1Cell.h"
  25. #import "ResultCustomerCell.h"
  26. #import "ResultISFCell.h"
  27. #import "ResulteManifestCell.h"
  28. #import "ApexResultMenuItem.h"
  29. #import "const.h"
  30. @interface ResultViewController ()<ResultProtocol, JLRefreshDelegate>
  31. @property (nonatomic,weak) JLRefreshBasis *curRefresh;
  32. @property (nonatomic,weak) RAProgressHUD *curHUD;
  33. @property (nonatomic,strong) IBOutlet UITableView *resultTableView;
  34. @property (nonatomic,strong) ResultPresenter *presenter;
  35. @property (nonatomic,strong) MyQLPreviewController *quickLook;
  36. @property (nonatomic,strong) NSDictionary *params;
  37. @end
  38. @implementation ResultViewController
  39. + (instancetype)resultViewController:(NSDictionary *)params {
  40. ResultViewController *vc = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
  41. vc.params = params;
  42. return vc;
  43. }
  44. #pragma mark - Override
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. // Do any additional setup after loading the view.
  48. [self setupNavigationBar];
  49. [self setupPresenter];
  50. [self setupTableView];
  51. [self.presenter loadData];
  52. }
  53. - (void)viewWillAppear:(BOOL)animated {
  54. [super viewWillAppear:animated];
  55. if (self.presenter.dirty) {
  56. [self.presenter loadData];
  57. }
  58. }
  59. - (void)dealloc {
  60. NSLog(@"result vc dealloc");
  61. }
  62. #pragma mark - Setup
  63. - (void)setupPresenter {
  64. self.presenter = [[ResultPresenter alloc] initWithParameters:self.params];
  65. self.presenter.delegate = self;
  66. }
  67. - (void)setupTableView {
  68. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  69. self.tableView.tableFooterView = [UIView new];
  70. self.tableView.tableHeaderView = [UIView new];
  71. [self.tableView registerNib:[UINib nibWithNibName:@"ResultACICell" bundle:nil] forCellReuseIdentifier:ResultACICell.identifier];
  72. [self.tableView registerNib:[UINib nibWithNibName:@"ResulteManifestCell" bundle:nil] forCellReuseIdentifier:ResulteManifestCell.identifier];
  73. [self.tableView registerNib:[UINib nibWithNibName:@"ResultACEM1Cell" bundle:nil] forCellReuseIdentifier:ResultACEM1Cell.identifier];
  74. [self.tableView registerNib:[UINib nibWithNibName:@"ResultCustomerCell" bundle:nil] forCellReuseIdentifier:ResultCustomerCell.identifier];
  75. [self.tableView registerNib:[UINib nibWithNibName:@"ResultISFCell" bundle:nil] forCellReuseIdentifier:ResultISFCell.identifier];
  76. // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultAirBookingCell" bundle:nil] forCellReuseIdentifier:ApexResultAirBookingCell.identifier];
  77. // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultAirAwbInfoCell" bundle:nil] forCellReuseIdentifier:ApexResultAirAwbInfoCell.identifier];
  78. // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultBLInfoCell" bundle:nil] forCellReuseIdentifier:ApexResultBLInfoCell.identifier];
  79. // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultContainerCell" bundle:nil] forCellReuseIdentifier:ApexResultContainerCell.identifier];
  80. // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultDocumentCell" bundle:nil] forCellReuseIdentifier:ApexResultDocumentCell.identifier];
  81. JLRefreshHeader *header = [[JLRefreshHeader alloc] init];
  82. header.refreshDelegate = self;
  83. self.tableView.jl_header = header;
  84. JLRefreshFooter *footer = [[JLRefreshFooter alloc] init];
  85. footer.refreshDelegate = self;
  86. self.tableView.jl_footer = footer;
  87. }
  88. - (void)setupNavigationBar {
  89. UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_search"] style:UIBarButtonItemStylePlain target:self action:@selector(searchItemClick:)];
  90. UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(menuItemClick:)];
  91. if([self.params[@"withsearch"] boolValue]==true)
  92. {
  93. self.navigationItem.rightBarButtonItems = @[menuItem,searchItem];;
  94. }
  95. else
  96. {
  97. self.navigationItem.rightBarButtonItem = menuItem;
  98. }
  99. // UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  100. // backItem.title = @"";
  101. // self.navigationItem.backBarButtonItem = backItem;
  102. }
  103. #pragma mark - Getter
  104. - (UITableView *)tableView {
  105. return self.resultTableView;
  106. }
  107. - (MyQLPreviewController *)quickLook {
  108. if (!_quickLook)
  109. {
  110. _quickLook = [[MyQLPreviewController alloc] init];
  111. _quickLook.delegate = self;
  112. _quickLook.dataSource = self;
  113. UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)];
  114. _quickLook.navigationItem.rightBarButtonItem = previewMenuBtn;
  115. }
  116. else
  117. {
  118. [_quickLook reloadData];
  119. }
  120. return _quickLook;
  121. }
  122. #pragma mark - Presenter Delegate
  123. - (void)onStartLoading {
  124. self.curHUD = [RAProgressHUD showHUDOnView:self.view];
  125. }
  126. - (void)onStopLoading {
  127. [self.curHUD dismiss];
  128. }
  129. - (void)onNoMoreData {
  130. [(JLRefreshFooter *)self.tableView.jl_footer noMoreData];
  131. }
  132. - (void)onSuccess:(NSString *)title {
  133. [self.curRefresh endRefresh];
  134. [self.tableView reloadData];
  135. self.title = title;
  136. }
  137. - (void)onFailed:(NSString *)errMsg {
  138. [self.curRefresh endRefresh];
  139. // [RAUtils message_alert:errMsg title:@"Warning" controller:self];
  140. [RAUtils ra_showAlertTitle:@"Warning" message:errMsg withViewController:self];
  141. }
  142. - (void)onDownloadFile:(NSString *)path {
  143. if (path) {
  144. [self.navigationController pushViewController:self.quickLook animated:YES];
  145. }
  146. }
  147. #pragma mark - Refresh Delegate
  148. - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
  149. }
  150. - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
  151. self.curRefresh = refresh;
  152. if (refresh == self.tableView.jl_header) {
  153. [self.presenter refreshData];
  154. [(JLRefreshFooter *)self.tableView.jl_footer enableLoadMore];
  155. } else if (refresh == self.tableView.jl_footer) {
  156. [self.presenter loadMoreData];
  157. }
  158. }
  159. - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
  160. }
  161. #pragma mark - Navigation Item Click
  162. - (void)searchItemClick:(id)sender {
  163. SearchViewController *searchViewController = [[UIStoryboard storyboardWithName:@"Search" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchViewController"];
  164. searchViewController.subtype = self.params[@"sub_type"];
  165. // searchViewController.type = @"search";
  166. [self.navigationController pushViewController:searchViewController animated:YES];
  167. }
  168. - (void)menuItemClick:(id)sender {
  169. if (self.presenter.menuItems && self.presenter.menuItems.count > 0) {
  170. __weak typeof(self) weakSelf = self;
  171. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  172. for (ApexResultMenuItem *item in self.presenter.menuItems) {
  173. UIAlertAction *itemAction = [UIAlertAction actionWithTitle:item.title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  174. if ([item.action isEqualToString:@"save"]) {
  175. [weakSelf saveSearchParameters];
  176. } else if ([item.action isEqualToString:@"field_setting"]) {
  177. [weakSelf showFieldsSetting];
  178. }
  179. }];
  180. [alertVC addAction:itemAction];
  181. }
  182. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  183. }];
  184. [alertVC addAction:cancelAction];
  185. [self presentViewController:alertVC animated:YES completion:nil];
  186. } else {
  187. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"there is no field to response" preferredStyle:UIAlertControllerStyleAlert];
  188. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  189. }];
  190. [alertVC addAction:okAction];
  191. [self presentViewController:alertVC animated:YES completion:nil];
  192. }
  193. }
  194. #pragma mark - Action
  195. - (void)saveSearchParameters {
  196. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_create_tag", nil) message:NSLocalizedString(@"alert_msg_savehint", nil) preferredStyle:UIAlertControllerStyleAlert];
  197. __block UITextField *inputTextField;
  198. [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  199. inputTextField = textField;
  200. }];
  201. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  202. }];
  203. __weak typeof(self) weakSelf = self;
  204. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"save", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  205. UITextField * txt= inputTextField;
  206. NSString* name = txt.text;
  207. if(name.length==0)
  208. {
  209. [RAUtils message_alert:@"Name can not be empty." title:@"Save Search" controller:self];
  210. return;
  211. }
  212. [weakSelf.presenter saveSearchParameters:name];
  213. }];
  214. [alertVC addAction:cancelAction];
  215. [alertVC addAction:saveAction];
  216. [self presentViewController:alertVC animated:YES completion:nil];
  217. }
  218. - (void)showFieldsSetting {
  219. self.presenter.dirty = YES;
  220. // NSString *module_name = [self.params objectForKey:@"module_name"];
  221. CustomizeFieldViewController *ViewController = [[UIStoryboard storyboardWithName:@"Fields" bundle:nil]
  222. instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
  223. // ViewController.function_name = module_name;
  224. ViewController.type = @"result";
  225. ViewController.subtype = self.params[@"sub_type"];
  226. ViewController.behavior = BEHAVIOR_RESULT;
  227. ViewController.forNewResult = YES;
  228. ViewController.maxDisplayCount = ResultMaxDispalyAdditionCount;
  229. [self.navigationController pushViewController:ViewController animated:YES];
  230. }
  231. @end