SignatureListViewController.m 16 KB

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