DocumentListViewController.m 47 KB

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