| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- //
- // ViewController.m
- // RedAnt Mobile
- //
- // Created by Ray on 06/09/2017.
- // Copyright © 2017 Ray. All rights reserved.
- //
- #import "RAModeListViewController.h"
- #import "RAModeCell.h"
- //#import "RAModel.h"
- #import "RAPredefQueryViewController.h"
- #import "RAQueryViewController.h"
- #import "ResultViewController.h"
- #import "SearchViewController.h"
- #import "RANetwork.h"
- //#import "BasicModeViewController.h"
- //#import "ModelModeViewController.h"
- //#import "PopModeViewController.h"
- //#import "RootViewController.h"
- #import "SearchSettingViewController.h"
- #import "RAResultViewController.h"
- @interface RAModeListViewController () <UITableViewDelegate,UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *modeTableView;
- //@property (nonatomic,strong) NSMutableArray<RAModel *> *modeArray;
- @end
- @implementation RAModeListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- [self removeFirstResponderTap]; // 截断了Cell响应
- self.automaticallyAdjustsScrollViewInsets = NO;
- self.modeTableView.tableHeaderView = [UIView new];
- self.modeTableView.tableFooterView = [UIView new];
-
- if(self.isroot)
- {
- [self.navigationItem setHidesBackButton:true];
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
- }
- else
- {
- [self.navigationItem setHidesBackButton:false];
- }
-
-
- // if(self.onRBName)
- // {
- // NSString* rbname= self.onRBName();
- // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:rbname style:UIBarButtonItemStylePlain target:self action:@selector(RBItemClick:)];
- //
- // }
- // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
-
- }
- //- (void)RBItemClick:(UIBarButtonItem *)sender {
- // if(self.onRBClick)
- // {
- // __weak typeof(self) weakself = self;
- // self.onRBClick(weakself);
- // }
- //}
- - (void)logoutItemClick:(UIBarButtonItem *)sender {
-
- __weak typeof(self) weakself = self;
-
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Logout" completion:^{
- [RANetwork logout:^(NSMutableDictionary *result) {
- NSMutableDictionary* logoutDic = result;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
- int resulti=[[logoutDic valueForKey:@"result"] intValue];
- if (resulti == RESULT_TRUE) {
-
- [weakself.navigationController popViewControllerAnimated:false];
- // weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- // [appDelegate logout];
- } else {
- __strong typeof(weakself) strongself = weakself;
- NSString *msg = [logoutDic objectForKey:@"err_msg"];
- [RAUtils message_alert:msg title:@"Warning" controller:strongself];
- }
- }];
- }];
-
- }];
- //
- //
- // UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
- // __weak typeof(self) weakself = self;
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // NSDictionary *logoutDic = [RANetwork logout];
- // int result = [[logoutDic objectForKey:@"result"] intValue];
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [alert dismissWithClickedButtonIndex:0 animated:YES];
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // if (result == RESULT_TRUE) {
- //
- // [weakself.navigationController popViewControllerAnimated:false];
- //// weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- // // [appDelegate logout];
- // } else {
- // __strong typeof(weakself) strongself = weakself;
- // NSString *msg = [logoutDic objectForKey:@"err_msg"];
- // [RAUtils message_alert:msg title:@"Warning" controller:strongself];
- // }
- // });
- //
- //
- // });
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //#pragma mark - Lazy Load
- //
- //- (NSMutableArray<RAModel *> *)modeArray {
- // if (!_modeArray) {
- // _modeArray = [NSMutableArray array];
- // }
- // return _modeArray;
- //}
- //#pragma mark - Public
- //
- //- (void)setModeList:(NSArray *)modeList {
- //
- // for (int i = 0; i < modeList.count; i++) {
- //
- // NSDictionary *mode_dic = [modeList objectAtIndex:i];
- // RAModel *model = [[RAModel alloc] init];
- // [model setValuesForKeysWithDictionary:mode_dic];
- // [self.modeArray addObject:model];
- // }
- //}
- #pragma mark - TableView Delegate & DataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.modelist.count;
- // return self.modeArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- RAModeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mode_cell" forIndexPath:indexPath];
- // RAModel *model = self.modelist[indexPath.row];//[self.modeArray objectAtIndex:indexPath.row];
-
- [cell setModeinfo:[self.modelist[indexPath.row] mutableCopy]];
- // [cell setModel:model];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 40.f;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- RAModeCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- // RAModel *model = cell.model;
- NSMutableDictionary* modeinfo= cell.modeinfo;
-
- if ([modeinfo[@"type"] isEqualToString:@"predef_query"]) {
- [self processPredefQueryModel:modeinfo];
-
- } else if ([modeinfo[@"type"] isEqualToString:@"query"]) {
- [self processQueryModel:modeinfo];
-
- } else if ([modeinfo[@"type"] isEqualToString:@"local_func"]) {
- [self processLocalFunModel:modeinfo];
-
- } else if ([modeinfo[@"type"] isEqualToString:@"submode"]) {
- [self processSubmodeModel:modeinfo];
- }
-
- }
- #pragma mark - Private
- - (void) processPredefQueryModel:(NSMutableDictionary *)modeinfo {
- // RAPredefQueryViewController *preQueryVC = [[UIStoryboard storyboardWithName:@"RAPredefQuery" bundle:nil] instantiateInitialViewController];
- // preQueryVC.query_id = [model.query_id integerValue];
- // preQueryVC.title = model.name;
-
- // ResultViewController *preQueryVC = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
- // [preQueryVC setQueryParams: @{
- // @"query_id" : modeinfo[@"query_id"],
- // @"title":modeinfo[@"name"]
- // }];
-
- RAResultViewController *preQueryVC = [RAResultViewController buildInstanceWithParams:@{
- @"query_id" : modeinfo[@"query_id"],
- @"title":modeinfo[@"name"]
- }.mutableCopy];
-
- [self.navigationController pushViewController:preQueryVC animated:YES];
- }
- - (void) processQueryModel:(NSMutableDictionary *)modeinfo {
-
-
-
-
- SearchViewController *queryVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchViewController"];
-
- queryVC.params = [NSMutableDictionary new];
- queryVC.params[@"query_id"]=modeinfo[@"query_id"];
- queryVC.params[@"title"]=modeinfo[@"name"];
- queryVC.request_url = [RANetwork get_url:URL_QUERY_UI];
- queryVC.url_type = URL_REMOTE;
- // BViewController *vc =[BViewController new];//[ self.storyboard instantiateViewControllerWithIdentifier:@"commonVC"];
- //
- //
- //
- // [self presentViewController:vc animated:true completion:nil];
- //
- //
- // RAQueryViewController *queryVC = [[UIStoryboard storyboardWithName:@"RAQuery" bundle:nil] instantiateInitialViewController];
- // queryVC.url = model.url;
- // queryVC.title = model.name;
- [self.navigationController pushViewController:queryVC animated:YES];
- }
- - (void) processLocalFunModel:(NSMutableDictionary *)modeinfo {
-
-
- [RAUtils message_alert:@"Local function" title:@"Message" controller:self];
- return ;
- //
- // if ([modeinfo[@"module"] isEqualToString:@"tools_change_pwd"]) {
- // NSLog(@"change password");
- // }
- // else if ([modeinfo[@"module"] isEqualToString:@"raimage_mode"]) {
- //
- //
- //
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // appDelegate.modeList = modeinfo[@"ext_data"];
- // RootViewController *ramodelist = [[UIStoryboard storyboardWithName:@"RAImage" bundle:nil] instantiateViewControllerWithIdentifier:@"RootViewController"];
- // [self.navigationController pushViewController:ramodelist animated:false];
- //
- // }
-
-
-
-
- }
- - (void)pushRAImageController:(NSMutableDictionary *)modeinfo {
- return;
-
- //
- // if (!modeinfo) {
- // return;
- // }
- //// NSIndexPath *indexPath = [self.modeTable indexPathForCell:cell];
- // NSDictionary *mode = modeinfo;//[self.modeList objectAtIndex:indexPath.row];
- // BasicModeViewController *modeVC = nil;
- // if ([mode[@"name"] isEqualToString:@"Model"]) {
- // ModelModeViewController *vc = (ModelModeViewController *)[self viewControllerInStoryboard:@"Mode" withId:@"ModelModeViewController"];
- // vc.manufacturerList = [mode objectForKey:@"manifacturer"];
- // modeVC = vc;
- // }else if ([mode[@"name"] isEqualToString:@"POP"]||[mode[@"name"] isEqualToString:@"Receiving"]||[mode[@"name"] isEqualToString:@"Returns"]) {
- // PopModeViewController *vc = [[UIStoryboard storyboardWithName:@"Mode" bundle:nil] instantiateViewControllerWithIdentifier:@"PopModeViewController"];
- // if (![mode[@"name"] isEqualToString:@"Receiving"]) {
- // vc.inputKeyboardType = UIKeyboardTypeNumberPad;
- // } else {
- // vc.inputKeyboardType = UIKeyboardTypeDefault;
- // }
- // modeVC = vc;
- // }
- //
- // if (modeVC) {
- // modeVC.barcodeTitle = mode[@"code_name"];
- // modeVC.name = mode[@"name"];
- // [self.navigationController pushViewController:modeVC animated:YES];
- // }
-
- }
- - (void) processSubmodeModel:(NSMutableDictionary *)modeinfo {
- RAModeListViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RARootViewController"];
- vc.title = modeinfo[@"name"];
- vc.modelist =modeinfo[@"mode_list"];
-
- //
- // if(modeinfo[@"menu"] !=nil)
- // {
- //
- // vc.onRBClick = ^(RAModeListViewController* bself){
- //
- // // UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
- // // // __weak typeof(self) weakself = self;
- // // dispatch_async(dispatch_get_main_queue(), ^{
- // //
- // // NSDictionary *logoutDic = [RANetwork logout];
- // // int result = [[logoutDic objectForKey:@"result"] intValue];
- // // dispatch_async(dispatch_get_main_queue(), ^{
- // // [alert dismissWithClickedButtonIndex:0 animated:YES];
- // // // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // // if (result == RESULT_TRUE) {
- // //
- // // [bself.navigationController popViewControllerAnimated:false];
- // // // weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- // // // [appDelegate logout];
- // // } else {
- // // __strong typeof(bself) strongself = bself;
- // // NSString *msg = [logoutDic objectForKey:@"err_msg"];
- // // [RAUtils message_alert:msg title:@"Warning" controller:strongself];
- // // }
- // // });
- // //
- // //
- // // });
- // // ;
- // };
- // vc.onRBName = ^NSString *{
- // return modeinfo[@"menu"];
- // };
- // }
-
-
-
- // [vc setModeList:];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (IBAction)onSearchSettingClick:(id)sender {
-
- UIView* v=(UIView*)sender;
- RAModeCell *cell = (RAModeCell*)v.superview.superview;
- // NSIndexPath* indexPath=[self.modeTableView indexPathForCell:(UITableViewCell*)v.superview.superview];
- NSMutableDictionary* modeinfo= cell.modeinfo;
-
- SearchSettingViewController *queryVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchSettingViewController"];
-
- queryVC.params = [NSMutableDictionary new];
- queryVC.params[@"query_id"]=modeinfo[@"query_id"];
- queryVC.params[@"title"]=[NSString stringWithFormat:@"%@ setting",modeinfo[@"name"]];
- queryVC.request_url = [RANetwork get_url:URL_QUERY_SETTIING];
- queryVC.url_type = URL_REMOTE;
-
- [self.navigationController pushViewController:queryVC animated:YES];
- }
- @end
|