DocumentListViewController.m 30 KB

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