PortfolioListViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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_alert:[content valueForKey:@"err_msg"] title:@"Loading Portfilio List" controller:self] ;
  168. }
  169. self.isrefreshing=false;
  170. }];
  171. return;
  172. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  173. NSMutableDictionary* content=nil;
  174. content=[[RANetwork request_PDFList:self.offset limit : self.limit keywords:self.keywords] mutableCopy];
  175. dispatch_async(dispatch_get_main_queue(), ^{
  176. [self.mum stopAnimating];
  177. int result=[[content valueForKey:@"result"] intValue];
  178. if(result==2||result==0)
  179. {
  180. self.table.hidden =false;
  181. int count = [[content valueForKey:@"count" ] intValue] ;
  182. // self.time_zone = [content valueForKey:@"time_zone" ];
  183. self.offset += count;
  184. for(int i=0;i<count;i++)
  185. {
  186. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  187. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  188. DebugLog(@"content_data: %@",self.content_data);
  189. }
  190. if(count<self.limit)
  191. {
  192. // int i =self.btnrefresh.state;
  193. self.load_more_hint=@"All loaded";
  194. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  195. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  196. }
  197. else
  198. {
  199. self.load_more_hint=@"Load more...";
  200. // self.btnrefresh.enabled = true;
  201. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  202. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  203. }
  204. [self.table reloadData ];
  205. }
  206. else if(result==RESULT_NET_ERROR)
  207. {
  208. self.label_net_err.hidden=false;
  209. self.table.hidden=true;
  210. }
  211. else
  212. {
  213. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Portfilio List" controller:self] ;
  214. }
  215. self.isrefreshing=false;
  216. });
  217. });
  218. });
  219. }
  220. - (void)loadmore
  221. {
  222. // self.btnrefresh.enabled = NO;
  223. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  224. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  225. [self loadpage];
  226. }
  227. /*
  228. #pragma mark - Navigation
  229. // In a storyboard-based application, you will often want to do a little preparation before navigation
  230. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  231. // Get the new view controller using [segue destinationViewController].
  232. // Pass the selected object to the new view controller.
  233. }
  234. */
  235. #pragma mark - Table view data source
  236. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  237. {
  238. return 66;
  239. }
  240. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  241. //{
  242. // return 0;
  243. //}
  244. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  245. //{
  246. // return 0;
  247. //}
  248. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  249. //{
  250. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  251. // return myView;
  252. //
  253. //}
  254. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  255. {
  256. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  257. if(value==nil)
  258. value=@"";
  259. unsigned long color = strtoul([value UTF8String],0,16);
  260. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  261. // myView.backgroundColor = UIColorFromRGB(color);
  262. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  263. myView.layer.shadowOffset = CGSizeMake(0, 0);
  264. myView.layer.shadowOpacity = 0.5;
  265. myView.layer.shadowRadius = 2.0;
  266. UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 75, 22)];
  267. namelabel.textColor=UIColorFromRGB(color);
  268. namelabel.backgroundColor = [UIColor clearColor];
  269. namelabel.text=NSLocalizedString(@"Name", nil);
  270. [namelabel sizeToFit];
  271. [myView addSubview:namelabel];
  272. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(173, 5.5, 130, 22)];
  273. // solabel.textColor=[UIColor whiteColor];
  274. // solabel.backgroundColor = [UIColor clearColor];
  275. // solabel.text=NSLocalizedString(@"Name", nil);
  276. // [solabel sizeToFit];
  277. // [myView addSubview:solabel];
  278. UILabel *notelabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 11, 75, 22)];
  279. notelabel.textColor=UIColorFromRGB(color);
  280. notelabel.backgroundColor = [UIColor clearColor];
  281. notelabel.text=NSLocalizedString(@"Notes", nil);
  282. [notelabel sizeToFit];
  283. [myView addSubview:notelabel];
  284. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table.frame.size.width-163,11, 148, 22)];
  285. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  286. timelabel.textColor=UIColorFromRGB(color);
  287. timelabel.backgroundColor = [UIColor clearColor];
  288. timelabel.text=@"Create time";
  289. [timelabel sizeToFit];
  290. [myView addSubview:timelabel];
  291. myView.autoresizesSubviews=true;
  292. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  293. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  294. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  295. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  296. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  297. //
  298. return myView;
  299. }
  300. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  301. {
  302. return 44;
  303. }
  304. //
  305. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  306. // if(section==0)
  307. // return nil;
  308. // else
  309. // return @"detail section";
  310. //}
  311. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  312. {
  313. return 1;
  314. }
  315. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  316. {
  317. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  318. if( self.content_data.count==0)
  319. return 0;
  320. return self.content_data.count+1;
  321. }
  322. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  323. {
  324. // if(tableView==self.itemListTable)
  325. // {
  326. // if(indexPath.row>self.content_data.count)
  327. // {
  328. // int debug=true;
  329. // }
  330. // DebugLog(@"row %ld",(long)indexPath.row);
  331. if(indexPath.row==self.content_data.count)
  332. {
  333. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  334. UILabel *moreDataLabel=[[UILabel alloc] init];
  335. moreDataLabel.tag=200;
  336. moreDataLabel.text=self.load_more_hint;
  337. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  338. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  339. moreDataLabel.frame=CGRectMake(0, 10, self.table.bounds.size.width, 20);
  340. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  341. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  342. [moreCell.contentView addSubview:moreDataLabel];
  343. if([self.load_more_hint isEqualToString:@"Load more..."])
  344. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  345. // DebugLog(@"更多...");
  346. moreCell.backgroundColor = [UIColor whiteColor];
  347. return moreCell;
  348. }
  349. else
  350. {
  351. NSString *CellIdentifier = @"PDFListTableViewCell";
  352. PortfolioListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  353. // int _id= [[self.content_data[indexPath.row] valueForKey:@"_id"] intValue];
  354. NSString* name= [self.content_data[indexPath.row] valueForKey:@"tear_name"];
  355. NSString* note= [self.content_data[indexPath.row] valueForKey:@"tear_note"];
  356. NSString* create_time= [self.content_data[indexPath.row] valueForKey:@"create_time"];
  357. // NSString* type = [self.content_data[indexPath.row] valueForKey:@"type"] ;
  358. // NSString* file_name = [self.content_data[indexPath.row] valueForKey:@"file_name"];
  359. cell.labelName.text = name;
  360. cell.labelTime.text = create_time;
  361. cell.labelNote.text = note;
  362. // cell.labelType.text = type;
  363. // cell.labelprice.text=price;
  364. // cell.label_date.text=purchase_time;
  365. // cell.label_contact.text=customer_name;
  366. // cell.label_model.text = model_count;
  367. //
  368. // cell.label_status.text=status;
  369. cell.backgroundColor = [UIColor whiteColor];
  370. return cell;
  371. }
  372. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  373. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  374. // cell.bundle_item=combine_json;
  375. // NSString* img_url = [item_json valueForKey:@"img_url"];
  376. // NSString* description = [item_json valueForKey:@"description"];
  377. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  378. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  379. // NSString* currency = [item_json valueForKey:@"currency"];
  380. // int count =[[item_json valueForKey:@"count"] intValue];
  381. // double price =[[item_json valueForKey:@"price"] doubleValue];
  382. // // cell.labelAttribute.text = attribute;
  383. // cell.labelCurrency.text = currency;
  384. // cell.labelDescription.text = description;
  385. // // cell.labelIdentifier.text = identifier;
  386. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  387. //
  388. //
  389. //
  390. // [cell set_Count:count];
  391. // NSString* file_name=[img_url lastPathComponent];
  392. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  393. // if(img_data!=nil)
  394. // {
  395. //
  396. // UIImage * img =[UIImage imageWithData:img_data];
  397. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  398. // }
  399. // else
  400. // {
  401. //
  402. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  403. //
  404. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  405. //
  406. // dispatch_async(dispatch_get_main_queue(), ^{
  407. //
  408. //
  409. //
  410. // if(downloadimg_data!=nil)
  411. // {
  412. // [iSalesDB cache_img:downloadimg_data :file_name ];
  413. //
  414. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  415. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  416. // }
  417. //
  418. // });
  419. // });
  420. //
  421. //
  422. // }
  423. // }
  424. // else
  425. // {
  426. // NSString *CellIdentifier = @"OrderInfoListItem";
  427. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  428. // return cell;
  429. // }
  430. }
  431. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  432. {
  433. if(self.content_data.count== indexPath.row)
  434. return;
  435. NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  436. NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  437. if(url==nil)
  438. {
  439. NSMutableDictionary* params = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"off_params"]] mutableCopy];
  440. NSMutableDictionary* values = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"model_info"]] mutableCopy];
  441. params[@"replaceValue"]=values;
  442. params[@"tearsheetsId"]=[self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  443. NSString* createpdf = [RANetwork create_portfolio:params];
  444. if(createpdf!=nil)
  445. url=createpdf;
  446. // if()
  447. }
  448. BOOL isLocalFile= [[self.content_data[indexPath.row] valueForKey:@"isLocalFile"] boolValue];
  449. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  450. ViewController.url = url;
  451. ViewController.canSave = false;
  452. ViewController.isLocalfile=isLocalFile;
  453. NSString* subject;
  454. // if (company.length==0) {
  455. // NSString* cur_time =[RAUtils current_date];
  456. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  457. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  458. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  459. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  460. if(customer_email.length>0)
  461. {
  462. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  463. // customer_email compo
  464. // [send_to addObject:customer_email];
  465. }
  466. ViewController.mail_to = send_to;
  467. // }
  468. // else
  469. // {
  470. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  471. // }
  472. NSString* lfilename = [TextUtils legalFilename:name];
  473. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",lfilename];
  474. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",lfilename];
  475. ViewController.mail_subject = subject;
  476. ViewController.hidenavi = false;
  477. [self.navigationController pushViewController:ViewController animated:YES];
  478. //[self.navigationController setNavigationBarHidden:NO animated:NO];
  479. }
  480. #pragma mark - searchBar delegate;
  481. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  482. {
  483. self.keywords=searchBar.text;
  484. self.offset = 0;
  485. [self.content_data removeAllObjects];
  486. [self loadpage];
  487. }
  488. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  489. {
  490. if([searchText isEqualToString:@""] && !self.reset)
  491. {
  492. DebugLog(@"clear");
  493. self.reset=true;
  494. self.keywords=nil;
  495. self.offset = 0;
  496. [self.content_data removeAllObjects];
  497. [self loadpage];
  498. }
  499. else
  500. self.reset = false;
  501. }
  502. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  503. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  504. {
  505. NSString* listid= [self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
  506. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  507. DebugLog(@"delete click");
  508. // 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];
  509. // // alert.tag = ALERT_DEL;
  510. // // alert.
  511. // [alert show];
  512. //
  513. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to remove this portfolio?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  514. //block代码块取代了delegate
  515. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  516. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Portfilio"];
  517. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  518. NSDictionary* cart_json = [RANetwork delete_portfoliolist:listid];
  519. dispatch_async(dispatch_get_main_queue(), ^{
  520. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  521. if([[cart_json valueForKey:@"result"] intValue]==2)
  522. {
  523. [self ReloadData];
  524. }
  525. else
  526. {
  527. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Portfolio" controller:self] ;
  528. }
  529. });
  530. });
  531. }];
  532. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  533. DebugLog(@"No");
  534. }];
  535. [alertControl addAction:actionOne];
  536. [alertControl addAction:alertthree];
  537. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  538. [self presentViewController:alertControl animated:YES completion:nil];
  539. }];
  540. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  541. NSString* create_user= [self.content_data[indexPath.row] valueForKey:@"create_user"];
  542. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  543. if([create_user isEqualToString:appDelegate.user])
  544. {
  545. return @[deleteRowAction];
  546. }
  547. return @[];
  548. }
  549. - (void)tableView:(UITableView *)tableView
  550. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  551. }
  552. - (void)reRefreshView {
  553. [self.table reloadData];
  554. }
  555. #pragma mark - RA_NOTIFICAITON
  556. -(void) refresh_ui
  557. {
  558. [self.table reloadData];
  559. }
  560. -(void) reload_data
  561. {
  562. self.offset = 0;
  563. [self.content_data removeAllObjects];
  564. [self.table reloadData];
  565. self.norefresh=true;
  566. [self loadpage];
  567. }
  568. @end