ClassificationVC.m 7.7 KB

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