PortfolioListViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. //
  2. // PDFListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 11/23/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PortfolioListViewController.h"
  9. #import "PortfolioListTableViewCell.h"
  10. #import "RANetwork.h"
  11. #import "RAPDFViewController.h"
  12. #import "MainViewController.h"
  13. #import "DefaultAppearance.h"
  14. #import "DefaultTableHeaderView.h"
  15. #import "SortItemViewController.h"
  16. #import "UIColor+JK_HEX.h"
  17. #import "TextUtils.h"
  18. #import "RAConvertor.h"
  19. @interface PortfolioListViewController ()
  20. @end
  21. @implementation PortfolioListViewController
  22. -(void) logout
  23. {
  24. self.offset = 0;
  25. self.limit = 25;
  26. [self.content_data removeAllObjects];
  27. [self refresh_ui];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.offset = 0;
  32. self.limit = 25;
  33. self.content_data = [[NSMutableArray alloc]init];
  34. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  35. ref.tag = 201 ;
  36. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  37. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  38. // ref.hidden = true;
  39. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  40. [self.table addSubview:ref];
  41. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  42. self.label_net_err.layer.borderWidth = 2.0;
  43. self.label_net_err.layer.cornerRadius=15;
  44. self.label_net_err.layer.masksToBounds=true;
  45. CGPoint center = self.mum.center;
  46. self.mum.frame = CGRectMake(0, 0, 100, 100);
  47. self.mum.center = center;
  48. // self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
  49. self.mum.layer.cornerRadius = 5.0f;
  50. self.mum.layer.masksToBounds = YES;
  51. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  52. // tap.minimumPressDuration = 0.8; //定义按的时间
  53. [self.label_net_err addGestureRecognizer:tap];
  54. // Do any additional setup after loading the view.
  55. //#ifdef BUILD_UWAVER
  56. // self.navItem.title = @"View Hang Tags";
  57. //#endif
  58. }
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. // Dispose of any resources that can be recreated.
  62. }
  63. #ifndef RA_NOTIFICATION
  64. -(void) reload_container_getdata:(bool) update_data
  65. {
  66. [super reload_container_getdata:update_data];
  67. if(update_data)
  68. {
  69. self.offset = 0;
  70. [self.content_data removeAllObjects];
  71. self.norefresh=true;
  72. [self loadpage];
  73. }
  74. else
  75. [self.table reloadData];
  76. }
  77. #endif
  78. - (void)viewWillAppear:(BOOL)animated
  79. {
  80. [super viewWillAppear:animated];
  81. // if(!self.norefresh)//避免 多次刷新
  82. // {
  83. // self.norefresh = true;
  84. // self.offset = 0;
  85. // [self.content_data removeAllObjects];
  86. // [self loadpage];
  87. //
  88. // }
  89. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  90. }
  91. -(void)manually_refresh
  92. {
  93. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  94. if(self.isrefreshing)
  95. {
  96. [reF endRefreshing];
  97. return;
  98. }
  99. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  100. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  101. }
  102. -(void)ReloadData
  103. {
  104. [self.content_data removeAllObjects];
  105. [self.table reloadData];
  106. // self.table_order.hidden = true;
  107. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  108. [reF endRefreshing];
  109. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  110. self.keywords=self.searchbar.text;
  111. self.offset = 0;
  112. // [self.content_data removeAllObjects];
  113. // [self.table_order reloadData];
  114. [self loadpage];
  115. // [self loadpage];
  116. }
  117. -(void) loadpage
  118. {
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. if(self.isrefreshing)
  121. return;
  122. self.label_net_err.hidden=true;
  123. self.isrefreshing=true;
  124. self.table.hidden =true;
  125. self.mum.center = self.view.center;
  126. self.mum.hidden = false;
  127. [self.mum startAnimating];
  128. [RANetwork request_portfoliopdf:self.offset limit:self.limit keywords:self.keywords completionHandler:^(NSMutableDictionary *result) {
  129. NSMutableDictionary* content= result;
  130. [self.mum stopAnimating];
  131. int result_code=[[content valueForKey:@"result"] intValue];
  132. if(result_code==2||result_code==0)
  133. {
  134. self.table.hidden =false;
  135. int count = [[content valueForKey:@"count" ] intValue] ;
  136. // self.time_zone = [content valueForKey:@"time_zone" ];
  137. self.offset += count;
  138. for(int i=0;i<count;i++)
  139. {
  140. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  141. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  142. DebugLog(@"content_data: %@",self.content_data);
  143. }
  144. if(count<self.limit)
  145. {
  146. // int i =self.btnrefresh.state;
  147. self.load_more_hint=@"All loaded";
  148. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  149. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  150. }
  151. else
  152. {
  153. self.load_more_hint=@"Load more...";
  154. // self.btnrefresh.enabled = true;
  155. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  156. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  157. }
  158. [self.table reloadData ];
  159. }
  160. else if(result_code==RESULT_NET_ERROR)
  161. {
  162. self.label_net_err.hidden=false;
  163. self.table.hidden=true;
  164. }
  165. else
  166. {
  167. [RAUtils message_box:@"Loading Portfilio List" message:[content valueForKey:@"err_msg"] completion:nil];
  168. }
  169. self.isrefreshing=false;
  170. }];
  171. return;
  172. });
  173. }
  174. - (void)loadmore
  175. {
  176. // self.btnrefresh.enabled = NO;
  177. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  178. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  179. [self loadpage];
  180. }
  181. /*
  182. #pragma mark - Navigation
  183. // In a storyboard-based application, you will often want to do a little preparation before navigation
  184. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  185. // Get the new view controller using [segue destinationViewController].
  186. // Pass the selected object to the new view controller.
  187. }
  188. */
  189. #pragma mark - Table view data source
  190. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  191. {
  192. return 66;
  193. }
  194. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  195. //{
  196. // return 0;
  197. //}
  198. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  199. //{
  200. // return 0;
  201. //}
  202. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  203. //{
  204. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  205. // return myView;
  206. //
  207. //}
  208. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  209. {
  210. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  211. if(value==nil)
  212. value=@"";
  213. unsigned long color = strtoul([value UTF8String],0,16);
  214. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  215. // myView.backgroundColor = UIColorFromRGB(color);
  216. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  217. myView.layer.shadowOffset = CGSizeMake(0, 0);
  218. myView.layer.shadowOpacity = 0.5;
  219. myView.layer.shadowRadius = 2.0;
  220. UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 75, 22)];
  221. namelabel.textColor=UIColorFromRGB(color);
  222. namelabel.backgroundColor = [UIColor clearColor];
  223. namelabel.text=NSLocalizedString(@"Name", nil);
  224. [namelabel sizeToFit];
  225. [myView addSubview:namelabel];
  226. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(173, 5.5, 130, 22)];
  227. // solabel.textColor=[UIColor whiteColor];
  228. // solabel.backgroundColor = [UIColor clearColor];
  229. // solabel.text=NSLocalizedString(@"Name", nil);
  230. // [solabel sizeToFit];
  231. // [myView addSubview:solabel];
  232. UILabel *notelabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 11, 75, 22)];
  233. notelabel.textColor=UIColorFromRGB(color);
  234. notelabel.backgroundColor = [UIColor clearColor];
  235. notelabel.text=NSLocalizedString(@"Notes", nil);
  236. [notelabel sizeToFit];
  237. [myView addSubview:notelabel];
  238. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table.frame.size.width-163,11, 148, 22)];
  239. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  240. timelabel.textColor=UIColorFromRGB(color);
  241. timelabel.backgroundColor = [UIColor clearColor];
  242. timelabel.text=@"Create time";
  243. [timelabel sizeToFit];
  244. [myView addSubview:timelabel];
  245. myView.autoresizesSubviews=true;
  246. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  247. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  248. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  249. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  250. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  251. //
  252. return myView;
  253. }
  254. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  255. {
  256. return 44;
  257. }
  258. //
  259. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  260. // if(section==0)
  261. // return nil;
  262. // else
  263. // return @"detail section";
  264. //}
  265. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  266. {
  267. return 1;
  268. }
  269. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  270. {
  271. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  272. if( self.content_data.count==0)
  273. return 0;
  274. return self.content_data.count+1;
  275. }
  276. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  277. {
  278. // if(tableView==self.itemListTable)
  279. // {
  280. // if(indexPath.row>self.content_data.count)
  281. // {
  282. // int debug=true;
  283. // }
  284. // DebugLog(@"row %ld",(long)indexPath.row);
  285. if(indexPath.row==self.content_data.count)
  286. {
  287. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  288. UILabel *moreDataLabel=[[UILabel alloc] init];
  289. moreDataLabel.tag=200;
  290. moreDataLabel.text=self.load_more_hint;
  291. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  292. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  293. moreDataLabel.frame=CGRectMake(0, 10, self.table.bounds.size.width, 20);
  294. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  295. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  296. [moreCell.contentView addSubview:moreDataLabel];
  297. if([self.load_more_hint isEqualToString:@"Load more..."])
  298. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  299. // DebugLog(@"更多...");
  300. moreCell.backgroundColor = [UIColor whiteColor];
  301. return moreCell;
  302. }
  303. else
  304. {
  305. NSString *CellIdentifier = @"PDFListTableViewCell";
  306. PortfolioListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  307. // int _id= [[self.content_data[indexPath.row] valueForKey:@"_id"] intValue];
  308. NSString* name= [self.content_data[indexPath.row] valueForKey:@"tear_name"];
  309. NSString* note= [self.content_data[indexPath.row] valueForKey:@"tear_note"];
  310. NSString* create_time= [self.content_data[indexPath.row] valueForKey:@"create_time"];
  311. // NSString* type = [self.content_data[indexPath.row] valueForKey:@"type"] ;
  312. // NSString* file_name = [self.content_data[indexPath.row] valueForKey:@"file_name"];
  313. cell.labelName.text = name;
  314. cell.labelTime.text = create_time;
  315. cell.labelNote.text = note;
  316. // cell.labelType.text = type;
  317. // cell.labelprice.text=price;
  318. // cell.label_date.text=purchase_time;
  319. // cell.label_contact.text=customer_name;
  320. // cell.label_model.text = model_count;
  321. //
  322. // cell.label_status.text=status;
  323. cell.backgroundColor = [UIColor whiteColor];
  324. return cell;
  325. }
  326. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  327. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  328. // cell.bundle_item=combine_json;
  329. // NSString* img_url = [item_json valueForKey:@"img_url"];
  330. // NSString* description = [item_json valueForKey:@"description"];
  331. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  332. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  333. // NSString* currency = [item_json valueForKey:@"currency"];
  334. // int count =[[item_json valueForKey:@"count"] intValue];
  335. // double price =[[item_json valueForKey:@"price"] doubleValue];
  336. // // cell.labelAttribute.text = attribute;
  337. // cell.labelCurrency.text = currency;
  338. // cell.labelDescription.text = description;
  339. // // cell.labelIdentifier.text = identifier;
  340. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  341. //
  342. //
  343. //
  344. // [cell set_Count:count];
  345. // NSString* file_name=[img_url lastPathComponent];
  346. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  347. // if(img_data!=nil)
  348. // {
  349. //
  350. // UIImage * img =[UIImage imageWithData:img_data];
  351. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  352. // }
  353. // else
  354. // {
  355. //
  356. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  357. //
  358. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  359. //
  360. // dispatch_async(dispatch_get_main_queue(), ^{
  361. //
  362. //
  363. //
  364. // if(downloadimg_data!=nil)
  365. // {
  366. // [iSalesDB cache_img:downloadimg_data :file_name ];
  367. //
  368. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  369. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  370. // }
  371. //
  372. // });
  373. // });
  374. //
  375. //
  376. // }
  377. // }
  378. // else
  379. // {
  380. // NSString *CellIdentifier = @"OrderInfoListItem";
  381. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  382. // return cell;
  383. // }
  384. }
  385. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  386. {
  387. if(self.content_data.count== indexPath.row)
  388. return;
  389. NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  390. __block NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  391. if(url==nil)
  392. {
  393. NSMutableDictionary* params = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"off_params"]] mutableCopy];
  394. NSMutableDictionary* values = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"model_info"]] mutableCopy];
  395. params[@"replaceValue"]=values;
  396. params[@"tearsheetsId"]=[self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  397. [RANetwork request_create_portfolio:params completionHandler:^(NSMutableDictionary *result) {
  398. // NSString* createpdf = result;
  399. url=result[@"pdf_path"];
  400. BOOL isLocalFile= [[self.content_data[indexPath.row] valueForKey:@"isLocalFile"] boolValue];
  401. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  402. ViewController.url = url;
  403. ViewController.canSave = false;
  404. ViewController.isLocalfile=isLocalFile;
  405. NSString* subject;
  406. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  407. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  408. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  409. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  410. if(customer_email.length>0)
  411. {
  412. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  413. }
  414. ViewController.mail_to = send_to;
  415. NSString* lfilename = [TextUtils legalFilename:name];
  416. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",lfilename];
  417. ViewController.mail_subject = subject;
  418. ViewController.hidenavi = false;
  419. [self.navigationController pushViewController:ViewController animated:YES];
  420. }];
  421. return;
  422. // NSString* createpdf = [RANetwork create_portfolio:params];
  423. // if(createpdf!=nil)
  424. // url=createpdf;
  425. // if()
  426. }
  427. BOOL isLocalFile= [[self.content_data[indexPath.row] valueForKey:@"isLocalFile"] boolValue];
  428. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  429. ViewController.url = url;
  430. ViewController.canSave = false;
  431. ViewController.isLocalfile=isLocalFile;
  432. NSString* subject;
  433. // if (company.length==0) {
  434. // NSString* cur_time =[RAUtils current_date];
  435. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  436. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  437. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  438. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  439. if(customer_email.length>0)
  440. {
  441. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  442. // customer_email compo
  443. // [send_to addObject:customer_email];
  444. }
  445. ViewController.mail_to = send_to;
  446. // }
  447. // else
  448. // {
  449. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  450. // }
  451. NSString* lfilename = [TextUtils legalFilename:name];
  452. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",lfilename];
  453. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",lfilename];
  454. ViewController.mail_subject = subject;
  455. ViewController.hidenavi = false;
  456. [self.navigationController pushViewController:ViewController animated:YES];
  457. //[self.navigationController setNavigationBarHidden:NO animated:NO];
  458. }
  459. #pragma mark - searchBar delegate;
  460. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  461. {
  462. self.keywords=searchBar.text;
  463. self.offset = 0;
  464. [self.content_data removeAllObjects];
  465. [self loadpage];
  466. }
  467. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  468. {
  469. if([searchText isEqualToString:@""] && !self.reset)
  470. {
  471. DebugLog(@"clear");
  472. self.reset=true;
  473. self.keywords=nil;
  474. self.offset = 0;
  475. [self.content_data removeAllObjects];
  476. [self loadpage];
  477. }
  478. else
  479. self.reset = false;
  480. }
  481. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  482. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  483. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  484. {
  485. NSString* listid= [self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  486. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  487. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  488. DebugLog(@"delete click");
  489. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure to remove portfolio?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  490. // // alert.tag = ALERT_DEL;
  491. // // alert.
  492. // [alert show];
  493. //
  494. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to remove this portfolio?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  495. //block代码块取代了delegate
  496. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  497. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Portfilio" completion:^{
  498. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Portfilio" completion:nil];
  499. [RANetwork request_removeportfoliopdf:listid completionHandler:^(NSMutableDictionary *result) {
  500. NSMutableDictionary* cart_json = result;
  501. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  502. [pop hide];
  503. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  504. if([[cart_json valueForKey:@"result"] intValue]==2)
  505. {
  506. [self ReloadData];
  507. }
  508. else
  509. {
  510. [RAUtils message_box:@"Delete Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  511. }
  512. }];
  513. // }];
  514. }];
  515. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  516. DebugLog(@"No");
  517. }];
  518. [alertControl addAction:actionOne];
  519. [alertControl addAction:alertthree];
  520. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  521. [self presentViewController:alertControl animated:YES completion:nil];
  522. }];
  523. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  524. NSString* create_user= [self.content_data[indexPath.row] valueForKey:@"create_user"];
  525. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  526. if([create_user isEqualToString:RASingleton.sharedInstance.user])
  527. {
  528. // return @[deleteRowAction];
  529. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  530. }
  531. // return @[];
  532. return [UISwipeActionsConfiguration configurationWithActions:@[]];
  533. }
  534. - (void)tableView:(UITableView *)tableView
  535. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  536. }
  537. - (void)reRefreshView {
  538. [self.table reloadData];
  539. }
  540. #pragma mark - RA_NOTIFICAITON
  541. -(void) refresh_ui
  542. {
  543. [self.table reloadData];
  544. }
  545. -(void) reload_data
  546. {
  547. self.offset = 0;
  548. [self.content_data removeAllObjects];
  549. [self.table reloadData];
  550. self.norefresh=true;
  551. [self loadpage];
  552. }
  553. @end