DocumentListViewController.m 41 KB

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