| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- //
- // ApexResultViewController.m
- // Apex Mobile
- //
- // Created by Jack on 2019/1/5.
- // Copyright © 2019 United Software Applications, Inc. All rights reserved.
- //
- #import "ResultViewController+QuickLook.h"
- #import "ResultProtocol.h"
- #import "ResultPresenter.h"
- //#import "ApexResultContainerCell.h"
- //#import "ApexResultDocumentCell.h"
- //#import "ApexResultAirBookingCell.h"
- #import "JLRefreshHeader.h"
- #import "JLRefreshFooter.h"
- #import "RAProgressHUD.h"
- #import "RAUtils.h"
- #import "MyQLPreviewController.h"
- #import "CustomizeFieldViewController.h"
- //#import "ApexResultBookingCell.h"
- //#import "ApexResultAirAwbInfoCell.h"
- //#import "ApexResultBLInfoCell.h"
- #import "ResultACICell.h"
- #import "ResultACEM1Cell.h"
- #import "ResultCustomerCell.h"
- #import "ResultISFCell.h"
- #import "ResulteManifestCell.h"
- #import "ApexResultMenuItem.h"
- #import "const.h"
- @interface ResultViewController ()<ResultProtocol, JLRefreshDelegate>
- @property (nonatomic,weak) JLRefreshBasis *curRefresh;
- @property (nonatomic,weak) RAProgressHUD *curHUD;
- @property (nonatomic,strong) IBOutlet UITableView *resultTableView;
- @property (nonatomic,strong) ResultPresenter *presenter;
- @property (nonatomic,strong) MyQLPreviewController *quickLook;
- @property (nonatomic,strong) NSDictionary *params;
- @end
- @implementation ResultViewController
- + (instancetype)resultViewController:(NSDictionary *)params {
-
- ResultViewController *vc = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
- vc.params = params;
-
- return vc;
- }
- #pragma mark - Override
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self setupNavigationBar];
- [self setupPresenter];
- [self setupTableView];
-
- [self.presenter loadData];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- if (self.presenter.dirty) {
- [self.presenter loadData];
- }
- }
- - (void)dealloc {
- NSLog(@"result vc dealloc");
- }
- #pragma mark - Setup
- - (void)setupPresenter {
- self.presenter = [[ResultPresenter alloc] initWithParameters:self.params];
- self.presenter.delegate = self;
- }
- - (void)setupTableView {
-
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.tableHeaderView = [UIView new];
-
- [self.tableView registerNib:[UINib nibWithNibName:@"ResultACICell" bundle:nil] forCellReuseIdentifier:ResultACICell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"ResulteManifestCell" bundle:nil] forCellReuseIdentifier:ResulteManifestCell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"ResultACEM1Cell" bundle:nil] forCellReuseIdentifier:ResultACEM1Cell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"ResultCustomerCell" bundle:nil] forCellReuseIdentifier:ResultCustomerCell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"ResultISFCell" bundle:nil] forCellReuseIdentifier:ResultISFCell.identifier];
-
- // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultAirBookingCell" bundle:nil] forCellReuseIdentifier:ApexResultAirBookingCell.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultAirAwbInfoCell" bundle:nil] forCellReuseIdentifier:ApexResultAirAwbInfoCell.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultBLInfoCell" bundle:nil] forCellReuseIdentifier:ApexResultBLInfoCell.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultContainerCell" bundle:nil] forCellReuseIdentifier:ApexResultContainerCell.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ApexResultDocumentCell" bundle:nil] forCellReuseIdentifier:ApexResultDocumentCell.identifier];
-
- JLRefreshHeader *header = [[JLRefreshHeader alloc] init];
- header.refreshDelegate = self;
- self.tableView.jl_header = header;
-
- JLRefreshFooter *footer = [[JLRefreshFooter alloc] init];
- footer.refreshDelegate = self;
- self.tableView.jl_footer = footer;
- }
- - (void)setupNavigationBar {
- UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_search"] style:UIBarButtonItemStylePlain target:self action:@selector(searchItemClick:)];
-
- UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(menuItemClick:)];
-
-
- if([self.params[@"withsearch"] boolValue]==true)
- {
- self.navigationItem.rightBarButtonItems = @[menuItem,searchItem];;
- }
- else
- {
- self.navigationItem.rightBarButtonItem = menuItem;
- }
-
- // UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
- // backItem.title = @"";
- // self.navigationItem.backBarButtonItem = backItem;
- }
- #pragma mark - Getter
- - (UITableView *)tableView {
- return self.resultTableView;
- }
- - (MyQLPreviewController *)quickLook {
- if (!_quickLook)
- {
- _quickLook = [[MyQLPreviewController alloc] init];
- _quickLook.delegate = self;
- _quickLook.dataSource = self;
- UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)];
- _quickLook.navigationItem.rightBarButtonItem = previewMenuBtn;
- }
- else
- {
- [_quickLook reloadData];
- }
- return _quickLook;
- }
- #pragma mark - Presenter Delegate
- - (void)onStartLoading {
- self.curHUD = [RAProgressHUD showHUDOnView:self.view];
- }
- - (void)onStopLoading {
- [self.curHUD dismiss];
- }
- - (void)onNoMoreData {
- [(JLRefreshFooter *)self.tableView.jl_footer noMoreData];
- }
- - (void)onSuccess:(NSString *)title {
- [self.curRefresh endRefresh];
- [self.tableView reloadData];
-
- self.title = title;
- }
- - (void)onFailed:(NSString *)errMsg {
- [self.curRefresh endRefresh];
- // [RAUtils message_alert:errMsg title:@"Warning" controller:self];
- [RAUtils ra_showAlertTitle:@"Warning" message:errMsg withViewController:self];
- }
- - (void)onDownloadFile:(NSString *)path {
- if (path) {
- [self.navigationController pushViewController:self.quickLook animated:YES];
- }
- }
- #pragma mark - Refresh Delegate
- - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
-
- }
- - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
-
- self.curRefresh = refresh;
- if (refresh == self.tableView.jl_header) {
-
- [self.presenter refreshData];
- [(JLRefreshFooter *)self.tableView.jl_footer enableLoadMore];
-
- } else if (refresh == self.tableView.jl_footer) {
-
- [self.presenter loadMoreData];
- }
- }
- - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
-
- }
- #pragma mark - Navigation Item Click
- - (void)searchItemClick:(id)sender {
- SearchViewController *searchViewController = [[UIStoryboard storyboardWithName:@"Search" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchViewController"];
-
- searchViewController.subtype = self.params[@"sub_type"];
- // searchViewController.type = @"search";
- [self.navigationController pushViewController:searchViewController animated:YES];
-
- }
- - (void)menuItemClick:(id)sender {
-
- if (self.presenter.menuItems && self.presenter.menuItems.count > 0) {
-
- __weak typeof(self) weakSelf = self;
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- for (ApexResultMenuItem *item in self.presenter.menuItems) {
-
- UIAlertAction *itemAction = [UIAlertAction actionWithTitle:item.title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- if ([item.action isEqualToString:@"save"]) {
-
- [weakSelf saveSearchParameters];
- } else if ([item.action isEqualToString:@"field_setting"]) {
-
- [weakSelf showFieldsSetting];
- }
- }];
- [alertVC addAction:itemAction];
- }
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-
- }];
- [alertVC addAction:cancelAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
- } else {
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"there is no field to response" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [alertVC addAction:okAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
- }
- }
- #pragma mark - Action
- - (void)saveSearchParameters {
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_create_tag", nil) message:NSLocalizedString(@"alert_msg_savehint", nil) preferredStyle:UIAlertControllerStyleAlert];
- __block UITextField *inputTextField;
- [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- inputTextField = textField;
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- __weak typeof(self) weakSelf = self;
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"save", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- UITextField * txt= inputTextField;
- NSString* name = txt.text;
- if(name.length==0)
- {
- [RAUtils message_alert:@"Name can not be empty." title:@"Save Search" controller:self];
- return;
- }
-
- [weakSelf.presenter saveSearchParameters:name];
-
- }];
-
- [alertVC addAction:cancelAction];
- [alertVC addAction:saveAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
- }
- - (void)showFieldsSetting {
-
- self.presenter.dirty = YES;
-
- // NSString *module_name = [self.params objectForKey:@"module_name"];
- CustomizeFieldViewController *ViewController = [[UIStoryboard storyboardWithName:@"Fields" bundle:nil]
- instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
- // ViewController.function_name = module_name;
-
- ViewController.type = @"result";
- ViewController.subtype = self.params[@"sub_type"];
- ViewController.behavior = BEHAVIOR_RESULT;
- ViewController.forNewResult = YES;
- ViewController.maxDisplayCount = ResultMaxDispalyAdditionCount;
-
- [self.navigationController pushViewController:ViewController animated:YES];
-
- }
- @end
|