SignatureListViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. //
  2. // SignatureListViewController.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/19/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SignatureListViewController.h"
  9. #import "SignatureTableViewCell.h"
  10. @interface SignatureListViewController ()
  11. @end
  12. @implementation SignatureListViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. if([self.signatureData[self.subType][@"count"] intValue]==0)
  16. [self onAddClick:self.bbAdd];
  17. // Do any additional setup after loading the view.
  18. }
  19. - (void)didReceiveMemoryWarning {
  20. [super didReceiveMemoryWarning];
  21. // Dispose of any resources that can be recreated.
  22. }
  23. - (IBAction)onAddClick:(id)sender {
  24. __weak __typeof(self)weakSelf = self;
  25. [self dismissViewControllerAnimated:false completion:^{
  26. if(weakSelf.blk_Add)
  27. weakSelf.blk_Add();
  28. }];
  29. }
  30. - (IBAction)onFillClick:(id)sender {
  31. __weak __typeof(self)weakSelf = self;
  32. UITableViewCell* cell = (UITableViewCell*)((UIView*)sender).superview.superview;
  33. NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
  34. NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
  35. NSString* title = [NSString stringWithFormat:@"Fill all %@ with %@ %ld?",self.subType,self.subType,(long)indexPath.section+1];
  36. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  37. //block代码块取代了delegate
  38. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  39. // textField.text = self.save_name;
  40. //
  41. //
  42. // }];
  43. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Fill" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  44. [weakSelf dismissViewControllerAnimated:false completion:^{
  45. if(weakSelf.blk_Fill)
  46. weakSelf.blk_Fill(item_json[@"file"],true);
  47. }];
  48. }];
  49. // UIAlertAction *alerttwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  50. //
  51. //
  52. //
  53. // [self dismissViewControllerAnimated:false completion:^{
  54. //
  55. //
  56. // if(self.blk_Fill)
  57. // self.blk_Fill(item_json[@"file"],false);
  58. //
  59. // }];
  60. //// DebugLog(@"Cancel");
  61. // }];
  62. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  63. // DebugLog(@"Cancel");
  64. }];
  65. [alertControl addAction:actionOne];
  66. // [alertControl addAction:alerttwo];
  67. [alertControl addAction:alertthree];
  68. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  69. [self presentViewController:alertControl animated:YES completion:nil];
  70. // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
  71. // __weak __typeof(self)weakSelf = self;
  72. // [self dismissViewControllerAnimated:false completion:^{
  73. //
  74. //
  75. // if(weakSelf.blk_Fill)
  76. // weakSelf.blk_Fill(item_json[@"file"]);
  77. //
  78. // }];
  79. }
  80. /*
  81. #pragma mark - Navigation
  82. // In a storyboard-based application, you will often want to do a little preparation before navigation
  83. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  84. // Get the new view controller using [segue destinationViewController].
  85. // Pass the selected object to the new view controller.
  86. }
  87. */
  88. #pragma mark - Table view data source
  89. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  90. {
  91. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  92. // if([item_json objectForKey:@"combine"] == nil)
  93. // {
  94. // return 120;
  95. // }
  96. // else
  97. // return 150;
  98. return 128;
  99. }
  100. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  101. //{
  102. // return 0;
  103. //}
  104. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  105. //{
  106. // return 0;
  107. //}
  108. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  109. //{
  110. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  111. // return myView;
  112. //
  113. //}
  114. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  115. //{
  116. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  117. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  118. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  119. //// titleLabel.textColor=[UIColor whiteColor];
  120. //// titleLabel.backgroundColor = [UIColor clearColor];
  121. //// if(section==0)
  122. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  123. //// else
  124. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  125. //// [titleLabel sizeToFit];
  126. //// [myView addSubview:titleLabel];
  127. ////
  128. // return myView;
  129. //}
  130. //
  131. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  132. //{
  133. //
  134. //
  135. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  136. //
  137. // if(value==nil)
  138. // value=@"";
  139. // unsigned long color = strtoul([value UTF8String],0,16);
  140. //
  141. //
  142. // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  143. // // myView.backgroundColor = UIColorFromRGB(0x996633);;
  144. //
  145. //
  146. // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  147. // // myView.layer.masksToBounds = false;
  148. // //添加四个边阴影
  149. //
  150. // myView.layer.shadowColor = [UIColor blackColor].CGColor;
  151. // myView.layer.shadowOffset = CGSizeMake(0, 0);
  152. // myView.layer.shadowOpacity = 0.5;
  153. // myView.layer.shadowRadius = 2.0;
  154. //
  155. //
  156. // NSString*labeltitle = nil;
  157. // switch (section) {
  158. // case 0:
  159. // labeltitle= @"Order Info";
  160. // break;
  161. // case 1:
  162. // {
  163. // labeltitle= @"More Info";
  164. //
  165. // NSString* btntitle=nil ;
  166. // if(self.showMore)
  167. // {
  168. // btntitle=@"Hide";
  169. // // [section setValue:@"false" forKey:@"hide"];
  170. // // [sender setTitle:@"Show" forState:UIControlStateNormal];
  171. // }
  172. // else{
  173. // btntitle=@"Show";
  174. // }
  175. //
  176. //
  177. // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  178. // btn.tag=section;
  179. // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  180. // [btn setTitle:btntitle forState:UIControlStateNormal];
  181. // [myView addSubview:btn];
  182. //
  183. // }
  184. // break;
  185. // case 2:{
  186. // labeltitle= @"Models";
  187. //
  188. // NSString* btntitle=nil ;
  189. // if(self.showModels)
  190. // {
  191. // btntitle=@"Hide";
  192. // }
  193. // else{
  194. // btntitle=@"Show";
  195. // }
  196. //
  197. //
  198. // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  199. // btn.tag=section;
  200. //
  201. // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  202. //
  203. // [btn setTitle:btntitle forState:UIControlStateNormal];
  204. // [myView addSubview:btn];
  205. //
  206. // }
  207. // break;
  208. // case 3:
  209. // labeltitle= @"Price Info";
  210. // default:
  211. // break;
  212. // }
  213. //
  214. //
  215. //
  216. // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  217. // titlelabel.textColor=UIColorFromRGB(color);;
  218. // titlelabel.backgroundColor = [UIColor clearColor];
  219. // titlelabel.text=NSLocalizedString(labeltitle, nil);
  220. // [titlelabel sizeToFit];
  221. // [myView addSubview:titlelabel];
  222. //
  223. // //
  224. // return myView;
  225. //}
  226. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  227. return [NSString stringWithFormat:@"%@ %ld",self.subType,(long)section+1];
  228. }
  229. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  230. {
  231. return [self.signatureData[self.subType][@"count"] intValue];
  232. }
  233. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  234. //{
  235. // return 33;
  236. //}
  237. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  238. {
  239. return 1;
  240. }
  241. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  242. {
  243. NSString *CellIdentifier = @"SignatureTableViewCell";
  244. SignatureTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  245. NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
  246. UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
  247. cell.signatureImageView.image = img;
  248. cell.btnFill.hidden = !self.can_fill;
  249. //
  250. //
  251. // cell.webview.tag = indexPath.section;
  252. //
  253. // cell.webview.delegate = self;
  254. // // cell.webView.scrollView.contentSize.height = 0;
  255. // cell.webview.scrollView.bounces=NO;
  256. // cell.webview.scrollView.directionalLockEnabled = true;
  257. // CGSize size= cell.webview.scrollView.contentSize;
  258. // size.height=10;
  259. // cell.webview.scrollView.contentSize=size;
  260. //
  261. // [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  262. //
  263. // cell.backgroundColor = [UIColor whiteColor];
  264. return cell;
  265. // if(tableView==self.itemListTable)
  266. // {
  267. // NSString *CellIdentifier = @"CartItemCell";
  268. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  269. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  270. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  271. //
  272. // cell.bundle_item=combine_json;
  273. // NSString* img_url = [item_json valueForKey:@"img_url"];
  274. // NSString* description = [item_json valueForKey:@"description"];
  275. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  276. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  277. // NSString* currency = [item_json valueForKey:@"currency"];
  278. // int count =[[item_json valueForKey:@"count"] intValue];
  279. //
  280. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  281. //
  282. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  283. //
  284. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  285. // cell.unit_price = unitprice;
  286. // // cell.labelAttribute.text = attribute;
  287. // // cell.labelCurrency.text = currency;
  288. // cell.labelDescription.text = description;
  289. // // cell.labelIdentifier.text = identifier;
  290. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  291. //
  292. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  293. //
  294. //
  295. //
  296. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  297. // cell.cart_id = cart_item_id;
  298. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  299. //
  300. //
  301. //
  302. // [cell set_Count:count];
  303. //
  304. // NSString* file_name=[img_url lastPathComponent];
  305. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  306. // if(img_data!=nil)
  307. // {
  308. //
  309. // UIImage * img =[UIImage imageWithData:img_data];
  310. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  311. // }
  312. // else
  313. // {
  314. //
  315. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  316. //
  317. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  318. //
  319. // dispatch_async(dispatch_get_main_queue(), ^{
  320. //
  321. //
  322. //
  323. // if(downloadimg_data!=nil)
  324. // {
  325. // [iSalesDB cache_img:downloadimg_data :file_name ];
  326. //
  327. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  328. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  329. // }
  330. //
  331. // });
  332. // });
  333. //
  334. //
  335. // }
  336. // return cell;
  337. // }
  338. // else
  339. // {
  340. // NSString *CellIdentifier = @"OrderInfoListItem";
  341. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  342. // return cell;
  343. // }
  344. }
  345. #pragma mark tableview delegate
  346. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  347. {
  348. if(self.blk_Select)
  349. {
  350. NSLog(@"signature selected.");
  351. // SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
  352. NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
  353. // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
  354. self.blk_Select(item_json[@"file"]);
  355. }
  356. NSLog(@"before dismiss signature list");
  357. [self dismissViewControllerAnimated:false completion:nil];
  358. // [self dismissViewControllerAnimated:false completion:^{
  359. // NSLog(@"dismiss completion");
  360. // }];
  361. NSLog(@"after dismiss signature list");
  362. // if (tableView.isEditing) { // 编辑模式下不响应
  363. // return;
  364. // }
  365. // //
  366. // if(indexPath.row==self.content_data.count)
  367. // return;
  368. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  369. //
  370. // if(appDelegate.user_type==USER_ROLE_CUSTOMER) { // Customer
  371. // if ([Singleton sharedInstance].global_lock) { // Order list 被锁
  372. // [RAUtils message_alert:@"App is locked,You can't view the order Detail" title:@"Warning" controller:self];
  373. // return;
  374. // }
  375. // }
  376. //
  377. // NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  378. // OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  379. //
  380. // // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  381. // dvc.selectOrder=^(NSMutableDictionary* order_detail){
  382. //
  383. // [self.navigationController popViewControllerAnimated:false];
  384. // if(self.selectOrder)
  385. // self.selectOrder(order_detail);
  386. //
  387. //
  388. //
  389. // };
  390. // NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  391. //
  392. // dvc.is_shoporder=(self.orderType == 0);
  393. // dvc.order_code = order_code;
  394. // dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  395. // // bool temp_order = false ;
  396. // // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  397. // // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  398. // // temp_order=true;
  399. // //
  400. // // dvc.isTempOrder = temp_order;
  401. //
  402. // // dvc
  403. //
  404. // dvc.orderid=orderid;
  405. // // dvc.category_id=nil;
  406. // // dvc.ispush=true;
  407. // // [dvc reload];
  408. // [self.navigationController pushViewController:dvc animated:true];
  409. }
  410. @end