DocumentListViewController.m 38 KB

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