// // SignatureListViewController.m // AntsContract // // Created by Ray on 12/19/16. // Copyright © 2016 United Software Applications, Inc. All rights reserved. // #import "SignatureListViewController.h" #import "SignatureTableViewCell.h" @interface SignatureListViewController () @end @implementation SignatureListViewController - (void)viewDidLoad { [super viewDidLoad]; if([self.signatureData[self.subType][@"count"] intValue]==0) [self onAddClick:self.bbAdd]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onAddClick:(id)sender { __weak __typeof(self)weakSelf = self; [self dismissViewControllerAnimated:false completion:^{ if(weakSelf.blk_Add) weakSelf.blk_Add(); }]; } - (IBAction)onFillClick:(id)sender { __weak __typeof(self)weakSelf = self; UITableViewCell* cell = (UITableViewCell*)((UIView*)sender).superview.superview; NSIndexPath * indexPath = [self.tableView indexPathForCell:cell]; NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]]; NSString* title = [NSString stringWithFormat:@"Fill all %@ with %@ %ld?",self.subType,self.subType,(long)indexPath.section+1]; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Fill" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [weakSelf dismissViewControllerAnimated:false completion:^{ if(weakSelf.blk_Fill) weakSelf.blk_Fill(item_json[@"file"],true); }]; }]; // UIAlertAction *alerttwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // // // // [self dismissViewControllerAnimated:false completion:^{ // // // if(self.blk_Fill) // self.blk_Fill(item_json[@"file"],false); // // }]; //// DebugLog(@"Cancel"); // }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { // DebugLog(@"Cancel"); }]; [alertControl addAction:actionOne]; // [alertControl addAction:alerttwo]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]]; // __weak __typeof(self)weakSelf = self; // [self dismissViewControllerAnimated:false completion:^{ // // // if(weakSelf.blk_Fill) // weakSelf.blk_Fill(item_json[@"file"]); // // }]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // if([item_json objectForKey:@"combine"] == nil) // { // return 120; // } // else // return 150; return 128; } //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 0; //} //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 0; //} //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // return myView; // //} //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)]; //// titleLabel.textColor=[UIColor whiteColor]; //// titleLabel.backgroundColor = [UIColor clearColor]; //// if(section==0) //// titleLabel.text=NSLocalizedString(@"display_items", nil); //// else //// titleLabel.text=NSLocalizedString(@"hide_items", nil); //// [titleLabel sizeToFit]; //// [myView addSubview:titleLabel]; //// // return myView; //} // //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section //{ // // // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"]; // // if(value==nil) // value=@""; // unsigned long color = strtoul([value UTF8String],0,16); // // // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // // myView.backgroundColor = UIColorFromRGB(0x996633);; // // // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath; // // myView.layer.masksToBounds = false; // //添加四个边阴影 // // myView.layer.shadowColor = [UIColor blackColor].CGColor; // myView.layer.shadowOffset = CGSizeMake(0, 0); // myView.layer.shadowOpacity = 0.5; // myView.layer.shadowRadius = 2.0; // // // NSString*labeltitle = nil; // switch (section) { // case 0: // labeltitle= @"Order Info"; // break; // case 1: // { // labeltitle= @"More Info"; // // NSString* btntitle=nil ; // if(self.showMore) // { // btntitle=@"Hide"; // // [section setValue:@"false" forKey:@"hide"]; // // [sender setTitle:@"Show" forState:UIControlStateNormal]; // } // else{ // btntitle=@"Show"; // } // // // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)]; // btn.tag=section; // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside]; // [btn setTitle:btntitle forState:UIControlStateNormal]; // [myView addSubview:btn]; // // } // break; // case 2:{ // labeltitle= @"Models"; // // NSString* btntitle=nil ; // if(self.showModels) // { // btntitle=@"Hide"; // } // else{ // btntitle=@"Show"; // } // // // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)]; // btn.tag=section; // // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside]; // // [btn setTitle:btntitle forState:UIControlStateNormal]; // [myView addSubview:btn]; // // } // break; // case 3: // labeltitle= @"Price Info"; // default: // break; // } // // // // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)]; // titlelabel.textColor=UIColorFromRGB(color);; // titlelabel.backgroundColor = [UIColor clearColor]; // titlelabel.text=NSLocalizedString(labeltitle, nil); // [titlelabel sizeToFit]; // [myView addSubview:titlelabel]; // // // // return myView; //} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [NSString stringWithFormat:@"%@ %ld",self.subType,(long)section+1]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.signatureData[self.subType][@"count"] intValue]; } //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 33; //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"SignatureTableViewCell"; SignatureTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]]; UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]]; cell.signatureImageView.image = img; cell.btnFill.hidden = !self.can_fill; // // // cell.webview.tag = indexPath.section; // // cell.webview.delegate = self; // // cell.webView.scrollView.contentSize.height = 0; // cell.webview.scrollView.bounces=NO; // cell.webview.scrollView.directionalLockEnabled = true; // CGSize size= cell.webview.scrollView.contentSize; // size.height=10; // cell.webview.scrollView.contentSize=size; // // [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil]; // // cell.backgroundColor = [UIColor whiteColor]; return cell; // if(tableView==self.itemListTable) // { // NSString *CellIdentifier = @"CartItemCell"; // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // NSDictionary * combine_json =[item_json objectForKey:@"combine"]; // // cell.bundle_item=combine_json; // NSString* img_url = [item_json valueForKey:@"img_url"]; // NSString* description = [item_json valueForKey:@"description"]; // // NSString* identifier = [item_json valueForKey:@"identifier"]; // // NSString* attribute = [item_json valueForKey:@"attribute"]; // NSString* currency = [item_json valueForKey:@"currency"]; // int count =[[item_json valueForKey:@"count"] intValue]; // // int stockUom =[[item_json valueForKey:@"stockUom"] intValue]; // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue]; // // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue]; // cell.unit_price = unitprice; // // cell.labelAttribute.text = attribute; // // cell.labelCurrency.text = currency; // cell.labelDescription.text = description; // // cell.labelIdentifier.text = identifier; // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice]; // // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice]; // // // // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"]; // cell.cart_id = cart_item_id; // [cell init_Stepper:stockUom max:9999 min:stockUom value:count]; // // // // [cell set_Count:count]; // // NSString* file_name=[img_url lastPathComponent]; // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url]; // if(img_data!=nil) // { // // UIImage * img =[UIImage imageWithData:img_data]; // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal]; // } // else // { // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; // // dispatch_async(dispatch_get_main_queue(), ^{ // // // // if(downloadimg_data!=nil) // { // [iSalesDB cache_img:downloadimg_data :file_name ]; // // UIImage * img =[UIImage imageWithData:downloadimg_data]; // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal]; // } // // }); // }); // // // } // return cell; // } // else // { // NSString *CellIdentifier = @"OrderInfoListItem"; // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // return cell; // } } #pragma mark tableview delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(self.blk_Select) { NSLog(@"signature selected."); // SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath]; NSDictionary * item_json = self.signatureData[self.subType][[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]]; // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]]; self.blk_Select(item_json[@"file"]); } NSLog(@"before dismiss signature list"); [self dismissViewControllerAnimated:false completion:nil]; // [self dismissViewControllerAnimated:false completion:^{ // NSLog(@"dismiss completion"); // }]; NSLog(@"after dismiss signature list"); // if (tableView.isEditing) { // 编辑模式下不响应 // return; // } // // // if(indexPath.row==self.content_data.count) // return; // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // // if(appDelegate.user_type==USER_ROLE_CUSTOMER) { // Customer // if ([Singleton sharedInstance].global_lock) { // Order list 被锁 // [RAUtils message_alert:@"App is locked,You can't view the order Detail" title:@"Warning" controller:self]; // return; // } // } // // NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"]; // OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ]; // // // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"]; // dvc.selectOrder=^(NSMutableDictionary* order_detail){ // // [self.navigationController popViewControllerAnimated:false]; // if(self.selectOrder) // self.selectOrder(order_detail); // // // // }; // NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"]; // // dvc.is_shoporder=(self.orderType == 0); // dvc.order_code = order_code; // dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue]; // // bool temp_order = false ; // // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"]; // // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"]) // // temp_order=true; // // // // dvc.isTempOrder = temp_order; // // // dvc // // dvc.orderid=orderid; // // dvc.category_id=nil; // // dvc.ispush=true; // // [dvc reload]; // [self.navigationController pushViewController:dvc animated:true]; } @end