RAModeListViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // ViewController.m
  3. // RedAnt Mobile
  4. //
  5. // Created by Ray on 06/09/2017.
  6. // Copyright © 2017 Ray. All rights reserved.
  7. //
  8. #import "RAModeListViewController.h"
  9. #import "RAModeCell.h"
  10. //#import "RAModel.h"
  11. #import "RAPredefQueryViewController.h"
  12. #import "RAQueryViewController.h"
  13. #import "ResultViewController.h"
  14. #import "SearchViewController.h"
  15. #import "RANetwork.h"
  16. //#import "BasicModeViewController.h"
  17. //#import "ModelModeViewController.h"
  18. //#import "PopModeViewController.h"
  19. //#import "RootViewController.h"
  20. #import "SearchSettingViewController.h"
  21. #import "RAResultViewController.h"
  22. @interface RAModeListViewController () <UITableViewDelegate,UITableViewDataSource>
  23. @property (weak, nonatomic) IBOutlet UITableView *modeTableView;
  24. //@property (nonatomic,strong) NSMutableArray<RAModel *> *modeArray;
  25. @end
  26. @implementation RAModeListViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view, typically from a nib.
  30. [self removeFirstResponderTap]; // 截断了Cell响应
  31. self.automaticallyAdjustsScrollViewInsets = NO;
  32. self.modeTableView.tableHeaderView = [UIView new];
  33. self.modeTableView.tableFooterView = [UIView new];
  34. if(self.isroot)
  35. {
  36. [self.navigationItem setHidesBackButton:true];
  37. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
  38. }
  39. else
  40. {
  41. [self.navigationItem setHidesBackButton:false];
  42. }
  43. // if(self.onRBName)
  44. // {
  45. // NSString* rbname= self.onRBName();
  46. // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:rbname style:UIBarButtonItemStylePlain target:self action:@selector(RBItemClick:)];
  47. //
  48. // }
  49. // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
  50. }
  51. //- (void)RBItemClick:(UIBarButtonItem *)sender {
  52. // if(self.onRBClick)
  53. // {
  54. // __weak typeof(self) weakself = self;
  55. // self.onRBClick(weakself);
  56. // }
  57. //}
  58. - (void)logoutItemClick:(UIBarButtonItem *)sender {
  59. __weak typeof(self) weakself = self;
  60. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Logout" completion:^{
  61. [RANetwork logout:^(NSMutableDictionary *result) {
  62. NSMutableDictionary* logoutDic = result;
  63. [waitalert dismissViewControllerAnimated:YES completion:^{
  64. int resulti=[[logoutDic valueForKey:@"result"] intValue];
  65. if (resulti == RESULT_TRUE) {
  66. [weakself.navigationController popViewControllerAnimated:false];
  67. // weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
  68. // [appDelegate logout];
  69. } else {
  70. __strong typeof(weakself) strongself = weakself;
  71. NSString *msg = [logoutDic objectForKey:@"err_msg"];
  72. [RAUtils message_alert:msg title:@"Warning" controller:strongself];
  73. }
  74. }];
  75. }];
  76. }];
  77. //
  78. //
  79. // UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
  80. // __weak typeof(self) weakself = self;
  81. // dispatch_async(dispatch_get_main_queue(), ^{
  82. //
  83. // NSDictionary *logoutDic = [RANetwork logout];
  84. // int result = [[logoutDic objectForKey:@"result"] intValue];
  85. // dispatch_async(dispatch_get_main_queue(), ^{
  86. // [alert dismissWithClickedButtonIndex:0 animated:YES];
  87. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  88. // if (result == RESULT_TRUE) {
  89. //
  90. // [weakself.navigationController popViewControllerAnimated:false];
  91. //// weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
  92. // // [appDelegate logout];
  93. // } else {
  94. // __strong typeof(weakself) strongself = weakself;
  95. // NSString *msg = [logoutDic objectForKey:@"err_msg"];
  96. // [RAUtils message_alert:msg title:@"Warning" controller:strongself];
  97. // }
  98. // });
  99. //
  100. //
  101. // });
  102. }
  103. - (void)didReceiveMemoryWarning {
  104. [super didReceiveMemoryWarning];
  105. // Dispose of any resources that can be recreated.
  106. }
  107. //#pragma mark - Lazy Load
  108. //
  109. //- (NSMutableArray<RAModel *> *)modeArray {
  110. // if (!_modeArray) {
  111. // _modeArray = [NSMutableArray array];
  112. // }
  113. // return _modeArray;
  114. //}
  115. //#pragma mark - Public
  116. //
  117. //- (void)setModeList:(NSArray *)modeList {
  118. //
  119. // for (int i = 0; i < modeList.count; i++) {
  120. //
  121. // NSDictionary *mode_dic = [modeList objectAtIndex:i];
  122. // RAModel *model = [[RAModel alloc] init];
  123. // [model setValuesForKeysWithDictionary:mode_dic];
  124. // [self.modeArray addObject:model];
  125. // }
  126. //}
  127. #pragma mark - TableView Delegate & DataSource
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  129. return self.modelist.count;
  130. // return self.modeArray.count;
  131. }
  132. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  133. RAModeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mode_cell" forIndexPath:indexPath];
  134. // RAModel *model = self.modelist[indexPath.row];//[self.modeArray objectAtIndex:indexPath.row];
  135. [cell setModeinfo:[self.modelist[indexPath.row] mutableCopy]];
  136. // [cell setModel:model];
  137. return cell;
  138. }
  139. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  140. return 40.f;
  141. }
  142. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  143. RAModeCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  144. // RAModel *model = cell.model;
  145. NSMutableDictionary* modeinfo= cell.modeinfo;
  146. if ([modeinfo[@"type"] isEqualToString:@"predef_query"]) {
  147. [self processPredefQueryModel:modeinfo];
  148. } else if ([modeinfo[@"type"] isEqualToString:@"query"]) {
  149. [self processQueryModel:modeinfo];
  150. } else if ([modeinfo[@"type"] isEqualToString:@"local_func"]) {
  151. [self processLocalFunModel:modeinfo];
  152. } else if ([modeinfo[@"type"] isEqualToString:@"submode"]) {
  153. [self processSubmodeModel:modeinfo];
  154. }
  155. }
  156. #pragma mark - Private
  157. - (void) processPredefQueryModel:(NSMutableDictionary *)modeinfo {
  158. // RAPredefQueryViewController *preQueryVC = [[UIStoryboard storyboardWithName:@"RAPredefQuery" bundle:nil] instantiateInitialViewController];
  159. // preQueryVC.query_id = [model.query_id integerValue];
  160. // preQueryVC.title = model.name;
  161. // ResultViewController *preQueryVC = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
  162. // [preQueryVC setQueryParams: @{
  163. // @"query_id" : modeinfo[@"query_id"],
  164. // @"title":modeinfo[@"name"]
  165. // }];
  166. RAResultViewController *preQueryVC = [RAResultViewController buildInstanceWithParams:@{
  167. @"query_id" : modeinfo[@"query_id"],
  168. @"title":modeinfo[@"name"]
  169. }.mutableCopy];
  170. [self.navigationController pushViewController:preQueryVC animated:YES];
  171. }
  172. - (void) processQueryModel:(NSMutableDictionary *)modeinfo {
  173. SearchViewController *queryVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchViewController"];
  174. queryVC.params = [NSMutableDictionary new];
  175. queryVC.params[@"query_id"]=modeinfo[@"query_id"];
  176. queryVC.params[@"title"]=modeinfo[@"name"];
  177. queryVC.request_url = [RANetwork get_url:URL_QUERY_UI];
  178. queryVC.url_type = URL_REMOTE;
  179. // BViewController *vc =[BViewController new];//[ self.storyboard instantiateViewControllerWithIdentifier:@"commonVC"];
  180. //
  181. //
  182. //
  183. // [self presentViewController:vc animated:true completion:nil];
  184. //
  185. //
  186. // RAQueryViewController *queryVC = [[UIStoryboard storyboardWithName:@"RAQuery" bundle:nil] instantiateInitialViewController];
  187. // queryVC.url = model.url;
  188. // queryVC.title = model.name;
  189. [self.navigationController pushViewController:queryVC animated:YES];
  190. }
  191. - (void) processLocalFunModel:(NSMutableDictionary *)modeinfo {
  192. [RAUtils message_alert:@"Local function" title:@"Message" controller:self];
  193. return ;
  194. //
  195. // if ([modeinfo[@"module"] isEqualToString:@"tools_change_pwd"]) {
  196. // NSLog(@"change password");
  197. // }
  198. // else if ([modeinfo[@"module"] isEqualToString:@"raimage_mode"]) {
  199. //
  200. //
  201. //
  202. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  203. // appDelegate.modeList = modeinfo[@"ext_data"];
  204. // RootViewController *ramodelist = [[UIStoryboard storyboardWithName:@"RAImage" bundle:nil] instantiateViewControllerWithIdentifier:@"RootViewController"];
  205. // [self.navigationController pushViewController:ramodelist animated:false];
  206. //
  207. // }
  208. }
  209. - (void)pushRAImageController:(NSMutableDictionary *)modeinfo {
  210. return;
  211. //
  212. // if (!modeinfo) {
  213. // return;
  214. // }
  215. //// NSIndexPath *indexPath = [self.modeTable indexPathForCell:cell];
  216. // NSDictionary *mode = modeinfo;//[self.modeList objectAtIndex:indexPath.row];
  217. // BasicModeViewController *modeVC = nil;
  218. // if ([mode[@"name"] isEqualToString:@"Model"]) {
  219. // ModelModeViewController *vc = (ModelModeViewController *)[self viewControllerInStoryboard:@"Mode" withId:@"ModelModeViewController"];
  220. // vc.manufacturerList = [mode objectForKey:@"manifacturer"];
  221. // modeVC = vc;
  222. // }else if ([mode[@"name"] isEqualToString:@"POP"]||[mode[@"name"] isEqualToString:@"Receiving"]||[mode[@"name"] isEqualToString:@"Returns"]) {
  223. // PopModeViewController *vc = [[UIStoryboard storyboardWithName:@"Mode" bundle:nil] instantiateViewControllerWithIdentifier:@"PopModeViewController"];
  224. // if (![mode[@"name"] isEqualToString:@"Receiving"]) {
  225. // vc.inputKeyboardType = UIKeyboardTypeNumberPad;
  226. // } else {
  227. // vc.inputKeyboardType = UIKeyboardTypeDefault;
  228. // }
  229. // modeVC = vc;
  230. // }
  231. //
  232. // if (modeVC) {
  233. // modeVC.barcodeTitle = mode[@"code_name"];
  234. // modeVC.name = mode[@"name"];
  235. // [self.navigationController pushViewController:modeVC animated:YES];
  236. // }
  237. }
  238. - (void) processSubmodeModel:(NSMutableDictionary *)modeinfo {
  239. RAModeListViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RARootViewController"];
  240. vc.title = modeinfo[@"name"];
  241. vc.modelist =modeinfo[@"mode_list"];
  242. //
  243. // if(modeinfo[@"menu"] !=nil)
  244. // {
  245. //
  246. // vc.onRBClick = ^(RAModeListViewController* bself){
  247. //
  248. // // UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
  249. // // // __weak typeof(self) weakself = self;
  250. // // dispatch_async(dispatch_get_main_queue(), ^{
  251. // //
  252. // // NSDictionary *logoutDic = [RANetwork logout];
  253. // // int result = [[logoutDic objectForKey:@"result"] intValue];
  254. // // dispatch_async(dispatch_get_main_queue(), ^{
  255. // // [alert dismissWithClickedButtonIndex:0 animated:YES];
  256. // // // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  257. // // if (result == RESULT_TRUE) {
  258. // //
  259. // // [bself.navigationController popViewControllerAnimated:false];
  260. // // // weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
  261. // // // [appDelegate logout];
  262. // // } else {
  263. // // __strong typeof(bself) strongself = bself;
  264. // // NSString *msg = [logoutDic objectForKey:@"err_msg"];
  265. // // [RAUtils message_alert:msg title:@"Warning" controller:strongself];
  266. // // }
  267. // // });
  268. // //
  269. // //
  270. // // });
  271. // // ;
  272. // };
  273. // vc.onRBName = ^NSString *{
  274. // return modeinfo[@"menu"];
  275. // };
  276. // }
  277. // [vc setModeList:];
  278. [self.navigationController pushViewController:vc animated:YES];
  279. }
  280. - (IBAction)onSearchSettingClick:(id)sender {
  281. UIView* v=(UIView*)sender;
  282. RAModeCell *cell = (RAModeCell*)v.superview.superview;
  283. // NSIndexPath* indexPath=[self.modeTableView indexPathForCell:(UITableViewCell*)v.superview.superview];
  284. NSMutableDictionary* modeinfo= cell.modeinfo;
  285. SearchSettingViewController *queryVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchSettingViewController"];
  286. queryVC.params = [NSMutableDictionary new];
  287. queryVC.params[@"query_id"]=modeinfo[@"query_id"];
  288. queryVC.params[@"title"]=[NSString stringWithFormat:@"%@ setting",modeinfo[@"name"]];
  289. queryVC.request_url = [RANetwork get_url:URL_QUERY_SETTIING];
  290. queryVC.url_type = URL_REMOTE;
  291. [self.navigationController pushViewController:queryVC animated:YES];
  292. }
  293. @end