DocumentListViewController.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. //
  2. // DocumentListViewController.m
  3. // Granite Expo eSign
  4. //
  5. // Created by Ray on 12/28/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DocumentListViewController.h"
  9. #import "ACNetwork.h"
  10. #import "DocListTableViewCell.h"
  11. #import "RAUtils.h"
  12. #import "GEContractFilterViewController.h"
  13. #import "PDFViewController.h"
  14. #import "AppDelegate.h"
  15. @interface DocumentListViewController ()
  16. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  17. @end
  18. @implementation DocumentListViewController
  19. - (NSOperationQueue *)dataOperationQueue {
  20. if (!_dataOperationQueue) {
  21. _dataOperationQueue = [[NSOperationQueue alloc] init];
  22. _dataOperationQueue.maxConcurrentOperationCount = 1;
  23. }
  24. return _dataOperationQueue;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.offset = 0;
  29. self.limit = 20;
  30. self.table_data = [[NSMutableArray alloc] init];
  31. self.filterparams = [[NSMutableDictionary alloc]init];
  32. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  33. self.label_net_err.layer.borderWidth = 2.0;
  34. self.label_net_err.layer.cornerRadius=15;
  35. self.label_net_err.layer.masksToBounds=true;
  36. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  37. [self.label_net_err addGestureRecognizer:tap];
  38. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  39. ref.tag = 201 ;
  40. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  41. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  42. // ref.hidden = true;
  43. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  44. [self.tableView addSubview:ref];
  45. // NSMutableArray * arr = [[NSMutableArray alloc] init];
  46. // for(int i=0;i<100;i++)
  47. // {
  48. // [arr addObject:[NSNumber numberWithInt:i]];
  49. // }
  50. // NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
  51. // dict[@"arr"] = arr;
  52. // DebugLog([RAUtils dict2string:dict]);
  53. [self loadpage];
  54. // Do any additional setup after loading the view.
  55. }
  56. - (void)didReceiveMemoryWarning {
  57. [super didReceiveMemoryWarning];
  58. // Dispose of any resources that can be recreated.
  59. }
  60. - (IBAction)onFilterClick:(id)sender {
  61. GEContractFilterViewController * filterVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"GEContractFilterViewController"];
  62. filterVC.filterparams = self.filterparams;
  63. filterVC.OnSearch = ^(NSMutableDictionary* params)
  64. {
  65. // [self reload_container_getdata:true];
  66. self.reset_result=true;
  67. // self.norefresh=true;
  68. [self loadpage];
  69. };
  70. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:filterVC] ;
  71. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  72. [self presentViewController:navi animated:YES completion:^{
  73. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  74. DebugLog(@"filter present.........");
  75. // self.btop = false;
  76. // <#code#>
  77. }];
  78. }
  79. -(void) previewPDF:(NSString*)url
  80. {
  81. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  82. // NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  83. bool isLocalFile= false;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  84. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  85. ViewController.url = url;
  86. ViewController.canSave = false;
  87. ViewController.isLocalfile=isLocalFile;
  88. ViewController.defaultStyle = true;
  89. NSString* subject;
  90. // if (company.length==0) {
  91. NSString* cur_time =[RAUtils current_date];
  92. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  93. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  94. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  95. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  96. // if(customer_email.length>0)
  97. // {
  98. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  99. // // customer_email compo
  100. // // [send_to addObject:customer_email];
  101. // }
  102. ViewController.mail_to = send_to;
  103. // }
  104. // else
  105. // {
  106. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  107. // }
  108. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  109. ViewController.mail_subject = subject;
  110. ViewController.hidenavi = false;
  111. [self.navigationController pushViewController:ViewController animated:YES];
  112. }
  113. #pragma mark - OperationQueue request page data
  114. -(void) loadpage
  115. {
  116. __weak typeof(self) weakself = self;
  117. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  118. if (weakself) {
  119. __strong typeof(weakself) strongself = weakself;
  120. [strongself operation_loadPage];
  121. }
  122. }];
  123. [self.dataOperationQueue addOperation:operation];
  124. }
  125. - (void)loadmore
  126. {
  127. // self.btnrefresh.enabled = NO;
  128. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  129. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  130. [self loadpage];
  131. }
  132. -(void)manually_refresh
  133. {
  134. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  135. // if(self.isrefreshing)
  136. // {
  137. // [reF endRefreshing];
  138. // return;
  139. // }
  140. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  141. if ([self respondsToSelector:@selector(ReloadData)])
  142. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  143. }
  144. -(void)ReloadData
  145. {
  146. // [self.content_data removeAllObjects];
  147. // [self.table_order reloadData];
  148. // self.table_order.hidden = true;
  149. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  150. [reF endRefreshing];
  151. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  152. // self.keywords=self.searchbar.text;
  153. // // self.offset = 0;
  154. self.reset_result=true;
  155. // [self.content_data removeAllObjects];
  156. // [self.table_order reloadData];
  157. [self loadpage];
  158. // [self loadpage];
  159. }
  160. -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer
  161. {
  162. // [self reload_container_getdata:true];
  163. self.reset_result=true;
  164. // self.norefresh=true;
  165. [self loadpage];
  166. }
  167. - (void)operation_loadPage {
  168. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  169. return;
  170. }
  171. dispatch_sync(dispatch_get_main_queue(), ^{
  172. //在主线程处理界面逻辑
  173. if(self.reset_result)
  174. {
  175. self.offset = 0;
  176. //[self.filterparams removeAllObjects];
  177. [self.table_data removeAllObjects];
  178. [self.tableView reloadData];
  179. }
  180. //
  181. // // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  182. //
  183. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  184. // int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  185. // for(int i=0;i<count;i++)
  186. // {
  187. // NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  188. // int check = [[val_json valueForKey:@"check"] intValue];
  189. // if(check==1)
  190. // {
  191. // // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  192. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  193. //
  194. // // break;
  195. // }
  196. // }
  197. //
  198. // // NSString * str_status = [arr_status componentsJoinedByString:@","];
  199. // NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  200. // if(str_statusname.length==0)
  201. // str_statusname = @"All";
  202. // self.label_filter.text = str_statusname;
  203. // if(self.offset==0)
  204. // {
  205. // self.table_order.hidden = true;
  206. //
  207. self.mum.center = self.view.center;
  208. self.mum.hidden = false;
  209. [self.mum startAnimating];
  210. // }
  211. self.label_net_err.hidden=true;
  212. });
  213. NSMutableDictionary* content=nil;
  214. // NSMutableDictionary* params = [[NSMutableDictionary alloc]init];
  215. self.filterparams[@"offset"] = [NSNumber numberWithLong:self.offset];
  216. // self.filterparams = params;
  217. content=[[ACNetwork request_DocList:self.filterparams]mutableCopy];
  218. dispatch_sync(dispatch_get_main_queue(), ^{
  219. //在主线程处理界请求结果
  220. [self.mum stopAnimating];
  221. // self.isrefreshing=false;
  222. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  223. return ;
  224. }
  225. int result=[[content valueForKey:@"result"] intValue];
  226. if(result==2||result==0)
  227. {
  228. NSArray * arrlist = content[@"list"];
  229. long count = arrlist.count ;
  230. self.offset += count;
  231. [self.table_data addObjectsFromArray:arrlist];
  232. // for(int i=0;i<count;i++)
  233. // {
  234. //
  235. // NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  236. //
  237. // table_data
  238. //
  239. // [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  240. //
  241. // }
  242. if(count<self.limit)
  243. {
  244. // int i =self.btnrefresh.state;
  245. self.load_more_hint=@"All loaded";
  246. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  247. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  248. }
  249. else
  250. {
  251. self.load_more_hint=@"Load more...";
  252. // self.btnrefresh.enabled = true;
  253. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  254. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  255. }
  256. self.tableView.hidden = false;
  257. self.reset_result=false;
  258. [self.tableView reloadData ];
  259. }
  260. else if(result==RESULT_NET_ERROR &&self.offset==0)
  261. {
  262. self.label_net_err.hidden=false;
  263. self.tableView.hidden = true;
  264. }
  265. else
  266. {
  267. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Document List" controller:self] ;
  268. }
  269. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  270. // bool autologin =[defaults boolForKey:@"autologin"];
  271. // if(!autologin)
  272. // {
  273. // TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  274. // [self presentViewController:viewController animated:YES completion:^{
  275. //
  276. // }];
  277. // }
  278. });
  279. }
  280. /*
  281. #pragma mark - Navigation
  282. // In a storyboard-based application, you will often want to do a little preparation before navigation
  283. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  284. // Get the new view controller using [segue destinationViewController].
  285. // Pass the selected object to the new view controller.
  286. }
  287. */
  288. #pragma mark - Table view data source
  289. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  290. {
  291. if(indexPath.row<self.table_data.count)
  292. return 128;
  293. else
  294. return 44;
  295. }
  296. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  297. //{
  298. // return 0;
  299. //}
  300. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  301. //{
  302. // return 0;
  303. //}
  304. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  305. //{
  306. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  307. // return myView;
  308. //
  309. //}
  310. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  311. {
  312. NSString* value =nil;//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  313. if(value==nil)
  314. value=@"";
  315. unsigned long color = strtoul([value UTF8String],0,16);
  316. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  317. myView.backgroundColor = UIColorFromRGB(0xf7f7f7);
  318. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  319. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  320. myView.layer.shadowOffset = CGSizeMake(0, 0);
  321. myView.layer.shadowOpacity = 0.5;
  322. myView.layer.shadowRadius = 2.0;
  323. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 2, 130, 22)];
  324. statuslabel.textColor=UIColorFromRGB(color);
  325. statuslabel.backgroundColor = [UIColor clearColor];
  326. statuslabel.text=NSLocalizedString(@"Document #", nil);
  327. [statuslabel sizeToFit];
  328. [myView addSubview:statuslabel];
  329. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 21, 130, 22)];
  330. solabel.textColor=UIColorFromRGB(color);
  331. solabel.backgroundColor = [UIColor clearColor];
  332. solabel.text=NSLocalizedString(@"Address", nil);
  333. [solabel sizeToFit];
  334. [myView addSubview:solabel];
  335. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(143, 2, 135, 22)];
  336. userlabel.textColor=UIColorFromRGB(color);
  337. userlabel.backgroundColor = [UIColor clearColor];
  338. userlabel.text=NSLocalizedString(@"Customer", nil);
  339. [userlabel sizeToFit];
  340. [myView addSubview:userlabel];
  341. // UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)];
  342. // creatorlabel.textColor=UIColorFromRGB(color);
  343. // creatorlabel.backgroundColor = [UIColor clearColor];
  344. // creatorlabel.text=NSLocalizedString(@"Create by", nil);
  345. // [creatorlabel sizeToFit];
  346. // [myView addSubview:creatorlabel];
  347. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(345, 2, 150, 22)];
  348. contactlabel.textColor=UIColorFromRGB(color);
  349. contactlabel.backgroundColor = [UIColor clearColor];
  350. contactlabel.text=NSLocalizedString(@"Job Date", nil);
  351. [contactlabel sizeToFit];
  352. [myView addSubview:contactlabel];
  353. //
  354. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  355. // modellabel.textColor=[UIColor whiteColor];
  356. // modellabel.backgroundColor = [UIColor clearColor];
  357. // modellabel.text=NSLocalizedString(@"Model", nil);
  358. // [modellabel sizeToFit];
  359. // [myView addSubview:modellabel];
  360. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  361. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  362. // modellabel.textColor=[UIColor whiteColor];
  363. // modellabel.backgroundColor = [UIColor clearColor];
  364. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  365. // [modellabel sizeToFit];
  366. // [myView addSubview:modellabel];
  367. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.tableView.frame.size.width-313, 2, 100, 22)];
  368. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  369. pricelabel.textColor=UIColorFromRGB(color);
  370. pricelabel.backgroundColor = [UIColor clearColor];
  371. pricelabel.text=NSLocalizedString(@"Agent Name", nil);
  372. [pricelabel sizeToFit];
  373. [myView addSubview:pricelabel];
  374. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.tableView.frame.size.width-111/*605*/,2, 148, 22)];
  375. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  376. timelabel.textColor=UIColorFromRGB(color);
  377. timelabel.backgroundColor = [UIColor clearColor];
  378. // if(self.time_zone==nil)
  379. timelabel.text=@"Sign Date";
  380. // else
  381. // timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  382. [timelabel sizeToFit];
  383. [myView addSubview:timelabel];
  384. myView.autoresizesSubviews=true;
  385. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  386. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  387. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  388. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  389. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  390. //
  391. return myView;
  392. }
  393. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  394. //{
  395. //
  396. //
  397. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  398. //
  399. // if(value==nil)
  400. // value=@"";
  401. // unsigned long color = strtoul([value UTF8String],0,16);
  402. //
  403. //
  404. // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  405. // // myView.backgroundColor = UIColorFromRGB(0x996633);;
  406. //
  407. //
  408. // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  409. // // myView.layer.masksToBounds = false;
  410. // //添加四个边阴影
  411. //
  412. // myView.layer.shadowColor = [UIColor blackColor].CGColor;
  413. // myView.layer.shadowOffset = CGSizeMake(0, 0);
  414. // myView.layer.shadowOpacity = 0.5;
  415. // myView.layer.shadowRadius = 2.0;
  416. //
  417. //
  418. // NSString*labeltitle = nil;
  419. // switch (section) {
  420. // case 0:
  421. // labeltitle= @"Order Info";
  422. // break;
  423. // case 1:
  424. // {
  425. // labeltitle= @"More Info";
  426. //
  427. // NSString* btntitle=nil ;
  428. // if(self.showMore)
  429. // {
  430. // btntitle=@"Hide";
  431. // // [section setValue:@"false" forKey:@"hide"];
  432. // // [sender setTitle:@"Show" forState:UIControlStateNormal];
  433. // }
  434. // else{
  435. // btntitle=@"Show";
  436. // }
  437. //
  438. //
  439. // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  440. // btn.tag=section;
  441. // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  442. // [btn setTitle:btntitle forState:UIControlStateNormal];
  443. // [myView addSubview:btn];
  444. //
  445. // }
  446. // break;
  447. // case 2:{
  448. // labeltitle= @"Models";
  449. //
  450. // NSString* btntitle=nil ;
  451. // if(self.showModels)
  452. // {
  453. // btntitle=@"Hide";
  454. // }
  455. // else{
  456. // btntitle=@"Show";
  457. // }
  458. //
  459. //
  460. // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  461. // btn.tag=section;
  462. //
  463. // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  464. //
  465. // [btn setTitle:btntitle forState:UIControlStateNormal];
  466. // [myView addSubview:btn];
  467. //
  468. // }
  469. // break;
  470. // case 3:
  471. // labeltitle= @"Price Info";
  472. // default:
  473. // break;
  474. // }
  475. //
  476. //
  477. //
  478. // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  479. // titlelabel.textColor=UIColorFromRGB(color);;
  480. // titlelabel.backgroundColor = [UIColor clearColor];
  481. // titlelabel.text=NSLocalizedString(labeltitle, nil);
  482. // [titlelabel sizeToFit];
  483. // [myView addSubview:titlelabel];
  484. //
  485. // //
  486. // return myView;
  487. //}
  488. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  489. //
  490. // return [NSString stringWithFormat:@"Signature%ld",(long)section+1];
  491. //
  492. //}
  493. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  494. {
  495. return 1;
  496. }
  497. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  498. {
  499. return 44;
  500. }
  501. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  502. {
  503. if( self.table_data.count==0)
  504. return 0;
  505. return self.table_data.count+1;
  506. }
  507. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  508. {
  509. if(indexPath.row==self.table_data.count)
  510. {
  511. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  512. UILabel *moreDataLabel=[[UILabel alloc] init];
  513. moreDataLabel.tag=200;
  514. moreDataLabel.text=self.load_more_hint;
  515. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  516. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  517. moreDataLabel.frame=CGRectMake(0, 10, self.tableView.bounds.size.width, 20);
  518. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  519. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  520. [moreCell.contentView addSubview:moreDataLabel];
  521. if([self.load_more_hint isEqualToString:@"Load more..."])
  522. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  523. // DebugLog(@"更多...");
  524. moreCell.backgroundColor = [UIColor whiteColor];
  525. return moreCell;
  526. }
  527. else
  528. {
  529. NSString *CellIdentifier = @"DocListTableViewCell";
  530. DocListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  531. NSDictionary * item_json = self.table_data[indexPath.row];
  532. cell.labelAgent.text = item_json[@"agent_name"];
  533. NSString* job_addr =item_json[@"job_addr"];
  534. NSString* job_city =item_json[@"job_city"];
  535. NSString* job_state =item_json[@"job_state"];
  536. NSString* job_zip =item_json[@"job_zip"];
  537. NSString* tel =item_json[@"tel"];
  538. if(tel.length>0)
  539. tel= [@"TEL: " stringByAppendingString:tel];
  540. NSMutableArray* arr_ext= [[NSMutableArray alloc] init];
  541. [arr_ext addObject:job_addr];
  542. [arr_ext addObject:@"\r\n"];
  543. [arr_ext addObject:job_city];
  544. [arr_ext addObject:job_state];
  545. [arr_ext addObject:job_zip];
  546. [arr_ext addObject:@"\r\n"];
  547. [arr_ext addObject:tel];
  548. NSString *nsext=[RAUtils arr2string:arr_ext separator:@", " trim:true];
  549. nsext=[nsext stringByReplacingOccurrencesOfString:@", \r\n," withString:@"\r\n"];
  550. // if(sss.length==0)
  551. // sss=@"";
  552. cell.labelDocID.text = item_json[@"doc_number"];//
  553. cell.labelExtInfo.text =nsext;
  554. cell.labelJobDate.text =item_json[@"job_date"];
  555. cell.labelCustomer.text =item_json[@"customer_name"];
  556. cell.labelSignDate.text =item_json[@"signed_date"];
  557. return cell;
  558. }
  559. // if(tableView==self.itemListTable)
  560. // {
  561. // NSString *CellIdentifier = @"CartItemCell";
  562. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  563. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  564. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  565. //
  566. // cell.bundle_item=combine_json;
  567. // NSString* img_url = [item_json valueForKey:@"img_url"];
  568. // NSString* description = [item_json valueForKey:@"description"];
  569. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  570. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  571. // NSString* currency = [item_json valueForKey:@"currency"];
  572. // int count =[[item_json valueForKey:@"count"] intValue];
  573. //
  574. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  575. //
  576. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  577. //
  578. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  579. // cell.unit_price = unitprice;
  580. // // cell.labelAttribute.text = attribute;
  581. // // cell.labelCurrency.text = currency;
  582. // cell.labelDescription.text = description;
  583. // // cell.labelIdentifier.text = identifier;
  584. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  585. //
  586. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  587. //
  588. //
  589. //
  590. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  591. // cell.cart_id = cart_item_id;
  592. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  593. //
  594. //
  595. //
  596. // [cell set_Count:count];
  597. //
  598. // NSString* file_name=[img_url lastPathComponent];
  599. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  600. // if(img_data!=nil)
  601. // {
  602. //
  603. // UIImage * img =[UIImage imageWithData:img_data];
  604. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  605. // }
  606. // else
  607. // {
  608. //
  609. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  610. //
  611. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  612. //
  613. // dispatch_async(dispatch_get_main_queue(), ^{
  614. //
  615. //
  616. //
  617. // if(downloadimg_data!=nil)
  618. // {
  619. // [iSalesDB cache_img:downloadimg_data :file_name ];
  620. //
  621. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  622. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  623. // }
  624. //
  625. // });
  626. // });
  627. //
  628. //
  629. // }
  630. // return cell;
  631. // }
  632. // else
  633. // {
  634. // NSString *CellIdentifier = @"OrderInfoListItem";
  635. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  636. // return cell;
  637. // }
  638. }
  639. #pragma mark tableview delegate
  640. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  641. {
  642. NSDictionary * item_json = self.table_data[indexPath.row];
  643. NSString* pdf_url = item_json[@"pdf_path1"];
  644. [self previewPDF:pdf_url];
  645. // if(self.blk_Select)
  646. // {
  647. //
  648. // // SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
  649. //
  650. // NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
  651. //
  652. // // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
  653. //
  654. //
  655. // self.blk_Select(item_json[@"file"]);
  656. //
  657. // }
  658. //
  659. // [self dismissViewControllerAnimated:false completion:nil];
  660. // if (tableView.isEditing) { // 编辑模式下不响应
  661. // return;
  662. // }
  663. // //
  664. // if(indexPath.row==self.content_data.count)
  665. // return;
  666. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  667. //
  668. // if(appDelegate.user_type==USER_ROLE_CUSTOMER) { // Customer
  669. // if ([Singleton sharedInstance].global_lock) { // Order list 被锁
  670. // [RAUtils message_alert:@"App is locked,You can't view the order Detail" title:@"Warning" controller:self];
  671. // return;
  672. // }
  673. // }
  674. //
  675. // NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  676. // OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  677. //
  678. // // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  679. // dvc.selectOrder=^(NSMutableDictionary* order_detail){
  680. //
  681. // [self.navigationController popViewControllerAnimated:false];
  682. // if(self.selectOrder)
  683. // self.selectOrder(order_detail);
  684. //
  685. //
  686. //
  687. // };
  688. // NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  689. //
  690. // dvc.is_shoporder=(self.orderType == 0);
  691. // dvc.order_code = order_code;
  692. // dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  693. // // bool temp_order = false ;
  694. // // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  695. // // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  696. // // temp_order=true;
  697. // //
  698. // // dvc.isTempOrder = temp_order;
  699. //
  700. // // dvc
  701. //
  702. // dvc.orderid=orderid;
  703. // // dvc.category_id=nil;
  704. // // dvc.ispush=true;
  705. // // [dvc reload];
  706. // [self.navigationController pushViewController:dvc animated:true];
  707. }
  708. @end