SelectClassVC.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // SelectClassVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/2.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "SelectClassVC.h"
  9. #import "CommodityClassCell.h"
  10. #import "CommodityClassModel.h"
  11. @interface SelectClassVC ()<UITableViewDelegate, UITableViewDataSource>
  12. {
  13. NSMutableArray *classArray;
  14. NSMutableArray *selArr;
  15. }
  16. @property (nonatomic, strong)UITableView *classTable;
  17. @property (nonatomic, strong)NSArray *modelArr;
  18. @end
  19. @implementation SelectClassVC
  20. - (UIStatusBarStyle)preferredStatusBarStyle {
  21. if (@available(iOS 13.0,*)) {
  22. return UIStatusBarStyleDarkContent;
  23. }
  24. return UIStatusBarStyleDefault;
  25. }
  26. -(void)initData{
  27. classArray = [NSMutableArray array];
  28. selArr = [NSMutableArray array];
  29. selArr = self.havaSelArr;
  30. }
  31. -(NSArray *)modelArr{
  32. NSMutableArray *array = [NSMutableArray array];
  33. for (NSDictionary *dic in classArray) {
  34. CommodityClassModel *model = [CommodityClassModel modelWithDic:dic];
  35. [array addObject:model];
  36. }
  37. _modelArr = array;
  38. return _modelArr;
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.titleL.text = YZMsg(@"经营类目设置");
  43. self.view.backgroundColor =UIColor.whiteColor;// RGB(250, 250, 250);
  44. self.subNavi.backgroundColor = UIColor.whiteColor;
  45. self.titleL.textColor = UIColor.blackColor;
  46. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  47. self.naviLine.hidden = NO;
  48. self.naviLine.backgroundColor = RGB(245, 245, 245);
  49. [self initData];
  50. [self.view addSubview:self.classTable];
  51. [self addBottomView];
  52. [self requestData];
  53. }
  54. -(UITableView *)classTable{
  55. if (!_classTable) {
  56. _classTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-60) style:UITableViewStylePlain];
  57. _classTable.delegate = self;
  58. _classTable.dataSource = self;
  59. _classTable.separatorStyle = 0;
  60. _classTable.backgroundColor = UIColor.whiteColor;
  61. }
  62. return _classTable;
  63. }
  64. -(void)addBottomView{
  65. UIButton *sureBtn = [UIButton buttonWithType:0];
  66. sureBtn.frame = CGRectMake(15, _window_height-60, _window_width-30, 45);
  67. [sureBtn setBackgroundColor:Pink_Cor];
  68. sureBtn.layer.cornerRadius = 5;
  69. sureBtn.layer.masksToBounds = YES;
  70. [sureBtn setTitle:YZMsg(@"提交") forState:0];
  71. sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  72. [sureBtn setTitleColor:[UIColor whiteColor] forState:0];
  73. [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
  74. [self.view addSubview:sureBtn];
  75. }
  76. -(void)sureBtnClick{
  77. if (selArr.count < 1) {
  78. [MBProgressHUD showError:YZMsg(@"请选择经营类目")];
  79. return;
  80. }
  81. if (self.classEvent) {
  82. self.classEvent(selArr);
  83. }
  84. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  85. }
  86. #pragma mark ------数据请求----------
  87. -(void)requestData{
  88. [YBNetworking postWithUrl:@"Shop.getOneGoodsClass" Dic:nil Suc:^(int code, id info, NSString *msg) {
  89. if (code ==0) {
  90. classArray = info;
  91. [self.classTable reloadData];
  92. }else{
  93. [MBProgressHUD showError:msg];
  94. }
  95. } Fail:^(id fail) {
  96. }];
  97. }
  98. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  99. {
  100. return self.modelArr.count;
  101. }
  102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  103. CommodityClassCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommodityClassCell"];
  104. if (!cell) {
  105. cell = [[[NSBundle mainBundle] loadNibNamed:@"CommodityClassCell" owner:nil options:nil] lastObject];
  106. }
  107. CommodityClassModel *allmodel =self.modelArr[indexPath.row];
  108. for (CommodityClassModel *model in selArr) {
  109. if ([model.idStr isEqual:allmodel.idStr]) {
  110. allmodel.gc_isshow = @"0";
  111. }
  112. }
  113. cell.models = allmodel;
  114. cell.contentView.backgroundColor = UIColor.whiteColor;
  115. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  116. return cell;
  117. }
  118. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  119. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 90)];
  120. view.backgroundColor = UIColor.whiteColor;
  121. UIView *backView = [[UIView alloc]init];
  122. backView.frame = CGRectMake(0, 0, _window_width, 50);
  123. backView.backgroundColor = UIColor.whiteColor;
  124. [view addSubview:backView];
  125. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(12, 10, _window_width-20, 30)];
  126. label.font = [UIFont systemFontOfSize:13];
  127. label.textColor = UIColor.blackColor;// RGB(150, 150, 150);
  128. label.text = YZMsg(@"请谨慎选择,主营类目设置成功后将不可更改");
  129. [backView addSubview:label];
  130. UILabel *lb = [[UILabel alloc]init];
  131. lb.frame = CGRectMake(12, backView.bottom+5, _window_width, 30);
  132. lb.font = [UIFont systemFontOfSize:16];
  133. lb.textColor = UIColor.blackColor;// RGB(150, 150, 150);
  134. lb.text = YZMsg(@"选择主营类目");
  135. [view addSubview:lb];
  136. return view;
  137. }
  138. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  139. return 90;
  140. }
  141. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  142. return 50;
  143. }
  144. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  145. [self.classTable deselectRowAtIndexPath:indexPath animated:YES];
  146. CommodityClassModel *model = self.modelArr[indexPath.row];
  147. __block NSInteger indexsss;
  148. __block BOOL isExist = NO;
  149. [selArr enumerateObjectsUsingBlock:^(CommodityClassModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  150. if ([obj.idStr isEqualToString:model.idStr]) {//数组中已经存在该对象
  151. *stop = YES;
  152. isExist = YES;
  153. indexsss = idx;
  154. }
  155. }];
  156. if (!isExist) {
  157. //如果不存在就添加进去
  158. [selArr addObject:model];
  159. }else{
  160. [selArr removeObjectAtIndex:indexsss];
  161. }
  162. [self.classTable reloadData];
  163. NSLog(@"----------selarr:-----1111:%@",selArr);
  164. }
  165. @end