|
|
@@ -0,0 +1,477 @@
|
|
|
+//
|
|
|
+// RAResultViewController.m
|
|
|
+// RedAnt Mobile
|
|
|
+//
|
|
|
+// Created by Jack on 2018/3/20.
|
|
|
+// Copyright © 2018年 Ray. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "RAResultViewController.h"
|
|
|
+#import "RANetwork.h"
|
|
|
+#import "RAUtils.h"
|
|
|
+#import "KVViewController.h"
|
|
|
+#import "OrderDetailViewController.h"
|
|
|
+#import "config.h"
|
|
|
+
|
|
|
+@interface RAResultViewController ()
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation RAResultViewController
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+ // Do any additional setup after loading the view.
|
|
|
+}
|
|
|
+
|
|
|
+- (void)didReceiveMemoryWarning {
|
|
|
+ [super didReceiveMemoryWarning];
|
|
|
+ // Dispose of any resources that can be recreated.
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Override
|
|
|
+
|
|
|
+/**
|
|
|
+ * 0: init load
|
|
|
+ * 1: refresh
|
|
|
+ * 2: load more
|
|
|
+ */
|
|
|
+- (void)loadContentWithOption:(int)option Complete:(void (^)(int result,int count))finish {
|
|
|
+
|
|
|
+ if (self.params) {
|
|
|
+
|
|
|
+ NSMutableDictionary *dic = self.params.mutableCopy;
|
|
|
+ switch (option) {
|
|
|
+ case 0:
|
|
|
+ case 1: {
|
|
|
+ self.offset = 0;
|
|
|
+ self.content_layout =nil;
|
|
|
+ self.content_action = nil;
|
|
|
+ self.content_menu = nil;
|
|
|
+ self.content_data = nil;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: {
|
|
|
+ self.offset = [self resultItemCount];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.loadingIndicator.hidden) {
|
|
|
+ self.loadingIndicator.hidden = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (![self.loadingIndicator isAnimating]) {
|
|
|
+ [self.loadingIndicator startAnimating];
|
|
|
+ }
|
|
|
+
|
|
|
+// dic[@"criteria"] = self.params;
|
|
|
+
|
|
|
+ [dic setObject:@(self.offset) forKey:@"offset"];
|
|
|
+ [dic setObject:@(delta) forKey:@"limit"];
|
|
|
+// dic[@"criteria"] = [NSArray arrayWithObjects:@"aaa",@"bbb", nil];
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+ NSDictionary *contentDic = [RANetwork query:dic];
|
|
|
+ NSInteger result = [[contentDic objectForKey:@"result"] integerValue];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if (weakSelf) {
|
|
|
+ __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
+
|
|
|
+ [strongSelf.loadingIndicator stopAnimating];
|
|
|
+
|
|
|
+ if (result == RESULT_TRUE) {
|
|
|
+ strongSelf.content_layout = [contentDic objectForKey:@"layout"];
|
|
|
+ strongSelf.content_action = [contentDic objectForKey:@"row_action"];
|
|
|
+ strongSelf.content_menu = [[contentDic objectForKey:@"menu"] mutableCopy];
|
|
|
+ [strongSelf setupNavigationBar];
|
|
|
+
|
|
|
+// UILabel * headerview=(UILabel *)self.tableview.tableHeaderView;
|
|
|
+// headerview.text = contentDic[@"table_title"];
|
|
|
+// [self resize_tableHeader];
|
|
|
+
|
|
|
+ NSString *title = contentDic[@"table_title"];
|
|
|
+ self.titleLabel.text = title;
|
|
|
+
|
|
|
+ if(strongSelf.content_data==nil)
|
|
|
+ strongSelf.content_data = [NSMutableDictionary new];
|
|
|
+ NSMutableDictionary* newdata = [[contentDic objectForKey:@"data"] mutableCopy];
|
|
|
+ for(int dc = 0;dc<[newdata[@"count"] intValue];dc++)
|
|
|
+ {
|
|
|
+ NSMutableDictionary * newdata_item = newdata[[NSString stringWithFormat:@"item_%d",dc]];
|
|
|
+
|
|
|
+ strongSelf.content_data[[NSString stringWithFormat:@"item_%d",[strongSelf.content_data[@"count"] intValue] ]] = newdata_item;
|
|
|
+ strongSelf.content_data[@"count"] = @([strongSelf.content_data[@"count"] intValue]+1);
|
|
|
+ }
|
|
|
+
|
|
|
+// strongSelf.content_data = [contentDic objectForKey:@"data"];
|
|
|
+ [strongSelf updateTableFrame];
|
|
|
+ [strongSelf.tableview reloadData];
|
|
|
+ } else {
|
|
|
+ [RAUtils message_alert:[contentDic objectForKey:@"err_msg"] title:@"Warning" controller:strongSelf];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (finish) {
|
|
|
+ finish((int)result,(int)[self resultItemCount]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)presses3DTouchForIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ [self handleRowAction:indexPath];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)cellDoubleTapAction:(UIGestureRecognizer*)gestureRecognizer {
|
|
|
+ NSLog(@"cell double tap");
|
|
|
+ UITableViewCell* cell = (UITableViewCell*)[gestureRecognizer view];
|
|
|
+ NSIndexPath* indexPath=[self.tableview indexPathForCell:cell];
|
|
|
+ //strongSelf.content_action
|
|
|
+
|
|
|
+ [self handleRowAction:indexPath];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)MenuClick:(UIBarButtonItem *)sender {
|
|
|
+
|
|
|
+ UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
+ //block代码块取代了delegate
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ for(int i=0;i<self.content_menu.count;i++)
|
|
|
+ {
|
|
|
+ NSMutableDictionary* json = self.content_menu[i];
|
|
|
+ NSString* title =json[@"title"];
|
|
|
+ NSString* actiontype = json[@"action"];
|
|
|
+ NSString* url = json[@"url"];
|
|
|
+ // NSMutableDictionary* add_params = json[@"params"];
|
|
|
+ UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+ // DebugLog(@"Cancel");
|
|
|
+ if([actiontype isEqualToString:@"download"])
|
|
|
+ {
|
|
|
+ [weakSelf Export:url];
|
|
|
+ }
|
|
|
+ else if([actiontype isEqualToString:@"save"])
|
|
|
+ {
|
|
|
+ [weakSelf save];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ [alertControl addAction:actioni];
|
|
|
+ }
|
|
|
+
|
|
|
+ UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ // DebugLog(@"Cancel");
|
|
|
+
|
|
|
+ }];
|
|
|
+ [alertControl addAction:actionCancel];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [self presentViewController:alertControl animated:NO completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Action
|
|
|
+
|
|
|
+- (void)handleRowAction:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ if (indexPath == nil) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(self.content_action!=nil)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(self.content_action.count==1)
|
|
|
+ {
|
|
|
+ NSDictionary* action =self.content_action.firstObject;
|
|
|
+ NSString * module = action[@"module"];
|
|
|
+ if([module isEqualToString:@"quick_look"])
|
|
|
+ {
|
|
|
+
|
|
|
+ // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
|
|
|
+ NSMutableDictionary *params = action[@"params"];
|
|
|
+ NSString* URL =action[@"url"];
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+
|
|
|
+
|
|
|
+ NSString *path = [RANetwork download_file:params url:URL];
|
|
|
+ weakSelf.documentPath = path;
|
|
|
+
|
|
|
+ if (path) {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if([module isEqualToString:@"kv_detail"])
|
|
|
+ {
|
|
|
+ NSMutableDictionary *params = [NSMutableDictionary new];
|
|
|
+ params[@"query_id"] = self.params[@"query_id"];
|
|
|
+
|
|
|
+ NSMutableDictionary *criteria =[NSMutableDictionary new];
|
|
|
+ for(NSString* key in [action[@"params"] allKeys] )
|
|
|
+ {
|
|
|
+ NSArray* item =self.content_data[[NSString stringWithFormat:@"item_%ld",indexPath.row]];
|
|
|
+ int idx =[action[@"params"][key] intValue];
|
|
|
+ criteria[key]=item[ idx];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ params[@"criteria"]=[RAConvertor dict2string:criteria] ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
|
|
|
+
|
|
|
+
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSDictionary* json =[RANetwork kv_detail:params];
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
+
|
|
|
+
|
|
|
+ if([[json valueForKey:@"result"] intValue]==2)
|
|
|
+ {
|
|
|
+ KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
|
|
|
+ vc.content = [json mutableCopy];
|
|
|
+ [weakself.navigationController pushViewController:vc animated:NO];
|
|
|
+
|
|
|
+ // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
|
|
|
+ //
|
|
|
+ // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // [weakself download_success];
|
|
|
+ // [weakself.editorTable reloadData];
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if([module isEqualToString:@"order_detail"])
|
|
|
+ {
|
|
|
+
|
|
|
+ OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
|
|
|
+
|
|
|
+
|
|
|
+ vc.url_type = URL_REMOTE;
|
|
|
+ vc.request_url=URL_ORDER_DETAIL;
|
|
|
+
|
|
|
+
|
|
|
+ vc.params = [NSMutableDictionary dictionary];
|
|
|
+ // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
|
|
|
+ // NSData *data = [NSData dataWithContentsOfFile:path];
|
|
|
+ // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
|
|
|
+ [self.navigationController pushViewController:vc animated:NO];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ //block代码块取代了delegate
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ for(int i=0;i<self.content_action.count;i++)
|
|
|
+ {
|
|
|
+ NSMutableDictionary* json = self.content_action[i];
|
|
|
+ NSString* title =json[@"title"];
|
|
|
+ NSString* module = json[@"module"];
|
|
|
+ NSMutableDictionary* add_params = json[@"params"];
|
|
|
+ UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+
|
|
|
+
|
|
|
+ if([module isEqualToString:@"quick_look"])
|
|
|
+ {
|
|
|
+
|
|
|
+ // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
|
|
|
+ NSMutableDictionary *params = json[@"params"];
|
|
|
+ NSString* URL =json[@"url"];
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+
|
|
|
+
|
|
|
+ NSString *path = [RANetwork download_file:params url:URL];
|
|
|
+ weakSelf.documentPath = path;
|
|
|
+
|
|
|
+ if (path) {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if([module isEqualToString:@"kv_detail"])
|
|
|
+ {
|
|
|
+ NSMutableDictionary *params = json[@"params"];
|
|
|
+
|
|
|
+
|
|
|
+ UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
|
|
|
+
|
|
|
+
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSDictionary* json =[RANetwork kv_detail:params];
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
+
|
|
|
+
|
|
|
+ if([[json valueForKey:@"result"] intValue]==2)
|
|
|
+ {
|
|
|
+ KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
|
|
|
+ vc.content = [json mutableCopy];
|
|
|
+ [weakself.navigationController pushViewController:vc animated:NO];
|
|
|
+
|
|
|
+ // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
|
|
|
+ //
|
|
|
+ // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // [weakself download_success];
|
|
|
+ // [weakself.editorTable reloadData];
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if([module isEqualToString:@"order_detail"])
|
|
|
+ {
|
|
|
+
|
|
|
+ OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
|
|
|
+
|
|
|
+
|
|
|
+ vc.url_type = URL_REMOTE;
|
|
|
+ vc.request_url=URL_ORDER_DETAIL;
|
|
|
+
|
|
|
+
|
|
|
+ vc.params = [NSMutableDictionary dictionary];
|
|
|
+ // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
|
|
|
+ // NSData *data = [NSData dataWithContentsOfFile:path];
|
|
|
+ // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
|
|
|
+ [self.navigationController pushViewController:vc animated:NO];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // DebugLog(@"Cancel");
|
|
|
+ // if([actiontype isEqualToString:@"download"])
|
|
|
+ // {
|
|
|
+ // [weakSelf Export:add_params];
|
|
|
+ // }
|
|
|
+ // else if([actiontype isEqualToString:@"save"])
|
|
|
+ // {
|
|
|
+ // }
|
|
|
+ }];
|
|
|
+ [alertControl addAction:actioni];
|
|
|
+ }
|
|
|
+
|
|
|
+ UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ // DebugLog(@"Cancel");
|
|
|
+
|
|
|
+ }];
|
|
|
+ [alertControl addAction:actionCancel];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [self presentViewController:alertControl animated:NO completion:nil];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)save {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+-(void)Export:(NSString*) url {
|
|
|
+
|
|
|
+ if(self.download_query )
|
|
|
+ {
|
|
|
+ self.documentPath = self.download_query;
|
|
|
+ [self.navigationController pushViewController:self.quickLook animated:NO];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+
|
|
|
+ // NSMutableDictionary *params = self.params.mutableCopy;
|
|
|
+ // if(add_params!=nil)
|
|
|
+ // [params addEntriesFromDictionary:add_params];
|
|
|
+ NSString *path = [RANetwork download_query:url];
|
|
|
+ weakSelf.download_query = path;
|
|
|
+ weakSelf.documentPath = path;
|
|
|
+
|
|
|
+ if (path) {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+}
|
|
|
+- (void)downloadItemClick:(UIBarButtonItem *)sender {
|
|
|
+
|
|
|
+ if(self.download_query )
|
|
|
+ {
|
|
|
+ self.documentPath = self.download_query;
|
|
|
+ [self.navigationController pushViewController:self.quickLook animated:NO];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+
|
|
|
+ NSMutableDictionary *params = self.params.mutableCopy;
|
|
|
+ NSString *path = [RANetwork download_query:params];
|
|
|
+ weakSelf.download_query = path;
|
|
|
+ weakSelf.documentPath = path;
|
|
|
+
|
|
|
+ if (path) {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+@end
|