CategoryPriceViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // CategoryPriceViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 2016/10/11.
  6. // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CategoryPriceViewController.h"
  9. #import "const.h"
  10. #import "CategoryPriceCell.h"
  11. #import "UIColor+JK_HEX.h"
  12. @interface CategoryPriceViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (strong, nonatomic) IBOutlet UITableView *categoryTable;
  14. @end
  15. @implementation CategoryPriceViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. [self configAppearance];
  20. }
  21. - (void)didReceiveMemoryWarning {
  22. [super didReceiveMemoryWarning];
  23. // Dispose of any resources that can be recreated.
  24. }
  25. - (void)configAppearance {
  26. self.navigationController.navigationBar.translucent = NO;
  27. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  28. style:UIBarButtonItemStylePlain
  29. target:self
  30. action:@selector( returnBackClick:)];
  31. self.navigationItem.leftBarButtonItem = backButton;
  32. }
  33. #pragma mark - action
  34. - (void)returnBackClick:(id)sender {
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }
  37. #pragma mark - data source
  38. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  39. return [[self.categoryGivenPrice objectForKey:@"count"] integerValue];
  40. }
  41. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  42. NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
  43. return [[[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"count"] integerValue];
  44. }
  45. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  46. CategoryPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryPriceCell"];
  47. // 解析数据
  48. NSInteger section = indexPath.section;
  49. NSInteger row = indexPath.row;
  50. NSDictionary *categorySection = [self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]];
  51. NSDictionary *categoryRow = [categorySection objectForKey:[NSString stringWithFormat:@"category_%d",row]];
  52. cell.categoryPrice = categoryRow;
  53. return cell;
  54. }
  55. #pragma mark - delegate
  56. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. return 47.0f;
  58. }
  59. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  60. return 40.0f;
  61. }
  62. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  63. NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
  64. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 40)];
  65. headerView.backgroundColor = [UIColor colorWithHEX:0xEFEAE5];
  66. UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
  67. categoryLabel.textColor = [UIColor blackColor];
  68. categoryLabel.font = [UIFont systemFontOfSize:17.0f];
  69. categoryLabel.textAlignment = NSTextAlignmentLeft;
  70. categoryLabel.text = [[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"title"];
  71. [headerView addSubview:categoryLabel];
  72. return headerView;
  73. }
  74. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  75. CategoryPriceCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  76. SetCategoryPriceController *setPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"SetCategoryPriceController"];
  77. __weak typeof(self) weakself = self;
  78. setPriceVC.returnBlock = ^(NSDictionary *result){
  79. if (weakself) {
  80. __strong typeof(weakself) strongself = weakself;
  81. NSInteger section = indexPath.section;
  82. NSInteger row = indexPath.row;
  83. NSDictionary *categorySection = [[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]] mutableCopy];
  84. [categorySection setValue:result forKey:[NSString stringWithFormat:@"category_%d",row]];
  85. [strongself.categoryGivenPrice setObject:categorySection forKey:[NSString stringWithFormat:@"category_%d",section]];
  86. dispatch_async(dispatch_get_main_queue(), ^{
  87. [strongself.categoryTable reloadData];
  88. });
  89. }
  90. };
  91. setPriceVC.categoryID = [[cell.categoryPrice objectForKey:@"cid"] integerValue];
  92. setPriceVC.categoryPrice = cell.categoryPrice.mutableCopy;
  93. [self.navigationController pushViewController:setPriceVC animated:YES];
  94. }
  95. @end